1+ name : Docker Build and Push
2+
3+ on :
4+ push :
5+ branches : [ main, develop ]
6+ paths :
7+ - ' amd64/**'
8+ - ' .github/workflows/docker-build.yml'
9+ pull_request :
10+ branches : [ main ]
11+ paths :
12+ - ' amd64/**'
13+ release :
14+ types : [ published ]
15+ schedule :
16+ - cron : ' 0 2 * * 1' # Weekly Monday 2 AM UTC
17+
18+ env :
19+ BUILD_VERSION : ${{ github.run_number }}
20+ BUILD_TIMESTAMP : ${{ github.event.head_commit.timestamp }}
21+
22+ jobs :
23+ detect-changes :
24+ runs-on : ubuntu-latest
25+ outputs :
26+ gcc-alpine : ${{ steps.changes.outputs.gcc-alpine }}
27+ gcc-alpine-edge : ${{ steps.changes.outputs.gcc-alpine-edge }}
28+ gcc14 : ${{ steps.changes.outputs.gcc14 }}
29+ gcc-cuda : ${{ steps.changes.outputs.gcc-cuda }}
30+ steps :
31+ - name : Checkout
32+ uses : actions/checkout@v4
33+
34+ - name : Detect changed files
35+ uses : dorny/paths-filter@v2
36+ id : changes
37+ with :
38+ filters : |
39+ gcc-alpine:
40+ - 'amd64/Dockerfile.alpine'
41+ gcc-alpine-edge:
42+ - 'amd64/Dockerfile.alpine'
43+ gcc14:
44+ - 'amd64/Dockerfile.ubuntu'
45+ gcc-cuda:
46+ - 'amd64/Dockerfile.nvidia-cuda'
47+
48+ build-and-push :
49+ needs : detect-changes
50+ runs-on : ubuntu-latest
51+ if : |
52+ needs.detect-changes.outputs.gcc-alpine == 'true' ||
53+ needs.detect-changes.outputs.gcc-alpine-edge == 'true' ||
54+ needs.detect-changes.outputs.gcc14 == 'true' ||
55+ needs.detect-changes.outputs.gcc-cuda == 'true' ||
56+ github.event_name == 'release' ||
57+ github.event_name == 'schedule'
58+
59+ strategy :
60+ matrix :
61+ include :
62+ - service : gcc-alpine
63+ dockerfile : Dockerfile.alpine
64+ platforms : linux/amd64,linux/arm64
65+ condition : ${{ needs.detect-changes.outputs.gcc-alpine == 'true' || github.event_name == 'release' || github.event_name == 'schedule' }}
66+ - service : gcc-alpine-edge
67+ dockerfile : Dockerfile.alpine
68+ platforms : linux/amd64,linux/arm64
69+ build_args : IMG_TAG=edge
70+ condition : ${{ needs.detect-changes.outputs.gcc-alpine-edge == 'true' || github.event_name == 'release' || github.event_name == 'schedule' }}
71+ - service : gcc14
72+ dockerfile : Dockerfile.ubuntu
73+ platforms : linux/amd64,linux/arm64
74+ build_args : GCC_VERSION=14
75+ condition : ${{ needs.detect-changes.outputs.gcc14 == 'true' || github.event_name == 'release' || github.event_name == 'schedule' }}
76+ - service : gcc-cuda
77+ dockerfile : Dockerfile.nvidia-cuda
78+ platforms : linux/amd64
79+ build_args : IMG_TAG=13.0.2-devel-ubuntu24.04,GCC_VERSION=14
80+ condition : ${{ needs.detect-changes.outputs.gcc-cuda == 'true' || github.event_name == 'release' || github.event_name == 'schedule' }}
81+
82+ steps :
83+ - name : Checkout
84+ uses : actions/checkout@v4
85+
86+ - name : Set up Docker Buildx
87+ uses : docker/setup-buildx-action@v3
88+ with :
89+ platforms : ${{ matrix.platforms }}
90+
91+ - name : Login to Docker Hub
92+ if : github.event_name != 'pull_request'
93+ uses : docker/login-action@v3
94+ with :
95+ username : ${{ secrets.DOCKERHUB_USERNAME }}
96+ password : ${{ secrets.DOCKERHUB_TOKEN }}
97+
98+ - name : Extract metadata
99+ id : meta
100+ uses : docker/metadata-action@v5
101+ with :
102+ images : krthkj/cpp
103+ tags : |
104+ type=ref,event=branch,suffix=-${{ matrix.service }}
105+ type=ref,event=pr,suffix=-${{ matrix.service }}
106+ type=semver,pattern={{version}},suffix=-${{ matrix.service }}
107+ type=semver,pattern={{major}}.{{minor}},suffix=-${{ matrix.service }}
108+ type=raw,value=latest,suffix=-${{ matrix.service }}
109+ type=raw,value=${{ env.BUILD_VERSION }},suffix=-${{ matrix.service }}
110+ type=raw,value=${{ env.BUILD_TIMESTAMP }},suffix=-${{ matrix.service }}
111+
112+ - name : Build and push
113+ uses : docker/build-push-action@v5
114+ with :
115+ context : .
116+ file : ./amd64/${{ matrix.dockerfile }}
117+ platforms : ${{ matrix.platforms }}
118+ push : ${{ github.event_name != 'pull_request' }}
119+ tags : |
120+ krthkj/cpp:${{ matrix.service }}:latest
121+ krthkj/cpp:${{ matrix.service }}:${{ env.BUILD_VERSION }}
122+ krthkj/cpp:${{ matrix.service }}:${{ env.BUILD_TIMESTAMP }}
123+ build-args : ${{ matrix.build_args }}
124+ cache-from : type=gha
125+ cache-to : type=gha,mode=max
126+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments