Skip to content

Commit b172843

Browse files
committed
refactor: Rewrite build workflows
GitHub Actions: - Bring down runner count from 5 to 2 - Separate frontend and backend build jobs - Uprev checkout actions to version 6 - Remove unused REGISTRY env variable Docker: - Separate Dockerfiles for frontend: Dockerfile -> for local development Dockerfiles.actions -> for GitHub Actions The static flutter web app is compiled on the actions runner directly and the assets are copied in multi-arch nginx docker images. - Run both the images as non root users Chore: - Remove unused FastAPI dependencies - Update existing packages to latest available versions
1 parent fc59943 commit b172843

File tree

9 files changed

+166
-548
lines changed

9 files changed

+166
-548
lines changed

.github/workflows/build-release.yaml

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,15 @@ on:
66
workflow_dispatch:
77

88
env:
9-
REGISTRY: ghcr.io
109
IMAGE_PREFIX: ghcr.io/dk10ws/slcm
1110

1211
jobs:
13-
build:
14-
name: Build ${{ matrix.service }} (${{ matrix.arch }})
15-
strategy:
16-
matrix:
17-
arch: [amd64, arm64]
18-
service: [frontend, backend]
19-
include:
20-
- arch: amd64
21-
runner: ubuntu-latest
22-
- arch: arm64
23-
runner: ubuntu-24.04-arm
24-
runs-on: ${{ matrix.runner }}
12+
build-backend:
13+
name: Build FastAPI application docker image
14+
runs-on: ubuntu-latest
2515
steps:
2616
- name: Checkout Repository
27-
uses: actions/checkout@v5
17+
uses: actions/checkout@v6
2818
with:
2919
ref: "web"
3020

@@ -38,22 +28,45 @@ jobs:
3828
- name: Set up Docker Buildx
3929
uses: docker/setup-buildx-action@v3
4030

41-
- name: Build and Push ${{ matrix.service }} Docker Image
31+
- name: Build and Push backend Docker Image
4232
uses: docker/build-push-action@v6
4333
with:
44-
context: ${{ matrix.service }}
34+
context: backend
4535
push: true
46-
platforms: linux/${{ matrix.arch }}
36+
platforms: linux/amd64,linux/arm64
4737
tags: |
48-
${{ env.IMAGE_PREFIX }}-${{ matrix.service }}:latest-${{ matrix.arch }}
49-
${{ env.IMAGE_PREFIX }}-${{ matrix.service }}:${{ github.sha }}-${{ matrix.arch }}
50-
cache-from: type=gha,scope=${{ matrix.service }}-${{ matrix.arch }}
51-
cache-to: type=gha,mode=max,scope=${{ matrix.service }}-${{ matrix.arch }}
38+
${{ env.IMAGE_PREFIX }}-backend:latest
39+
${{ env.IMAGE_PREFIX }}-backend:${{ github.sha }}
40+
cache-from: type=gha
41+
cache-to: type=gha,mode=max
5242

53-
merge-manifest:
54-
needs: build
43+
build-frontend:
44+
name: Build Flutter Web application docker image
5545
runs-on: ubuntu-latest
5646
steps:
47+
- name: Checkout Repository
48+
uses: actions/checkout@v6
49+
with:
50+
ref: "web"
51+
52+
- name: Cache pub deps
53+
uses: actions/cache@v5
54+
with:
55+
path: ~/.pub-cache
56+
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}
57+
restore-keys: ${{ runner.os }}-pub-
58+
59+
- name: Setup Flutter
60+
uses: subosito/flutter-action@v2
61+
with:
62+
channel: stable
63+
64+
- name: Build web app
65+
working-directory: frontend
66+
run: |
67+
flutter pub get
68+
flutter build web
69+
5770
- name: Log in to GitHub Container Registry
5871
uses: docker/login-action@v3
5972
with:
@@ -64,16 +77,15 @@ jobs:
6477
- name: Set up Docker Buildx
6578
uses: docker/setup-buildx-action@v3
6679

67-
- name: Create multi-arch manifests
68-
run: |
69-
services=("frontend" "backend")
70-
71-
for service in "${services[@]}"; do
72-
echo "Creating manifest for $service..."
73-
74-
docker buildx imagetools create \
75-
-t ${{ env.IMAGE_PREFIX }}-$service:${{ github.sha }} \
76-
-t ${{ env.IMAGE_PREFIX }}-$service:latest \
77-
${{ env.IMAGE_PREFIX }}-$service:${{ github.sha }}-amd64 \
78-
${{ env.IMAGE_PREFIX }}-$service:${{ github.sha }}-arm64
79-
done
80+
- name: Build and Push frontend Docker Image
81+
uses: docker/build-push-action@v6
82+
with:
83+
context: frontend
84+
file: frontend/Dockerfile.actions
85+
push: true
86+
platforms: linux/amd64,linux/arm64
87+
tags: |
88+
${{ env.IMAGE_PREFIX }}-frontend:latest
89+
${{ env.IMAGE_PREFIX }}-frontend:${{ github.sha }}
90+
cache-from: type=gha
91+
cache-to: type=gha,mode=max

backend/Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ RUN --mount=type=cache,target=/root/.cache/uv \
2020
# Then, use a final image without uv
2121
FROM python:3.13-slim-bookworm
2222

23+
# Setup a non-root user
24+
RUN groupadd --system --gid 999 nonroot \
25+
&& useradd --system --gid 999 --uid 999 --create-home nonroot
26+
2327
WORKDIR /app
2428

2529
# Copy the application from the builder
26-
COPY --from=builder --chown=app:app /app /app
30+
COPY --from=builder --chown=nonroot:nonroot /app /app
2731

2832
# Place executables in the environment at the front of the path
2933
ENV PATH="/app/.venv/bin:$PATH"
3034

35+
USER nonroot
36+
37+
EXPOSE 8000
38+
3139
# Run the FastAPI application by default
3240
CMD ["python", "-m", "src.main"]

backend/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ authors = [
99
requires-python = ">=3.13"
1010
dependencies = [
1111
"bs4>=0.0.2",
12-
"fastapi[standard]>=0.116.1",
13-
"requests>=2.32.4",
12+
"fastapi>=0.125.0",
13+
"httpx>=0.28.1",
14+
"uvicorn>=0.38.0",
1415
]
1516

1617
[dependency-groups]

backend/uv.lock

Lines changed: 94 additions & 503 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose-dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
container_name: slcm-frontend
44
build: frontend
55
ports:
6-
- 80:80
6+
- 8080:8080
77
restart: unless-stopped
88
depends_on:
99
- backend

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
container_name: slcm-frontend
44
image: ghcr.io/dk10ws/slcm-frontend:latest
55
ports:
6-
- 80:80
6+
- 8080:8080
77
restart: unless-stopped
88
depends_on:
99
- backend

frontend/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ RUN flutter pub get
77
RUN flutter build web
88

99

10-
FROM nginx:alpine-slim AS runner
10+
FROM nginxinc/nginx-unprivileged:stable-alpine-slim
1111

12-
COPY --from=builder /app/build/web /usr/share/nginx/html
12+
COPY --chown=nginx:nginx --from=builder /app/build/web /usr/share/nginx/html/
1313
COPY nginx.conf /etc/nginx/conf.d/default.conf
1414

15-
CMD ["nginx", "-g", "daemon off;"]
15+
EXPOSE 8080

frontend/Dockerfile.actions

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM nginxinc/nginx-unprivileged:stable-alpine-slim
2+
3+
COPY --chown=nginx:nginx build/web /usr/share/nginx/html/
4+
COPY nginx.conf /etc/nginx/conf.d/default.conf
5+
6+
EXPOSE 8080

frontend/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server {
2-
listen 80;
2+
listen 8080;
33
server_name _;
44

55
root /usr/share/nginx/html;

0 commit comments

Comments
 (0)