Skip to content

Commit 2e7f3e6

Browse files
szachovyCopilot
andcommitted
Use registry images instead of building
Add publish workflow that builds and pushes service images to GHCR on master merge. Update test workflow to pull pre-built images from the registry with a local build fallback when pull fails. Closes #97 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6099814 commit 2e7f3e6

3 files changed

Lines changed: 49 additions & 14 deletions

File tree

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: "Publish"
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches: "master"
7+
8+
env:
9+
REGISTRY: "ghcr.io"
10+
11+
jobs:
12+
publish:
13+
runs-on: "ubuntu-22.04"
14+
permissions:
15+
contents: "read"
16+
packages: "write"
17+
strategy:
18+
matrix:
19+
include:
20+
- image: "ghcr.io/szachovy/superset-cluster-mysql-server"
21+
context: "services/mysql-server"
22+
- image: "ghcr.io/szachovy/superset-cluster-mysql-mgmt"
23+
context: "services/mysql-mgmt"
24+
- image: "ghcr.io/szachovy/superset-cluster-superset-service"
25+
context: "services/superset"
26+
steps:
27+
- uses: "actions/checkout@v4"
28+
29+
- name: "Log in to GitHub Container Registry"
30+
uses: "docker/login-action@v3"
31+
with:
32+
registry: "${{ env.REGISTRY }}"
33+
username: "${{ github.actor }}"
34+
password: "${{ secrets.GITHUB_TOKEN }}"
35+
36+
- name: "Build and push image"
37+
run: |
38+
docker build --quiet -t "${{ matrix.image }}:latest" "${{ matrix.context }}"
39+
docker push "${{ matrix.image }}:latest"

.github/workflows/tests.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,28 @@ jobs:
4747
run: "terraform apply --auto-approve"
4848
working-directory: "${{ env.TERRAFORM_WORKING_DIRECTORY }}"
4949

50-
- name: "Build and pre-load service images into test containers"
50+
- name: "Pull or build service images and pre-load into test containers"
5151
run: |
52-
if [ "$GITHUB_REF_NAME" = "master" ]; then
53-
IMAGE_TAG="latest"
54-
else
55-
IMAGE_TAG="${GITHUB_REF_NAME//\//-}"
56-
fi
57-
build_and_load() {
52+
pull_or_build_and_load() {
5853
local image_name="$1"
5954
local build_context="$2"
6055
shift 2
6156
local nodes=("$@")
62-
docker build --quiet -t "${image_name}:${IMAGE_TAG}" "$build_context"
63-
if [ "$IMAGE_TAG" != "latest" ]; then
64-
docker tag "${image_name}:${IMAGE_TAG}" "${image_name}:latest"
57+
if ! docker pull "${image_name}:latest" 2>/dev/null; then
58+
echo "Pull failed for ${image_name}:latest, building locally"
59+
docker build --quiet -t "${image_name}:latest" "$build_context"
6560
fi
6661
for node in "${nodes[@]}"; do
6762
docker save "${image_name}:latest" | docker exec -i "$node" docker load
6863
done
69-
docker rmi "${image_name}:${IMAGE_TAG}" || true
7064
docker rmi "${image_name}:latest" || true
7165
docker image prune --force
7266
}
73-
build_and_load "ghcr.io/szachovy/superset-cluster-mysql-server" \
67+
pull_or_build_and_load "ghcr.io/szachovy/superset-cluster-mysql-server" \
7468
"services/mysql-server" node-2 node-3 node-4
75-
build_and_load "ghcr.io/szachovy/superset-cluster-mysql-mgmt" \
69+
pull_or_build_and_load "ghcr.io/szachovy/superset-cluster-mysql-mgmt" \
7670
"services/mysql-mgmt" node-0 node-1
77-
build_and_load "ghcr.io/szachovy/superset-cluster-superset-service" \
71+
pull_or_build_and_load "ghcr.io/szachovy/superset-cluster-superset-service" \
7872
"services/superset" node-0 node-1
7973
docker image prune --all --force
8074

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
[RELIABILITY.md](./docs/RELIABILITY.md) documents in the documentation. (#93)
1414
* CodeQL code scanning workflow for Python static analysis. (#29)
1515
* Dependabot updates for `github-actions` and `terraform` ecosystems. (#29)
16+
* CI workflow to build and push service images to GitHub Container Registry on master merge. (#97)
1617

1718
### Changed
1819

1920
* Completed [ARCHITECTURE.md](./docs/ARCHITECTURE.md) (#93)
2021
* Migrated CI from self-hosted to GitHub-hosted runners with Docker-in-Docker test infrastructure. (#94)
22+
* Test workflow pulls pre-built images from GHCR with local build fallback. (#97)
2123

2224
### Fixed
2325

0 commit comments

Comments
 (0)