greenpau / caddy-git

Git Plugin for Caddy v2
Apache License 2.0
70 stars 13 forks source link

Post pull command error #17

Closed vfiee closed 2 years ago

vfiee commented 2 years ago

Describe the issue

Post pull exec command error

Configuration

{
    git {
        repo github-vite-demo {
            base_dir /tmp/ssh
            url https://github.com/vfiee/github-vite-demo.git
            branch main
            auth key /root/.ssh/id_rsa
            post pull exec {
                name changeDir
                command /bin/cd
                args "/tmp/ssh/github-vite-demo"
            }
            post pull exec {
                name install
                command /usr/local/bin/npm
                args "run install"
            }
            post pull exec {
                name build
                command /usr/local/bin/npm
                args "run build"
            }
        }
    }
}

:2022 {
    root * /srv
    encode gzip
    file_server browse
}

:2023 {
    route /update {
        git update repo github-vite-demo
    }
    root * /tmp/ssh/github-vite-demo/dist
    encode gzip
    file_server browse
}
# https://caddyserver.com/docs/caddyfile
# docker-compose
version: "3"

services:
  caddy:
    image: s6-caddy:latest
    container_name: caddy
    restart: always
    ports:
      - 2022:2022
      - 2019:2019
      - 2023:2023
    volumes:
      - ./var:/var
      - ./data:/data
      - /Users/vyron/.ssh:/root/.ssh
      - ./etc/caddy:/etc/caddy
      - ./etc/services:/etc/services.d
      - ../index.html:/srv/index.html

# note: s6-caddy is my local docker image

Version Information

Provide output of caddy list-modules -versions | grep git below:

/ # caddy list-modules --versions | grep git
git v1.0.7
http.handlers.git v1.0.7

Expected behavior

Expect the command to run successfully

Additional context

# Dockerfile for build s6-caddy image

FROM caddy:2.6.1-builder AS builder

RUN xcaddy build \
    --with github.com/caddy-dns/cloudflare \
    --with github.com/greenpau/caddy-git

FROM node:current-alpine3.16

ENV TZ=Asia/Shanghai XDG_CONFIG_HOME=/config XDG_DATA_HOME=/data S6_VERSION=v2.2.0.3

LABEL maintainer "vyronfiee <vyronfiee@gmail.com>" \
    s6_version="${S6_VERSION}" \
    caddy_version="2.6.1"

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

RUN apk add --no-cache \
    ca-certificates \
    git \
    mailcap \
    openssh-client \
    tzdata \
    inotify-tools \
    curl && \ 
    curl -fSL https://github.com/just-containers/s6-overlay/releases/download/$S6_VERSION/s6-overlay-amd64.tar.gz | tar xz && \
    /usr/bin/caddy version && \
    /usr/bin/caddy list-modules && \
    echo 'Asia/Shanghai' >/etc/timezone 

EXPOSE 80 443 2019

VOLUME /srv

WORKDIR /srv

COPY Caddyfile /etc/caddy/Caddyfile

COPY index.html /srv/index.html

ENTRYPOINT ["/init"]
greenpau commented 2 years ago

@vfiee , what is the error?

greenpau commented 2 years ago

args "run install"

@vfiee , have you tried the following?

args run install
vfiee commented 2 years ago

@vfiee , what is the error?

image
vfiee commented 2 years ago

args "run install"

@vfiee , have you tried the following?

args run install

by hand

  1. docker exec -it caddy sh
  2. cd /tmp/ssh/github-vite-demo
  3. npm install (succed)

caddy log

looks cd command is faild, so npm install is faild too!

{"level":"warn","ts":1664880246.4712973,"logger":"git","msg":"failed executing post-pull command","repo_name":"github-vite-demo","error":"execline-cd: usage: cd path prog...\n"}
{"level":"warn","ts":1664880247.310766,"logger":"git","msg":"failed executing post-pull command","repo_name":"github-vite-demo","error":"npm ERR! code ENOENT\nnpm ERR! syscall open\nnpm ERR! path /var/run/s6/services/caddy/package.json\nnpm ERR! errno -2\nnpm ERR! enoent ENOENT: no such file or directory, open '/var/run/s6/services/caddy/package.json'\nnpm ERR! enoent This is related to npm not being able to find a file.\nnpm ERR! enoent \n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /root/.npm/_logs/2022-10-04T10_44_06_966Z-debug-0.log\n"}
{"level":"warn","ts":1664880248.1021268,"logger":"git","msg":"failed executing post-pull command","repo_name":"github-vite-demo","error":""}
{"level":"info","ts":1664880248.102182,"logger":"git","msg":"provisioned app instance","app":"git"}
{"level":"info","ts":1664880248.102451,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc00035cd90"}
{"level":"info","ts":1664880248.1030974,"logger":"http.handlers.git","msg":"provisioned plugin instance","instance_name":"git-github-vite-demo","path":"*","started_at":1664880248.1030953}
greenpau commented 2 years ago

looks cd command is faild, so npm install is faild too!

@vfiee , each of the commands have its own shell. Thus, cd path would not be retained. I suggest adding a script that performs the install. This way you only have a single post pull exec command.

However, it could be a neat feature to add a script to execute:

{
    git {
        repo github-vite-demo {
            base_dir /tmp/ssh
            url https://github.com/vfiee/github-vite-demo.git
            branch main
            auth key /root/.ssh/id_rsa
            post pull script {
                name changeDir
                content {
                  cd /tmp/ssh/github-vite-demo
                  npm run install
                  npm run build
                }
            }
        }
    }
}
vfiee commented 2 years ago

looks cd command is faild, so npm install is faild too!

@vfiee , each of the commands have its own shell. Thus, cd path would not be retained. I suggest adding a script that performs the install. This way you only have a single post pull exec command.

However, it could be a neat feature to add a script to execute:


{

  git {

      repo github-vite-demo {

          base_dir /tmp/ssh

          url https://github.com/vfiee/github-vite-demo.git

          branch main

          auth key /root/.ssh/id_rsa

          post pull script {

              name changeDir

              content {

                cd /tmp/ssh/github-vite-demo

                npm run install

                npm run build

              }

          }

      }

  }

}

OK, thank you for your timely reply. I'm looking forward to the way shell is executed.

vfiee commented 2 years ago

Running the shell is possible, thank you very much! I'll close the issues.

post pull exec {
                name changeDir
                command /bin/sh
                args "/scripts/installAndbuild"
            }