diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cb1278b..a318b18a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ # Builds, tests and packages (on Windows and Linux) the project on merges or PRs to 'dev' or 'main'. # Saves artifacts (from Windows job) on merges to main, or when the workflow is manually triggered with 'Publish a GitHub release and packages'. -# The Linux job publishes a docker image on every build. +# The Linux job runs the tests against a Seq Docker container. name: CI @@ -91,15 +91,9 @@ jobs: uses: actions/setup-dotnet@v5 with: dotnet-version: 10.0.x - - name: Configure Docker - run: | - docker run --privileged --rm linuxkit/binfmt:bebbae0c1100ebf7bf2ad4dfb9dfd719cf0ef132 - sudo service docker restart - - name: Build and Publish + - name: Build and Package env: DOTNET_CLI_TELEMETRY_OPTOUT: true - DOCKER_USER: ${{ secrets.DOCKER_USER }} - DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} SEQ_DOCKER_TAG: 2026.1 shell: pwsh run: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7adc69b4..517e41bf 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,5 +1,6 @@ # Publishes the packages built by a successful CI run: creates a draft GitHub release, pushes the -# packages to NuGet.org and npm, then publishes the release once both registries have succeeded. +# packages to NuGet.org and npm and the Docker images to Docker Hub, then publishes the release once +# all three registries have succeeded. name: Publish @@ -143,12 +144,46 @@ jobs: run: | ./build/Build.Npm.ps1 -ArchiveDir ./npm-archives + publish-docker: + name: Publish (Docker) + runs-on: ubuntu-24.04 + + needs: draft-release + + permissions: + contents: read + + steps: + # Build.Docker.ps1, the Dockerfiles and the source, at the commit CI built and tested. The checks + # on the draft-release job guarantee this is a commit pushed to this repository, not pull request code. + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.workflow_run.head_sha }} + persist-credentials: false + - name: Setup + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.x + - name: Configure Docker + # Enables building the arm64 image on the x64 runner. + run: | + docker run --privileged --rm linuxkit/binfmt:bebbae0c1100ebf7bf2ad4dfb9dfd719cf0ef132 + sudo service docker restart + - name: Build and Publish + env: + DOTNET_CLI_TELEMETRY_OPTOUT: true + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + shell: pwsh + run: | + ./build/Build.Docker.ps1 + publish-github: name: Publish GitHub release runs-on: ubuntu-24.04 - # Only publish the release once the packages are on NuGet.org and npm. - needs: [ draft-release, publish-nuget, publish-npm ] + # Only publish the release once the packages are on NuGet.org, npm and Docker Hub. + needs: [ draft-release, publish-nuget, publish-npm, publish-docker ] permissions: # Required to publish the release and create its tag. diff --git a/build/Build.Docker.ps1 b/build/Build.Docker.ps1 new file mode 100644 index 00000000..8dca56a3 --- /dev/null +++ b/build/Build.Docker.ps1 @@ -0,0 +1,87 @@ +# Builds the `datalust/seqcli-ci` Docker images for linux/amd64 and linux/arm64, and, when +# DOCKER_TOKEN is set, pushes them along with a multi-arch manifest. +# +# In CI (see publish-docker in .github/workflows/publish.yml) this runs against the commit that the +# triggering CI run built and tested, with CI_BUILD_NUMBER_BASE and CI_TARGET_BRANCH reproducing its version. +# +# Building the arm64 image on an x64 host requires binfmt to be configured (the workflow does this). + +Push-Location $PSScriptRoot/../ + +. ./build/Build.Common.ps1 + +Write-Host "Run Number: $env:CI_BUILD_NUMBER_BASE" +Write-Host "Target Branch: $env:CI_TARGET_BRANCH" + +$version = Get-SemVer + +Write-Output "Building Docker images for version $version" + +$framework = "net10.0" +$image = "datalust/seqcli" +$archs = @( + @{ rid = "x64"; platform = "linux/amd64" }, + @{ rid = "arm64"; platform = "linux/arm64/v8" } +) + +function Build-DockerImage($arch) +{ + $rid = "linux-$($arch.rid)" + + & dotnet publish src/SeqCli/SeqCli.csproj -c Release -f $framework -r $rid --self-contained /p:VersionPrefix=$version /p:PublishSingleFile=true + if($LASTEXITCODE -ne 0) { exit 2 } + + & docker buildx build --platform "$($arch.platform)" -f dockerfiles/seqcli/$rid.Dockerfile -t "$image-ci:$version-$($arch.rid)" . + if($LASTEXITCODE -ne 0) { exit 3 } +} + +function Login-ToDocker() +{ + $ErrorActionPreference = "SilentlyContinue" + + Write-Output "$env:DOCKER_TOKEN" | docker login -u $env:DOCKER_USER --password-stdin + if ($LASTEXITCODE) { exit 3 } + + $ErrorActionPreference = "Stop" +} + +function Publish-DockerImage($arch) +{ + $ErrorActionPreference = "SilentlyContinue" + + & docker push "$image-ci:$version-$($arch.rid)" + if($LASTEXITCODE -ne 0) { exit 3 } + + $ErrorActionPreference = "Stop" +} + +function Publish-DockerManifest($archs) +{ + $images = "" + foreach ($arch in $archs) { + $images += "$image-ci:$version-$($arch.rid) " + } + + # We use `invoke-expression` here so each tag is treated as a separate arg + invoke-expression "docker manifest create $image-ci:$version $images" + if ($LASTEXITCODE) { exit 4 } + + docker manifest push $image-ci:$version + if ($LASTEXITCODE) { exit 4 } +} + +foreach ($arch in $archs) { + Build-DockerImage($arch) +} + +if ("$($env:DOCKER_TOKEN)" -ne "") { + Login-ToDocker + + foreach ($arch in $archs) { + Publish-DockerImage($arch) + } + + Publish-DockerManifest($archs) +} + +Pop-Location diff --git a/build/Build.Linux.ps1 b/build/Build.Linux.ps1 index cc550b3d..f3ece527 100644 --- a/build/Build.Linux.ps1 +++ b/build/Build.Linux.ps1 @@ -12,14 +12,9 @@ Write-Host "Published: $env:CI_PUBLISH" $version = Get-SemVer -Write-Output "Building version $version" +Write-Output "Testing version $version" $framework = "net10.0" -$image = "datalust/seqcli" -$archs = @( - @{ rid = "x64"; platform = "linux/amd64" }, - @{ rid = "arm64"; platform = "linux/arm64/v8" } -) function Execute-Tests { @@ -37,66 +32,6 @@ function Execute-Tests cd ../.. } -function Build-DockerImage($arch) -{ - $rid = "linux-$($arch.rid)" - - & dotnet publish src/SeqCli/SeqCli.csproj -c Release -f $framework -r $rid --self-contained /p:VersionPrefix=$version /p:PublishSingleFile=true - if($LASTEXITCODE -ne 0) { exit 2 } - - & docker buildx build --platform "$($arch.platform)" -f dockerfiles/seqcli/$rid.Dockerfile -t "$image-ci:$version-$($arch.rid)" . - if($LASTEXITCODE -ne 0) { exit 3 } -} - -function Login-ToDocker() -{ - $ErrorActionPreference = "SilentlyContinue" - - Write-Output "$env:DOCKER_TOKEN" | docker login -u $env:DOCKER_USER --password-stdin - if ($LASTEXITCODE) { exit 3 } - - $ErrorActionPreference = "Stop" -} - -function Publish-DockerImage($arch) -{ - $ErrorActionPreference = "SilentlyContinue" - - & docker push "$image-ci:$version-$($arch.rid)" - if($LASTEXITCODE -ne 0) { exit 3 } - - $ErrorActionPreference = "Stop" -} - -function Publish-DockerManifest($archs) -{ - $images = "" - foreach ($arch in $archs) { - $images += "$image-ci:$version-$($arch.rid) " - } - - # We use `invoke-expression` here so each tag is treated as a separate arg - invoke-expression "docker manifest create $image-ci:$version $images" - if ($LASTEXITCODE) { exit 4 } - - docker manifest push $image-ci:$version - if ($LASTEXITCODE) { exit 4 } -} - Execute-Tests -foreach ($arch in $archs) { - Build-DockerImage($arch) -} - -if ("$($env:DOCKER_TOKEN)" -ne "") { - Login-ToDocker - - foreach ($arch in $archs) { - Publish-DockerImage($arch) - } - - Publish-DockerManifest($archs) -} - Pop-Location diff --git a/build/README.md b/build/README.md index bd2c4025..a31ed03a 100644 --- a/build/README.md +++ b/build/README.md @@ -6,7 +6,8 @@ This directory holds the PowerShell scripts that build, test, package, and publi |---|---|---| | `Build.Common.ps1` | (dot-sourced by the others) | Version number helpers | | `Build.Windows.ps1` | Windows | Release archives for every platform, the `seqcli` .NET tool package, generated docs | -| `Build.Linux.ps1` | Linux | `datalust/seqcli` Docker images for `linux/amd64` and `linux/arm64` | +| `Build.Linux.ps1` | Linux | Nothing; runs the unit tests and the end-to-end tests against a Seq Docker container | +| `Build.Docker.ps1` | Linux | `datalust/seqcli-ci` Docker images for `linux/amd64` and `linux/arm64` | | `Build.Npm.ps1` | Linux (any OS locally) | `@datalust/seqcli` and `@datalust/seqcli-` npm packages | | `Build.Release.ps1` | Linux (any OS locally) | Draft GitHub release `v` with the CI artifacts attached | @@ -35,7 +36,7 @@ npm enforces strict semver, which forbids leading zeros in numeric components, s The workflow runs on pushes and pull requests to `dev` and `main`, and can be triggered manually with `workflow_dispatch`. Two jobs run: 1. **Build (Windows)** runs `Build.Windows.ps1`. When `CI_PUBLISH` is set (pushes to `main`, and manual runs with the `publish` input checked), it then uploads the tool package as a workflow artifact named `packages`, the release archives as one named `archives`, and the markdown command reference as one named `docs`, for the publish workflow to consume. -2. **Build (Linux)** runs `Build.Linux.ps1`, after configuring `binfmt` so that ARM64 images can be built on the x64 runner. It runs in parallel with the Windows job. +2. **Build (Linux)** runs `Build.Linux.ps1`, which runs the tests on Linux, including the end-to-end tests against the `datalust/seq` Docker image. It runs in parallel with the Windows job. Environment variables control what gets published: @@ -44,44 +45,45 @@ Environment variables control what gets published: | `CI_BUILD_NUMBER_BASE` | `github.run_number` | Build number component of the version | | `CI_TARGET_BRANCH` | `github.head_ref` or `github.ref_name` | Branch component of the version | | `CI_PUBLISH` | `True` for pushes to `main`, or when the manual `publish` input is set | Whether CI uploads the artifacts the publish workflow publishes to NuGet, npm and a GitHub release | -| `DOCKER_USER`, `DOCKER_TOKEN` | Docker Hub secrets | When `DOCKER_TOKEN` is non-empty, `Build.Linux.ps1` pushes images | | `SEQ_DOCKER_TAG` | e.g. `2026.1` | Seq image tag used for the Linux end-to-end tests | GitHub supplies no secrets or OIDC tokens to pull requests from forks, and PR builds run the full build and test steps but publish nothing. ## The publish workflow -`publish.yml` runs via `workflow_run` when the CI workflow completes. It only publishes when that CI run succeeded in this repository, and was either a push to `main` or a manual dispatch on `dev` or `main`; it does nothing for pull requests or pushes to `dev`. Four jobs run: +`publish.yml` runs via `workflow_run` when the CI workflow completes. It only publishes when that CI run succeeded in this repository, and was either a push to `main` or a manual dispatch on `dev` or `main`; it does nothing for pull requests or pushes to `dev`. Five jobs run: 1. **Draft GitHub release** downloads all three artifacts and runs `Build.Release.ps1`, which creates a draft release `v` targeting the commit CI built, with them attached; builds from branches other than `main` are marked as prereleases. Drafts are visible only to people with write access, and the tag isn't created until the release is published. 2. **Publish (NuGet)** downloads the `packages` artifact from the CI run and pushes it to NuGet.org. 3. **Publish (npm)** checks out the commit CI built, downloads the `archives` artifact, and runs `Build.Npm.ps1`. -4. **Publish GitHub release** runs only after both registries succeed, and publishes the draft, which creates the tag. +4. **Publish (Docker)** checks out the commit CI built, configures `binfmt` so that ARM64 images can be built on the x64 runner, and runs `Build.Docker.ps1`, which builds the images and, because `DOCKER_USER` and `DOCKER_TOKEN` are set from the Docker Hub secrets, pushes them. +5. **Publish GitHub release** runs only after all three registries succeed, and publishes the draft, which creates the tag. -The NuGet and npm jobs run in parallel, after the draft is created. If either fails, the draft is left in place; re-running the failed jobs publishes it once they succeed. Re-running the draft job updates the existing draft's assets rather than creating another. +The NuGet, npm and Docker jobs run in parallel, after the draft is created. If any of them fails, the draft is left in place; re-running the failed jobs publishes it once they succeed. Re-running the draft job updates the existing draft's assets rather than creating another. -Both registries use [trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing). +NuGet and npm use [trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing); Docker Hub uses the `DOCKER_USER` and `DOCKER_TOKEN` secrets. ### What each branch publishes | Trigger | GitHub release | NuGet | Docker Hub | npm | |---|---|---|---|---| | Pull request | no | no | no | no | -| Push to `dev` | no | no | `datalust/seqcli-ci:` | no | +| Push to `dev` | no | no | no | no | | Push to `main` | yes, `v` | release version | `datalust/seqcli-ci:` | release, dist-tag `latest` | | Manual run, `publish` checked | yes (prerelease unless on `main`) | prerelease version unless on `main` | `datalust/seqcli-ci:` | prerelease (dist-tag `dev`) unless on `main` | | Manual run, `publish` unchecked | no (CI skips its jobs) | no | no | no | -Note that `Build.Linux.ps1` always pushes to the `datalust/seqcli-ci` repository (the image name with a `-ci` suffix), never directly to `datalust/seqcli`. Promoting an image to the public `datalust/seqcli` repository, and tagging it `latest`, is a separate step outside this repository. +Note that `Build.Docker.ps1` always pushes to the `datalust/seqcli-ci` repository (the image name with a `-ci` suffix), never directly to `datalust/seqcli`. Promoting an image to the public `datalust/seqcli` repository, and tagging it `latest`, is a separate step outside this repository. -To publish a release from `dev` (for example a preview build), run the workflow manually from the Actions tab with the **Publish a GitHub release and packages** input checked; this also publishes to NuGet and npm. The release is marked as a prerelease because the branch is not `main`. +To publish a release from `dev` (for example a preview build), run the workflow manually from the Actions tab with the **Publish a GitHub release and packages** input checked; this also publishes to NuGet, npm and Docker Hub. The release is marked as a prerelease because the branch is not `main`. ## Running the builds locally All scripts need PowerShell 7 (`pwsh`) and the .NET 10 SDK, and must be run from anywhere inside the repository (they `Push-Location` to the root themselves). Without the `CI_*` variables the version is `.local`, and nothing is published because the credential variables are unset. * `Build.Windows.ps1` requires Windows: it uses `7za.exe`, installs Seq with Chocolatey for the end-to-end tests, and builds `win-*` RIDs. Run it as `./build/Build.Windows.ps1`. -* `Build.Linux.ps1` requires Docker with `buildx`. Building the `arm64` image on an x64 host needs `binfmt` configured, as the workflow does. Run it as `./build/Build.Linux.ps1 -SeqDockerTag 2026.1`. +* `Build.Linux.ps1` requires Docker, to run Seq for the end-to-end tests. Run it as `./build/Build.Linux.ps1 -SeqDockerTag 2026.1`. +* `Build.Docker.ps1` requires Docker with `buildx`. Building the `arm64` image on an x64 host needs `binfmt` configured, as the workflow does. Run it as `./build/Build.Docker.ps1`; it only pushes when `DOCKER_TOKEN` is set. * `Build.Npm.ps1` runs anywhere with `npm`, `tar`, and `gh`. To exercise it end to end without publishing, point it at a directory of archives (for example a local `artifacts/` from a Windows build, or assets downloaded from a release) and use `-DryRun`: ```shell @@ -97,4 +99,4 @@ All scripts need PowerShell 7 (`pwsh`) and the .NET 10 SDK, and must be run from 1. Update [`baseversion`](../baseversion). 2. Update the SDK version in [`ci.global.json`](../ci.global.json) to match the Seq release. 3. Update `SEQ_DOCKER_TAG` in [`ci.yml`](../.github/workflows/ci.yml) to the Seq image the end-to-end tests should run against. -4. If the target framework changes, update `$framework` in `Build.Windows.ps1` and `Build.Linux.ps1`, and the `COPY` paths in the Dockerfiles. +4. If the target framework changes, update `$framework` in `Build.Windows.ps1`, `Build.Linux.ps1` and `Build.Docker.ps1`, and the `COPY` paths in the Dockerfiles.