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