Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit d42fcde

Browse files
VianpyroVianpyro
andauthored
Refactor devcontainer configuration (#9)
Refactor devcontainer configuration and add workflow for rebuilding devcontainer image Co-authored-by: Vianpyro <vianney@veremme.org>
1 parent d9c3b7e commit d42fcde

3 files changed

Lines changed: 130 additions & 16 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "ChocoMax API Development Container",
3-
"dockerFile": "Dockerfile",
2+
"name": "ChocoMax API",
3+
"image": "ghcr.io/themaximousse/api-devcontainer:latest",
44
"customizations": {
55
"settings": {
66
"terminal.integrated.shell.linux": "/bin/bash"
Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,107 @@
11
---
2-
name: Package Docker Image
2+
name: Package Docker Images
33

44
permissions:
55
packages: write
6+
contents: write
67

78
on:
89
push:
910
branches:
1011
- main
11-
workflow_dispatch:
12+
paths:
13+
- 'app/**/*.py'
14+
- '.devcontainer/**'
15+
- '.github/workflows/package-docker-images.yml'
1216

1317
jobs:
14-
docker:
18+
build-docker-images:
19+
name: Build and push ${{ matrix.name }} image
1520
runs-on: ubuntu-latest
21+
continue-on-error: true
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
- name: api
27+
context: ./
28+
dockerfile: Dockerfile
29+
path_filter: api/
30+
needs_api_url: true
31+
- name: api-devcontainer
32+
context: ./.devcontainer
33+
dockerfile: .devcontainer/Dockerfile
34+
path_filter: .devcontainer/
35+
needs_api_url: true
1636

1737
steps:
1838
- uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Check if build is needed
43+
id: check_changes
44+
run: |
45+
# Check if files in the component's directory were changed
46+
if git diff --name-only HEAD~1 HEAD | grep -q "^${{ matrix.path_filter }}" || \
47+
git diff --name-only HEAD~1 HEAD | grep -q "^\.github/workflows/package-docker-images\.yml"; then
48+
echo "should_build=true" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "should_build=false" >> "$GITHUB_OUTPUT"
51+
fi
1952
2053
- name: Extract version
54+
if: steps.check_changes.outputs.should_build == 'true'
2155
id: version
2256
run: |
23-
VERSION=$(grep -oP '__version__\s*=\s*"\K[0-9]+\.[0-9]+\.[0-9]+' app/version.py)
57+
VERSION=$(date +%y.%m.%d.%H.%M)
2458
echo "tag=$VERSION" >> "$GITHUB_OUTPUT"
2559
26-
- uses: docker/login-action@v3
60+
- name: Normalize repository owner
61+
if: steps.check_changes.outputs.should_build == 'true'
62+
id: repo_owner
63+
run: echo "name=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
64+
65+
- name: Validate Dockerfile exists
66+
if: steps.check_changes.outputs.should_build == 'true'
67+
run: |
68+
test -f "${{ matrix.dockerfile }}" || (echo "Dockerfile not found at ${{ matrix.dockerfile }}" && exit 1)
69+
70+
- name: Set up QEMU
71+
if: steps.check_changes.outputs.should_build == 'true'
72+
uses: docker/setup-qemu-action@v3
73+
74+
- name: Set up Docker Buildx
75+
if: steps.check_changes.outputs.should_build == 'true'
76+
uses: docker/setup-buildx-action@v3
77+
78+
- name: Login to GHCR
79+
if: steps.check_changes.outputs.should_build == 'true'
80+
uses: docker/login-action@v3
2781
with:
2882
registry: ghcr.io
2983
username: ${{ github.actor }}
3084
password: ${{ secrets.GITHUB_TOKEN }}
3185

32-
- name: Normalize image name
33-
run: |
34-
echo "REPO_LOWER=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
86+
- name: Build and push ${{ matrix.name }} image
87+
if: steps.check_changes.outputs.should_build == 'true'
88+
uses: docker/build-push-action@v5
89+
with:
90+
context: ${{ matrix.context }}
91+
platforms: linux/amd64,linux/arm64
92+
push: true
93+
build-args: ${{ matrix.needs_api_url == true && format('PUBLIC_API_URL={0}', secrets.PUBLIC_API_URL) || '' }}
94+
tags: |
95+
ghcr.io/${{ steps.repo_owner.outputs.name }}/${{ matrix.name }}:${{ steps.version.outputs.tag }}
96+
ghcr.io/${{ steps.repo_owner.outputs.name }}/${{ matrix.name }}:latest
97+
cache-from: type=gha,scope=${{ matrix.name }}
98+
cache-to: type=gha,mode=max,scope=${{ matrix.name }}
3599

36-
- name: Build and push Docker image
37-
run: |
38-
IMAGE="ghcr.io/${REPO_LOWER}-image:${{ steps.version.outputs.tag }}"
39-
echo "🔨 Building image: $IMAGE"
40-
docker build -t "$IMAGE" .
41-
docker push "$IMAGE"
100+
- name: Generate SBOM
101+
if: steps.check_changes.outputs.should_build == 'true'
102+
uses: anchore/sbom-action@v0
103+
with:
104+
image: ghcr.io/${{ steps.repo_owner.outputs.name }}/${{ matrix.name }}:${{ steps.version.outputs.tag }}
105+
format: spdx-json
106+
upload-release-assets: false
107+
artifact-name: sbom-${{ matrix.name }}-${{ steps.version.outputs.tag }}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: Rebuild Devcontainer to Update Dependencies
3+
4+
permissions:
5+
packages: write
6+
contents: write
7+
8+
on:
9+
schedule:
10+
- cron: '0 4 1 * *' # Run monthly on the 1st at 4 AM UTC
11+
workflow_dispatch:
12+
13+
jobs:
14+
rebuild-devcontainer:
15+
name: Rebuild devcontainer base image
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v3
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Login to GHCR
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Extract version
34+
id: version
35+
run: |
36+
VERSION=$(date +%y.%m.%d.%H.%M)
37+
echo "tag=$VERSION" >> "$GITHUB_OUTPUT"
38+
39+
- name: Build and push devcontainer image
40+
uses: docker/build-push-action@v5
41+
with:
42+
context: ./.devcontainer
43+
platforms: linux/amd64,linux/arm64
44+
push: true
45+
no-cache: true
46+
tags: |
47+
ghcr.io/${{ github.repository_owner }}/api-devcontainer:${{ steps.version.outputs.tag }}
48+
ghcr.io/${{ github.repository_owner }}/api-devcontainer:latest

0 commit comments

Comments
 (0)