diff --git a/.gitea/workflows/build-caddy.yaml b/.github/workflows/build-caddy.yaml similarity index 56% rename from .gitea/workflows/build-caddy.yaml rename to .github/workflows/build-caddy.yaml index 4960988..44d0e76 100644 --- a/.gitea/workflows/build-caddy.yaml +++ b/.github/workflows/build-caddy.yaml @@ -8,9 +8,8 @@ on: required: true default: 'latest' caddy_plugin: - description: 'Specify plugin module path (e.g., github.com/caddy-dns/cloudflare)' - required: true - default: 'github.com/caddy-dns/cloudflare' + description: 'Comma-separated plugin module paths, e.g. github.com/caddy-dns/cloudflare, github.com/caddyserver/nginx-adapter. Leave empty to build vanilla Caddy.' + required: false jobs: build-caddy: @@ -26,7 +25,16 @@ jobs: run: go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest - name: Compile customised Caddy binary - run: xcaddy build ${{ inputs.caddy_version }} --with ${{ inputs.caddy_plugin }} + run: | + PLUGIN_ARGS="" + IFS=',' read -ra PLUGINS <<< "${{ inputs.caddy_plugin }}" + for PLUGIN in "${PLUGINS[@]}"; do + PLUGIN="${PLUGIN// /}" + if [ -n "$PLUGIN" ]; then + PLUGIN_ARGS="$PLUGIN_ARGS --with $PLUGIN" + fi + done + xcaddy build ${{ inputs.caddy_version }} $PLUGIN_ARGS - name: Upload compiled artefact uses: actions/upload-artifact@v3 diff --git a/README.md b/README.md new file mode 100644 index 0000000..d584b0d --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# infra + +The infrastructure repository of onixbyte, hosting the CI workflows used to build and maintain the runtime environment. + +## Directory structure + +``` +infra/ +└── .github/workflows/ + └── build-caddy.yaml # GitHub Actions workflow that builds a customised Caddy binary +``` + +## Building a customised Caddy + +The `build-caddy.yaml` workflow uses [xcaddy](https://github.com/caddyserver/xcaddy) to compile a specified version of Caddy with plugins injected, and uploads the compiled binary as an artefact. The workflow can only be triggered manually. + +### How to trigger the build + +1. Open the **Actions** page of the repository. +2. Select the **Build Customised Caddy** workflow from the left-hand panel. +3. Click **Run workflow** and fill in the parameters (see the table below). +4. Wait for the build to finish, then download the `caddy-custom-linux-amd64` artefact from the build run page. + +### Input parameters + +| Parameter | Description | Required | Default | +|-----------|-------------|:---:|---------| +| `caddy_version` | Caddy version to build, e.g. `latest`, `v2.8.4` | Yes | `latest` | +| `caddy_plugin` | Comma-separated plugin module paths, e.g. `github.com/caddy-dns/cloudflare, github.com/caddyserver/nginx-adapter`. Leave empty to build vanilla Caddy. | No | — | + +### Plugin input behaviour + +The table below shows how the value of `caddy_plugin` maps to the actual `xcaddy` command (using the default `latest` version): + +| Input (`caddy_plugin`) | Command that runs | +|------------------------|-------------------| +| `github.com/caddy-dns/cloudflare, github.com/caddyserver/nginx-adapter` | `xcaddy build latest --with github.com/caddy-dns/cloudflare --with github.com/caddyserver/nginx-adapter` | +| `github.com/caddy-dns/cloudflare,github.com/caddyserver/nginx-adapter` | Same as above (spaces are optional) | +| `github.com/caddy-dns/cloudflare` | `xcaddy build latest --with github.com/caddy-dns/cloudflare` | +| *(empty)* | `xcaddy build latest` (vanilla Caddy) | + +> Empty entries are skipped automatically, so `plugin1, , plugin2` behaves the same as `plugin1, plugin2`. + +## Building locally + +To reproduce the same build on your own machine you need Go 1.22+: + +```sh +go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest + +# Compile a specific version with a plugin injected +xcaddy build v2.8.4 --with github.com/caddy-dns/cloudflare + +# Inject several plugins at once +xcaddy build latest \ + --with github.com/caddy-dns/cloudflare \ + --with github.com/caddyserver/nginx-adapter +``` + +When the build finishes, an executable named `caddy` is produced in the current directory.