1818
1919env :
2020 REGISTRY : ghcr.io
21- IMAGE_BACKEND : ghcr.io/myelectricaldata/myelectricaldata_new/backend
22- IMAGE_FRONTEND : ghcr.io/myelectricaldata/myelectricaldata_new/frontend
21+ IMAGE_PREFIX : ghcr.io/myelectricaldata/myelectricaldata_new
2322
2423jobs :
25- build-and-push :
24+ # Prepare version info (shared by all build jobs)
25+ prepare :
26+ runs-on : ubuntu-latest
27+ outputs :
28+ version : ${{ steps.version.outputs.version }}
29+ steps :
30+ - name : Get version
31+ id : version
32+ run : |
33+ if [ -n "${{ github.event.inputs.version }}" ]; then
34+ VERSION="${{ github.event.inputs.version }}"
35+ elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
36+ VERSION="${{ github.ref_name }}"
37+ VERSION="${VERSION#v}"
38+ else
39+ VERSION="latest"
40+ fi
41+ echo "version=$VERSION" >> $GITHUB_OUTPUT
42+ echo "Version: $VERSION"
43+
44+ # Build images in parallel using matrix strategy
45+ build :
46+ needs : prepare
2647 runs-on : ubuntu-latest
2748 permissions :
2849 contents : read
2950 packages : write
51+ strategy :
52+ fail-fast : false
53+ matrix :
54+ include :
55+ - image : backend
56+ context : ./apps/api
57+ - image : frontend
58+ context : ./apps/web
3059
3160 steps :
3261 - name : Checkout repository
@@ -46,63 +75,39 @@ jobs:
4675 username : ${{ github.actor }}
4776 password : ${{ secrets.GITHUB_TOKEN }}
4877
49- - name : Get version
50- id : version
51- run : |
52- if [ -n "${{ github.event.inputs.version }}" ]; then
53- VERSION="${{ github.event.inputs.version }}"
54- elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
55- VERSION="${{ github.ref_name }}"
56- VERSION="${VERSION#v}"
57- else
58- VERSION="latest"
59- fi
60- echo "version=$VERSION" >> $GITHUB_OUTPUT
61- echo "Version: $VERSION"
62-
63- - name : Build and push backend
78+ - name : Build and push ${{ matrix.image }}
6479 uses : docker/build-push-action@v6
6580 with :
66- context : ./apps/api
81+ context : ${{ matrix.context }}
6782 platforms : linux/amd64,linux/arm64
6883 push : ${{ github.event_name != 'pull_request' }}
6984 tags : |
70- ${{ env.IMAGE_BACKEND }}:${{ steps.version.outputs.version }}
71- ${{ env.IMAGE_BACKEND }}:latest
72- cache-from : type=gha,scope=backend
73- cache-to : type=gha,mode=max,scope=backend
74- labels : |
75- org.opencontainers.image.source=https://github.com/${{ github.repository }}
76- org.opencontainers.image.revision=${{ github.sha }}
77-
78- - name : Build and push frontend
79- uses : docker/build-push-action@v6
80- with :
81- context : ./apps/web
82- platforms : linux/amd64,linux/arm64
83- push : ${{ github.event_name != 'pull_request' }}
84- tags : |
85- ${{ env.IMAGE_FRONTEND }}:${{ steps.version.outputs.version }}
86- ${{ env.IMAGE_FRONTEND }}:latest
87- cache-from : type=gha,scope=frontend
88- cache-to : type=gha,mode=max,scope=frontend
85+ ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:${{ needs.prepare.outputs.version }}
86+ ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:latest
87+ cache-from : type=gha,scope=${{ matrix.image }}
88+ cache-to : type=gha,mode=max,scope=${{ matrix.image }}
8989 labels : |
9090 org.opencontainers.image.source=https://github.com/${{ github.repository }}
9191 org.opencontainers.image.revision=${{ github.sha }}
9292
93+ # Summary job (runs after all builds complete)
94+ summary :
95+ needs : [prepare, build]
96+ runs-on : ubuntu-latest
97+ if : github.event_name != 'pull_request'
98+ steps :
9399 - name : Create summary
94- if : github.event_name != 'pull_request'
95100 run : |
96101 echo "## Docker Images Published 🐳" >> $GITHUB_STEP_SUMMARY
97102 echo "" >> $GITHUB_STEP_SUMMARY
98103 echo "### Images" >> $GITHUB_STEP_SUMMARY
99104 echo "| Image | Tag | Architectures |" >> $GITHUB_STEP_SUMMARY
100105 echo "|-------|-----|---------------|" >> $GITHUB_STEP_SUMMARY
101- echo "| \`${{ env.IMAGE_BACKEND }}\` | \`${{ steps.version .outputs.version }}\` | amd64, arm64 |" >> $GITHUB_STEP_SUMMARY
102- echo "| \`${{ env.IMAGE_FRONTEND }}\` | \`${{ steps.version .outputs.version }}\` | amd64, arm64 |" >> $GITHUB_STEP_SUMMARY
106+ echo "| \`${{ env.IMAGE_PREFIX }}/backend \` | \`${{ needs.prepare .outputs.version }}\` | amd64, arm64 |" >> $GITHUB_STEP_SUMMARY
107+ echo "| \`${{ env.IMAGE_PREFIX }}/frontend \` | \`${{ needs.prepare .outputs.version }}\` | amd64, arm64 |" >> $GITHUB_STEP_SUMMARY
103108 echo "" >> $GITHUB_STEP_SUMMARY
104109 echo "### Pull Commands" >> $GITHUB_STEP_SUMMARY
105110 echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
106- echo "docker pull ${{ env.IMAGE_BACKEND }}:${{ steps.version .outputs.version }}" >> $GITHUB_STEP_SUMMARY
107- echo "docker pull ${{ env.IMAGE_FRONTEND }}:${{ steps.version .outputs.version }}" >> $GITHUB_STEP_SUMMARY
111+ echo "docker pull ${{ env.IMAGE_PREFIX }}/backend :${{ needs.prepare .outputs.version }}" >> $GITHUB_STEP_SUMMARY
112+ echo "docker pull ${{ env.IMAGE_PREFIX }}/frontend :${{ needs.prepare .outputs.version }}" >> $GITHUB_STEP_SUMMARY
108113 echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
0 commit comments