Skip to content

Commit dfcc693

Browse files
committed
ci: add GitHub Actions workflow for building and pushing DevContainer images
1 parent ae01daf commit dfcc693

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Build and Push DevContainer Images
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
detect-changes:
8+
name: Detect Changed Images
9+
runs-on: ubuntu-24.04
10+
outputs:
11+
node: ${{ steps.changes.outputs.node }}
12+
php+node: ${{ steps.changes.outputs.php+node }}
13+
python: ${{ steps.changes.outputs.python }}
14+
ubuntu: ${{ steps.changes.outputs.ubuntu }}
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Detect changes
22+
id: changes
23+
uses: dorny/paths-filter@v3
24+
with:
25+
filters: |
26+
'node':
27+
- 'dockerfiles/node/Dockerfile'
28+
'php+node':
29+
- 'dockerfiles/php+node/Dockerfile'
30+
'python':
31+
- 'dockerfiles/python/Dockerfile'
32+
'ubuntu':
33+
- 'dockerfiles/ubuntu/Dockerfile'
34+
35+
build-and-push:
36+
name: Build ${{ matrix.image }}
37+
needs: detect-changes
38+
if: |
39+
needs.detect-changes.outputs.node == 'true' ||
40+
needs.detect-changes.outputs.php+node == 'true' ||
41+
needs.detect-changes.outputs.python == 'true' ||
42+
needs.detect-changes.outputs.ubuntu == 'true'
43+
runs-on: ubuntu-24.04
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
include:
48+
- image: node
49+
changed: ${{ needs.detect-changes.outputs.node }}
50+
- image: php+node
51+
changed: ${{ needs.detect-changes.outputs.php+node }}
52+
- image: python
53+
changed: ${{ needs.detect-changes.outputs.python }}
54+
- image: ubuntu
55+
changed: ${{ needs.detect-changes.outputs.ubuntu }}
56+
steps:
57+
- name: Skip if not changed
58+
if: matrix.changed != 'true'
59+
run: |
60+
echo "Skipping ${{ matrix.image }} - no changes detected"
61+
exit 0
62+
63+
- name: Checkout Repository
64+
if: matrix.changed == 'true'
65+
uses: actions/checkout@v4
66+
67+
- name: Set up Docker Buildx
68+
if: matrix.changed == 'true'
69+
uses: docker/setup-buildx-action@v3
70+
71+
- name: Log in to GitHub Container Registry
72+
if: matrix.changed == 'true'
73+
uses: docker/login-action@v3
74+
with:
75+
registry: ${{ env.REGISTRY }}
76+
username: ${{ github.actor }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Extract metadata
80+
if: matrix.changed == 'true'
81+
id: meta
82+
uses: docker/metadata-action@v5
83+
with:
84+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/devcontainer-${{ matrix.image }}
85+
tags: |
86+
type=raw,value=latest
87+
type=sha,prefix={{branch}}-
88+
type=ref,event=branch
89+
type=semver,pattern={{version}}
90+
91+
- name: Build and push
92+
if: matrix.changed == 'true'
93+
uses: docker/build-push-action@v5
94+
with:
95+
context: ./dockerfiles/${{ matrix.image }}
96+
file: ./dockerfiles/${{ matrix.image }}/Dockerfile
97+
push: true
98+
tags: ${{ steps.meta.outputs.tags }}
99+
labels: ${{ steps.meta.outputs.labels }}
100+
cache-from: type=gha
101+
cache-to: type=gha,mode=max
102+
platforms: linux/amd64,linux/arm64

0 commit comments

Comments
 (0)