Repository navigation
ci: Build a container image for PRs and main #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| .git | ||
| .github | ||
| .devcontainer | ||
| .astro | ||
| node_modules | ||
| dist | ||
| design | ||
| docs | ||
| raw-input.md | ||
| tests | ||
| test-results | ||
| playwright-report | ||
| blob-report | ||
| external/koudijs-public-website |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| version: 2 | ||
| updates: | ||
| # Base images in the Dockerfile (pinned by digest). | ||
| - package-ecosystem: "docker" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" | ||
|
|
||
| - package-ecosystem: "github-actions" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| name: Container image | ||
|
|
||
| # ghcr.io/<repo>:pr-<N> / :main (moving) and :sha-<short> (immutable, pin this). | ||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [ main ] | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: image-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| jobs: | ||
| image: | ||
| # Fork PRs get a read-only token and can't push. | ||
| if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Build the PR head, not the merge commit, so sha-<short> names exactly what's inside. | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | ||
| submodules: true | ||
|
|
||
| - uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - id: meta | ||
| uses: docker/metadata-action@v5 | ||
| env: | ||
| DOCKER_METADATA_PR_HEAD_SHA: true | ||
| with: | ||
| images: ghcr.io/${{ github.repository }} | ||
| tags: | | ||
| type=ref,event=pr | ||
| type=ref,event=branch | ||
| type=sha,format=short | ||
|
|
||
| # Push before testing, so a failing image can still be inspected. | ||
| - id: push | ||
| uses: docker/build-push-action@v7 | ||
| with: | ||
| context: . | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
|
|
||
| - name: Test image | ||
| env: | ||
| DIGEST: ${{ steps.push.outputs.digest }} | ||
| run: IMAGE="ghcr.io/${GITHUB_REPOSITORY,,}@$DIGEST" tests/image.sh | ||
|
|
||
| - name: Summary | ||
| if: always() && steps.push.outputs.digest | ||
| run: | | ||
| { | ||
| echo '### Image' | ||
| echo '```' | ||
| echo "${{ steps.meta.outputs.tags }}" | ||
| echo | ||
| echo "digest: ${{ steps.push.outputs.digest }}" | ||
| echo '```' | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,3 +44,6 @@ Icon? | |
|
|
||
| # Windows system files | ||
| Desktop.ini | ||
|
|
||
| # Reference clone (not a submodule) | ||
| external/koudijs-public-website/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Static Astro build served by unprivileged nginx on :8080. | ||
| # Bases are pinned by digest so Dependabot proposes (and CI tests) bumps. | ||
| FROM node:24-alpine@sha256:a34ab6d7f6f4813f4d0c5469d74685604b962fbdbf5793a7bc7b4998ecb867c8 AS build | ||
| WORKDIR /site | ||
| COPY package.json package-lock.json ./ | ||
| RUN npm ci --no-audit --no-fund | ||
| COPY . . | ||
| RUN npm run build | ||
|
|
||
| FROM nginxinc/nginx-unprivileged:alpine@sha256:b5047b9b76845eac124358373c6852377c52e4b05834a47647e955dd91cb8f1e | ||
| COPY nginx/default.conf /etc/nginx/conf.d/default.conf | ||
| COPY --from=build /site/dist/ /usr/share/nginx/html/ | ||
| EXPOSE 8080 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| server { | ||
| listen 8080; | ||
| server_name _; | ||
|
|
||
| root /usr/share/nginx/html; | ||
| index index.html; | ||
|
|
||
| # Behind a reverse proxy: never leak the internal scheme/host/:8080. | ||
| absolute_redirect off; | ||
|
|
||
| # /about and /about/ both serve about/index.html directly, no redirect. | ||
| location / { | ||
| try_files $uri $uri.html $uri/index.html =404; | ||
| } | ||
|
|
||
| # Astro's hashed assets never change. | ||
| location /_astro/ { | ||
| add_header Cache-Control "public, max-age=31536000, immutable"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env bash | ||
| # Black-box test of the container image (Dockerfile + nginx/default.conf). | ||
| # | ||
| # tests/image.sh # build from the repo, test, clean up | ||
| # IMAGE=ghcr.io/foo/bar:tag tests/image.sh # test an existing image | ||
| set -euo pipefail | ||
| cd "$(dirname "$0")/.." | ||
|
|
||
| PORT="${PORT:-18088}" | ||
| CONTAINER="site-image-test-$$" | ||
| IMAGE="${IMAGE:-}" | ||
| BUILT_IMAGE="" | ||
|
|
||
| cleanup() { | ||
| docker rm -f "$CONTAINER" >/dev/null 2>&1 || true | ||
| [ -n "$BUILT_IMAGE" ] && docker rmi "$BUILT_IMAGE" >/dev/null 2>&1 || true | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| if [ -z "$IMAGE" ]; then | ||
| BUILT_IMAGE="site-image-test:$$" | ||
| IMAGE="$BUILT_IMAGE" | ||
| echo "==> docker build -> $IMAGE" | ||
| docker build -q -t "$IMAGE" . >/dev/null | ||
| fi | ||
|
|
||
| echo "==> running $IMAGE on :$PORT" | ||
| docker run -d --name "$CONTAINER" -p "$PORT:8080" "$IMAGE" >/dev/null | ||
| base="http://localhost:$PORT" | ||
|
|
||
| for _ in $(seq 1 30); do | ||
| curl -fsS -o /dev/null "$base/" 2>/dev/null && break | ||
| sleep 0.5 | ||
| done | ||
|
|
||
| fail=0 | ||
| pass() { printf ' ok %s\n' "$1"; } | ||
| bad() { printf ' FAIL %s\n' "$1"; fail=1; } | ||
|
|
||
| assert_status() { | ||
| local got | ||
| got=$(curl -s -o /dev/null -w '%{http_code}' "$base$1") | ||
| [ "$got" = "$2" ] && pass "$1 -> $got" || bad "$1 -> $got (want $2)" | ||
| } | ||
|
|
||
| # 2xx with no Location header: nothing can leak the internal :8080. | ||
| assert_served_directly() { | ||
| local headers code loc | ||
| headers=$(curl -s -D - -o /dev/null "$base$1") | ||
| code=$(printf '%s' "$headers" | awk 'NR==1{print $2}') | ||
| loc=$(printf '%s' "$headers" | grep -i '^location:' || true) | ||
| if [ "${code:0:1}" = "2" ] && [ -z "$loc" ]; then | ||
| pass "$1 served directly ($code)" | ||
| else | ||
| bad "$1 want direct 2xx, got code=$code location='$loc'" | ||
| fi | ||
| } | ||
|
|
||
| # Capture first; piping curl into `grep -q` flakes under pipefail (SIGPIPE). | ||
| assert_body_contains() { | ||
| local body | ||
| body=$(curl -s "$base$1") | ||
| [[ "$body" == *"$2"* ]] && pass "$1 contains '$2'" || bad "$1 missing '$2'" | ||
| } | ||
|
|
||
| echo "== status ==" | ||
| assert_status "/" 200 | ||
| assert_status "/robots.txt" 200 | ||
| assert_status "/sitemap.xml" 200 | ||
| assert_status "/does-not-exist-xyz123" 404 | ||
|
|
||
| echo "== pretty URLs, no redirect ==" | ||
| for p in /about /about/ /gitops /gitops/ /technology /technology/; do | ||
| assert_served_directly "$p" | ||
| done | ||
|
|
||
| echo "== real pages ==" | ||
| assert_body_contains "/" "ConfigButler" | ||
| assert_body_contains "/about" "ConfigButler" | ||
|
|
||
| echo | ||
| [ "$fail" -eq 0 ] || { echo "IMAGE TESTS FAILED" >&2; exit 1; } | ||
| echo "ALL IMAGE TESTS PASSED" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.