xcaddy
xcaddy copied to clipboard
exmaple github workflow to build
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.
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