xcaddy icon indicating copy to clipboard operation
xcaddy copied to clipboard

exmaple github workflow to build

Open tcurdt opened this issue 7 months ago • 1 comments

I think it could be very helpful to have an example workflow that uses Github actions and xcaddy to build caddy ...and a container image.

tcurdt avatar May 03 '25 09:05 tcurdt

I'm writing related documents, but I encountered a problem. The downloaded dependencies cannot be cached. Here are the relevant files:

,github/workflows/caddy.yml:

on: 
  - push

permissions:
  contents: read
  packages: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - uses: actions/setup-go@v5
        with:
          # https://hub.docker.com/_/golang
          go-version: stable
          check-latest: true

      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      
      - run: |
          DATE=$(date +'%Y%m%d%H%M%S')
          SHA=$(git rev-parse --short HEAD)
          echo "TAG=${DATE}-${SHA}" >> $GITHUB_ENV

      - uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: |
            ghcr.io/username/caddy:latest
            ghcr.io/username/caddy:${{ env.TAG }}

./Dockerfile:

FROM caddy:builder AS builder

COPY ./caddy-plugin /app/caddy-plugin

RUN xcaddy build --with example.com/custom-plugin=/app/caddy-plugin/custom-plugin

FROM caddy

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

JuTemp avatar Aug 15 '25 12:08 JuTemp