Skip to content

Commit 477a820

Browse files
feat: add ghcr image publishing (#1735)
* feat: add ghcr image publishing Closes #1739 * docs: add doc for ghcr publishing
1 parent 652f55a commit 477a820

9 files changed

Lines changed: 232 additions & 11 deletions

File tree

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Publish GHCR Images
2+
3+
on:
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: publish-ghcr-${{ github.ref }}
8+
cancel-in-progress: true
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
17+
jobs:
18+
build-and-push-backend:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
digest: ${{ steps.build.outputs.digest }}
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Compute image prefix
26+
id: meta
27+
run: echo "prefix=${REGISTRY}/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
28+
29+
- name: Log in to GHCR
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v3
38+
39+
- name: Build and push backend image
40+
id: build
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: ./backend
44+
push: true
45+
tags: |
46+
${{ steps.meta.outputs.prefix }}/dashboard-backend:latest
47+
${{ steps.meta.outputs.prefix }}/dashboard-backend:${{ github.sha }}
48+
49+
build-and-push-dashboard:
50+
runs-on: ubuntu-latest
51+
outputs:
52+
digest: ${{ steps.build.outputs.digest }}
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- name: Compute image prefix
57+
id: meta
58+
run: echo "prefix=${REGISTRY}/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
59+
60+
- name: Log in to GHCR
61+
uses: docker/login-action@v3
62+
with:
63+
registry: ${{ env.REGISTRY }}
64+
username: ${{ github.actor }}
65+
password: ${{ secrets.GITHUB_TOKEN }}
66+
67+
- name: Set up Docker Buildx
68+
uses: docker/setup-buildx-action@v3
69+
70+
- name: Build and push dashboard image
71+
id: build
72+
uses: docker/build-push-action@v6
73+
with:
74+
context: .
75+
file: ./dashboard/Dockerfile
76+
push: true
77+
tags: |
78+
${{ steps.meta.outputs.prefix }}/dashboard-frontend:latest
79+
${{ steps.meta.outputs.prefix }}/dashboard-frontend:${{ github.sha }}
80+
81+
build-and-push-proxy:
82+
runs-on: ubuntu-latest
83+
outputs:
84+
digest: ${{ steps.build.outputs.digest }}
85+
steps:
86+
- uses: actions/checkout@v4
87+
88+
- name: Compute image prefix
89+
id: meta
90+
run: echo "prefix=${REGISTRY}/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
91+
92+
- name: Log in to GHCR
93+
uses: docker/login-action@v3
94+
with:
95+
registry: ${{ env.REGISTRY }}
96+
username: ${{ github.actor }}
97+
password: ${{ secrets.GITHUB_TOKEN }}
98+
99+
- name: Set up Docker Buildx
100+
uses: docker/setup-buildx-action@v3
101+
102+
- name: Build and push proxy image
103+
id: build
104+
uses: docker/build-push-action@v6
105+
with:
106+
context: ./proxy
107+
push: true
108+
tags: |
109+
${{ steps.meta.outputs.prefix }}/dashboard-proxy:latest
110+
${{ steps.meta.outputs.prefix }}/dashboard-proxy:${{ github.sha }}
111+
112+
verify:
113+
if: always()
114+
needs:
115+
- build-and-push-backend
116+
- build-and-push-dashboard
117+
- build-and-push-proxy
118+
runs-on: ubuntu-latest
119+
steps:
120+
- name: Image publish summary
121+
run: |
122+
echo "### Published GHCR Images" >> "$GITHUB_STEP_SUMMARY"
123+
echo "" >> "$GITHUB_STEP_SUMMARY"
124+
echo "| Image | Digest |" >> "$GITHUB_STEP_SUMMARY"
125+
echo "| ----- | ------ |" >> "$GITHUB_STEP_SUMMARY"
126+
echo "| dashboard-backend | \`${{ needs.build-and-push-backend.outputs.digest }}\` |" >> "$GITHUB_STEP_SUMMARY"
127+
echo "| dashboard-frontend | \`${{ needs.build-and-push-dashboard.outputs.digest }}\` |" >> "$GITHUB_STEP_SUMMARY"
128+
echo "| dashboard-proxy | \`${{ needs.build-and-push-proxy.outputs.digest }}\` |" >> "$GITHUB_STEP_SUMMARY"

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ A web app built with [React](https://react.dev/) + [Typescript](https://www.type
1818
A Python http server built with [Django](https://www.djangoproject.com/) + [DRF](https://www.django-rest-framework.org/), to see more information check the backend [README](/backend/README.md).
1919

2020

21+
## Quick run
22+
23+
If you want to just run the project, you can try out pre-built images with the [docker-compose-next.yml](./docker-compose-next.yml) file. This pulls images from GHCR and runs them locally without needing to rebuild them. You may still need to set up environment variables, so read the docs.
24+
2125
## Build
2226

2327
### Frontend
@@ -133,6 +137,21 @@ docker compose up --build
133137
To deploy to prod you need to push a tag in the `release/YYYYMMDD.N` format
134138
like: `release/20240910.0`
135139

140+
### Publishing container images to GHCR
141+
142+
The workflow `.github/workflows/deploy-containers.yaml` publishes Docker images for the three services used by the dashboard stack:
143+
144+
- `dashboard-backend` (from `./backend`)
145+
- `dashboard-frontend` (from `./dashboard/Dockerfile`)
146+
- `dashboard-proxy` (from `./proxy`)
147+
148+
This workflow is manual for now (`workflow_dispatch`) and pushes images to GHCR under `ghcr.io/<owner>/<repo>` with two tags for each image:
149+
150+
- `latest`
151+
- `${{ github.sha }}`
152+
153+
At the end of the run, the workflow writes an image digest summary in the GitHub Actions job summary.
154+
136155
## Test results email reports
137156

138157
See details about our new [notifications](docs/notifications.md) system.

backend/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__pycache__
2+
.pytest_cache
3+
*.pyc
4+
5+
tests_submissions

backend/Dockerfile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ RUN O='0 1 2' \
4545
PYTHONOPTIMIZE=$N poetry run python -m compileall -q $D || exit 1; \
4646
done
4747

48-
ARG BACKEND_VOLUME_DIR
49-
ENV BACKEND_VOLUME_DIR=${BACKEND_VOLUME_DIR}
50-
RUN echo "Building with volume on: $BACKEND_VOLUME_DIR"
51-
VOLUME ${BACKEND_VOLUME_DIR}
52-
5348
# Expose both application and metrics ports
5449
EXPOSE 8000 8001
5550

docker-compose-next.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
volumes:
2+
backend-data:
3+
runtime-data:
4+
static-data:
5+
dashboard-db-data:
6+
7+
networks:
8+
public:
9+
private:
10+
11+
services:
12+
dashboard_db:
13+
image: postgres:17
14+
env_file:
15+
- .env.db
16+
volumes:
17+
- dashboard-db-data:/var/lib/postgresql/data
18+
networks:
19+
- private
20+
ports:
21+
- "5434:5432"
22+
23+
redis:
24+
image: redis:8.0-M04-alpine
25+
restart: always
26+
networks:
27+
- private
28+
ports:
29+
- 6379:6379
30+
31+
backend:
32+
image: ${IMAGE_REGISTRY:-ghcr.io}/${IMAGE_OWNER}/${IMAGE_REPOSITORY}/dashboard-backend:${IMAGE_TAG}
33+
volumes:
34+
- backend-data:${BACKEND_VOLUME_DIR:-/volume_data}
35+
restart: always
36+
networks:
37+
- private
38+
- public
39+
ports:
40+
- target: 8000
41+
published: 8000
42+
protocol: tcp
43+
- target: 8001
44+
published: 8001
45+
protocol: tcp
46+
depends_on:
47+
- redis
48+
- dashboard_db
49+
env_file:
50+
- .env.backend
51+
environment:
52+
DB_DEFAULT_HOST: ${DB_DEFAULT_HOST:-dashboard_db}
53+
54+
dashboard:
55+
image: ${IMAGE_REGISTRY:-ghcr.io}/${IMAGE_OWNER}/${IMAGE_REPOSITORY}/dashboard-frontend:${IMAGE_TAG}
56+
volumes:
57+
- static-data:/data/static
58+
59+
proxy:
60+
image: ${IMAGE_REGISTRY:-ghcr.io}/${IMAGE_OWNER}/${IMAGE_REPOSITORY}/dashboard-proxy:${IMAGE_TAG}
61+
restart: always
62+
depends_on:
63+
- backend
64+
- dashboard
65+
networks:
66+
- public
67+
volumes:
68+
- static-data:/data/static
69+
ports:
70+
- target: 80
71+
published: 80
72+
protocol: tcp
73+
env_file:
74+
- .env.proxy

docker-compose.k6.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ services:
3838
test-backend:
3939
build:
4040
context: ./backend
41-
args:
42-
BACKEND_VOLUME_DIR: /volume_data
4341
volumes:
4442
- test-backend-data:/volume_data
4543
networks:

docker-compose.test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ services:
3232
build:
3333
context: ./backend
3434
args:
35-
BACKEND_VOLUME_DIR: /volume_data
3635
INSTALL_DEV_DEPS: "true"
3736
volumes:
3837
- test-backend-data:/volume_data

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ services:
4747
backend:
4848
build:
4949
context: ./backend
50-
args:
51-
BACKEND_VOLUME_DIR: ${BACKEND_VOLUME_DIR:-/volume_data}
50+
image: ghcr.io/${IMAGE_NAME:-local}/backend:latest
5251
volumes:
5352
- backend-data:${BACKEND_VOLUME_DIR:-/volume_data}
5453
restart: always
@@ -78,12 +77,13 @@ services:
7877
build:
7978
context: .
8079
dockerfile: ./dashboard/Dockerfile
81-
image: dashboard:latest
80+
image: ghcr.io/${IMAGE_NAME:-local}/dashboard:latest
8281
volumes:
8382
- static-data:/data/static
8483

8584
proxy:
8685
build: ./proxy
86+
image: ghcr.io/${IMAGE_NAME:-local}/proxy:latest
8787
restart: always
8888
depends_on:
8989
- backend

docs/Onboarding.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ docker logs <container_id>
171171
172172
Definition of Done: The KernelCI Dashboard (backend and frontend) is running via Docker and accessible locally.
173173
174+
> [!NOTE]
175+
> The Task 6 teaches you how to build and run the project locally during development. Note that you can also run the project using pre-built images generated by the [deploy-containers](../.github/workflows/deploy-containers.yaml) workflow, using the [docker-compose-next](../docker-compose-next.yml) file to pull and run these pre-built images without rebuilding them.
176+
174177
### Task 7: Complete a real Task
175178
1. Go to https://github.com/kernelci/dashboard/issues and search for issues with the label `good first issue`.
176179
2. Pick any of those and assign to yourself.

0 commit comments

Comments
 (0)