Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -42,6 +44,21 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=sha,format=long

- name: Build the image to test
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
load: true
tags: ashl-dot-dev:runtime-check
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Smoke test the built image
run: bash scripts/smoke-container.sh ashl-dot-dev:runtime-check

- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
Expand All @@ -51,13 +68,16 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and publish Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Publish the tested image
if: github.event_name != 'pull_request'
env:
RELEASE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
test -n "$RELEASE_TAGS"
image_id=$(docker image inspect --format '{{.Id}}' ashl-dot-dev:runtime-check)
revision=$(docker image inspect --format '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$image_id")
test "$revision" = "$GITHUB_SHA"
while IFS= read -r tag; do
docker image tag "$image_id" "$tag"
docker image push "$tag"
done <<< "$RELEASE_TAGS"
37 changes: 37 additions & 0 deletions scripts/smoke-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail

image=${1:?Pass the locally built Docker image}
container=$(docker run --detach --network none \
-e TARGET_URL=https://example.invalid \
-e STEAM_API_KEY=fixture -e STEAM_ID=fixture \
-e SPOTIFY_USER_ID=fixture -e SPOTIFY_CLIENT_ID=fixture \
-e SPOTIFY_CLIENT_SECRET=fixture -e SPOTIFY_REFRESH_TOKEN=fixture \
"$image")
trap 'docker rm -f "$container" >/dev/null 2>&1 || true' EXIT

for attempt in {1..20}; do
if docker exec "$container" bun -e '
const url = "http://127.0.0.1:4321";
const options = { redirect: "manual", signal: AbortSignal.timeout(2000) };
const page = await fetch(url + "/experience", options);
if (page.status !== 200 || !(await page.text()).includes("<h1>Experience</h1>")) {
throw new Error("Experience page did not render its heading");
}
const route = await fetch(url + "/best-viewed-with", options);
if (route.status !== 400 || (await route.text()) !== "Incompatible User-Agent") {
throw new Error("Server-handled route did not produce its expected response");
}
' >/dev/null 2>&1; then
printf 'Verified the Experience page and a server-handled route in the built image.\n'
exit 0
fi
if [[ $(docker inspect --format '{{.State.Running}}' "$container") != true ]]; then
break
fi
sleep 2
done

docker logs --tail 30 "$container" >&2 || true
printf 'The built image failed its local HTTP smoke test.\n' >&2
exit 1
Loading