GitHub CI: tests, then the image to GHCR, Docker Hub and Quay

62fa6c1 · gmorell · 2026-11-18 22:26

15 files +168 -11
Message
{commit_body(@commit)}

Files changed

modified .dockerignore
+1 −0
@@ -26,3 +26,4 @@ priv/uploads/
26 26 .git/
27 27 .gitignore
28 28 .forgejo/
29 +.github/
added .github/workflows/ci.yml
+140 −0
@@ -0,0 +1,140 @@
1 +name: ci
2 +# Tests, then the release image to the public registries: GitHub (GHCR),
3 +# Docker Hub and Quay. As angler's ci.yml.
4 +#
5 +# GitHub only. The forge runs .forgejo/workflows/image.yml instead (it
6 +# ignores .github/workflows once .forgejo/workflows exists) and publishes to
7 +# its own registry, ggr.neiam.co, which the deployment pulls.
8 +
9 +on:
10 + push:
11 + branches: [master]
12 + tags: ["v*"]
13 + pull_request:
14 +
15 +# A newer push supersedes this run: on a branch or PR the run in
16 +# progress is cancelled; on master it finishes, and only a run still
17 +# waiting is replaced.
18 +concurrency:
19 + group: ${{ github.workflow }}-${{ github.ref }}
20 + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
21 +
22 +jobs:
23 + test:
24 + if: github.server_url == 'https://github.com'
25 + # Self-hosted ARC runners, as angler. `ubuntu-latest` works too; the
26 + # Postgres service needs a runner that supports service containers.
27 + runs-on: arc-runner-set
28 + env:
29 + MIX_ENV: test
30 + # The service's published port on the runner (config/test.exs
31 + # defaults to 54330, compose.yml's).
32 + POSTGRES_PORT: "5432"
33 + # Below the service Postgres's 100 connections, however big the runner.
34 + POOL_SIZE: "40"
35 + services:
36 + postgres:
37 + image: docker.io/postgres:17-alpine
38 + env:
39 + POSTGRES_USER: postgres
40 + POSTGRES_PASSWORD: postgres
41 + ports:
42 + - 5432:5432
43 + options: >-
44 + --health-cmd "pg_isready -U postgres"
45 + --health-interval 5s
46 + --health-timeout 3s
47 + --health-retries 5
48 + steps:
49 + - uses: actions/checkout@v4
50 +
51 + # ARC's default runner image is bare.
52 + - run: sudo apt-get update && sudo apt-get install -y --no-install-recommends build-essential git
53 +
54 + # Our fork of erlef/setup-beam, mirrored to GitHub (as angler): it
55 + # defaults ImageOS to ubuntu-24.04, which the ARC runner otherwise
56 + # forces to something unmappable.
57 + - uses: neiam/action-setup-beam@v1
58 + with:
59 + # Match the build image in the Dockerfile.
60 + elixir-version: "1.20.5"
61 + otp-version: "28.5.0.8"
62 +
63 + - uses: actions/cache@v4
64 + with:
65 + path: |
66 + deps
67 + _build
68 + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
69 + restore-keys: ${{ runner.os }}-mix-
70 +
71 + - run: mix deps.get
72 +
73 + # compile --warnings-as-errors, deps.unlock --unused, format, test.
74 + - run: mix precommit
75 +
76 + image:
77 + if: github.server_url == 'https://github.com'
78 + needs: test
79 + runs-on: arc-runner-set
80 + permissions:
81 + contents: read
82 + packages: write
83 + steps:
84 + - uses: actions/checkout@v4
85 + - uses: docker/setup-buildx-action@v3
86 +
87 + # GHCR takes the built-in GITHUB_TOKEN (`packages: write`, above).
88 + # Docker Hub and Quay need repo secrets (Settings → Secrets and
89 + # variables → Actions):
90 + # DOCKERHUB_USER / DOCKERHUB_TOKEN (a Docker Hub access token)
91 + # QUAY_USERNAME / QUAY_TOKEN (a Quay robot account)
92 + # A missing login just fails the push to that registry; drop its login
93 + # and `images` line to skip one.
94 + - name: Log in to GHCR
95 + if: github.event_name != 'pull_request'
96 + uses: docker/login-action@v3
97 + with:
98 + registry: ghcr.io
99 + username: ${{ github.actor }}
100 + password: ${{ secrets.GITHUB_TOKEN }}
101 +
102 + - name: Log in to Docker Hub
103 + if: github.event_name != 'pull_request'
104 + uses: docker/login-action@v3
105 + with:
106 + registry: docker.io
107 + username: ${{ secrets.DOCKERHUB_USER }}
108 + password: ${{ secrets.DOCKERHUB_TOKEN }}
109 +
110 + - name: Log in to Quay
111 + if: github.event_name != 'pull_request'
112 + uses: docker/login-action@v3
113 + with:
114 + registry: quay.io
115 + username: ${{ secrets.QUAY_USERNAME }}
116 + password: ${{ secrets.QUAY_TOKEN }}
117 +
118 + - id: meta
119 + uses: docker/metadata-action@v5
120 + with:
121 + images: |
122 + ghcr.io/${{ github.repository }}
123 + docker.io/neiam/final_track
124 + quay.io/neiam/final_track
125 + tags: |
126 + type=ref,event=branch
127 + type=ref,event=pr
128 + type=semver,pattern={{version}}
129 + type=semver,pattern={{major}}.{{minor}}
130 + type=sha
131 + type=raw,value=latest,enable={{is_default_branch}}
132 +
133 + # Pull requests build (proving the Dockerfile still works) but don't push.
134 + - uses: docker/build-push-action@v6
135 + with:
136 + context: .
137 + platforms: linux/amd64
138 + push: ${{ github.event_name != 'pull_request' }}
139 + tags: ${{ steps.meta.outputs.tags }}
140 + labels: ${{ steps.meta.outputs.labels }}
modified README.md
+8 −2
@@ -123,8 +123,14 @@ so scrobbling locally makes real requests to MusicBrainz.
123 123
124 124 ## Running it
125 125
126 −The image is built by `.forgejo/workflows/image.yml` on every push to
127 −master: `ggr.neiam.co/neiam/final_track:{master,latest,sha-…}`. The release
126 +The forge builds `ggr.neiam.co/neiam/final_track:{master,latest,sha-…}`
127 +on every push to master (`.forgejo/workflows/image.yml`; the deployment
128 +pulls it). On GitHub, `.github/workflows/ci.yml` runs the tests and then
129 +publishes the same image publicly to `ghcr.io/neiam/final_track`,
130 +`docker.io/neiam/final_track` and `quay.io/neiam/final_track` (`latest`
131 +and `master` from master, versions from `v*` tags). Docker Hub and Quay
132 +need `DOCKERHUB_USER`/`DOCKERHUB_TOKEN` and `QUAY_USERNAME`/`QUAY_TOKEN`
133 +as repo secrets; GHCR uses the workflow's own token. The release
128 134 (`mix release`) ships these scripts in `bin/`:
129 135
130 136 | Script | |
modified config/test.exs
+4 −1
@@ -41,7 +41,10 @@ config :final_track, FinalTrack.Repo,
41 41 # parallel suite the default 50ms queue target made them give up.
42 42 queue_target: 1_000,
43 43 queue_interval: 5_000,
44 − pool_size: System.schedulers_online() * 2,
44 + # POOL_SIZE caps it (CI): big runners would otherwise open cores × 2
45 + # connections and run out of the service Postgres's 100.
46 + pool_size:
47 + String.to_integer(System.get_env("POOL_SIZE") || "#{System.schedulers_online() * 2}"),
45 48 # compose.yml's postgres by default; POSTGRES_PORT=5432 for the host's own.
46 49 port: String.to_integer(System.get_env("POSTGRES_PORT") || "54330")
47 50
modified lib/final_track_web/live/about_live.ex
+9 −5
@@ -9,9 +9,13 @@ defmodule FinalTrackWeb.AboutLive do
9 9 # {key, label, binary}: container runtimes for "Run your own".
10 10 @runtimes [{:podman, "Podman", "podman"}, {:docker, "Docker", "docker"}]
11 11
12 − # {key, label, image}: registries the image is published to. Add a row and
13 − # the registry picker appears.
14 − @registries [{:gitgud, "GitGud", "ggr.neiam.co/neiam/final_track"}]
12 + # {key, label, image}: the public registries the image is published to
13 + # (.github/workflows/ci.yml). The forge's own registry is private.
14 + @registries [
15 + {:ghcr, "GitHub", "ghcr.io/neiam/final_track"},
16 + {:dockerhub, "Docker Hub", "docker.io/neiam/final_track"},
17 + {:quay, "Quay", "quay.io/neiam/final_track"}
18 + ]
15 19
16 20 # {name, placeholder (and default), width class, label}: the blanks.
17 21 @config_fields [
@@ -43,7 +47,7 @@ defmodule FinalTrackWeb.AboutLive do
43 47 |> assign(:config_fields, @config_fields)
44 48 |> assign(:optional_settings, @optional_settings)
45 49 |> assign(:runtime, :podman)
46 − |> assign(:registry, :gitgud)
50 + |> assign(:registry, :ghcr)
47 51 |> assign(:config_form, to_form(%{"user" => "", "password" => "", "host" => ""}))
48 52 |> recompute_commands()}
49 53 end
@@ -57,7 +61,7 @@ defmodule FinalTrackWeb.AboutLive do
57 61 def handle_event("set_registry", %{"registry" => registry}, socket),
58 62 do:
59 63 {:noreply,
60 − socket |> assign(:registry, pick(@registries, registry, :gitgud)) |> recompute_commands()}
64 + socket |> assign(:registry, pick(@registries, registry, :ghcr)) |> recompute_commands()}
61 65
62 66 def handle_event("set_config", params, socket) do
63 67 form = to_form(Map.take(params, ["user", "password", "host"]))
modified test/final_track_web/live/about_live_test.exs
+6 −3
@@ -40,12 +40,15 @@ defmodule FinalTrackWeb.AboutLiveTest do
40 40 assert has_element?(lv, "#db-command", "POSTGRES_DB=final_track")
41 41 assert has_element?(lv, "#run-command", "--network final-track")
42 42 assert has_element?(lv, "#run-command", "ecto://USER:PASS@final-track-db/final_track")
43 − assert has_element?(lv, "#run-command", "ggr.neiam.co/neiam/final_track:latest")
43 + assert has_element?(lv, "#registry-ghcr[aria-selected=true]")
44 + assert has_element?(lv, "#run-command", "ghcr.io/neiam/final_track:latest")
44 45 assert has_element?(lv, "#run-command", "-v final-track-covers:/var/lib/final_track/covers")
45 46 assert has_element?(lv, "#setup-command", "podman exec final-track bin/migrate")
46 47 assert has_element?(lv, "#setup-command", "bin/invite")
47 − # One registry so far: no picker.
48 − refute has_element?(lv, "[id^=registry-]")
48 + lv |> element("#registry-quay") |> render_click()
49 + assert has_element?(lv, "#run-command", "quay.io/neiam/final_track:latest")
50 + lv |> element("#registry-dockerhub") |> render_click()
51 + assert has_element?(lv, "#run-command", "docker.io/neiam/final_track:latest")
49 52 end
50 53
51 54 test "switch runtime, fill in the blanks", %{conn: conn} do

Parents: 73c9c47