Skip to content

Commit 5078bde

Browse files
committed
added ci-cd changes
1 parent ff85a29 commit 5078bde

4 files changed

Lines changed: 420 additions & 0 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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 }}

.github/workflows/docker-pr.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Docker Pull Request Validation
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
paths:
7+
- 'amd64/**'
8+
9+
env:
10+
BUILD_VERSION: pr-${{ github.event.number }}
11+
BUILD_TIMESTAMP: ${{ github.event.head_commit.timestamp }}
12+
13+
jobs:
14+
validate-pr:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
gcc-alpine: ${{ steps.changes.outputs.gcc-alpine }}
18+
gcc-alpine-edge: ${{ steps.changes.outputs.gcc-alpine-edge }}
19+
gcc14: ${{ steps.changes.outputs.gcc14 }}
20+
gcc-cuda: ${{ steps.changes.outputs.gcc-cuda }}
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Detect changed files
28+
uses: dorny/paths-filter@v2
29+
id: changes
30+
with:
31+
filters: |
32+
gcc-alpine:
33+
- 'amd64/Dockerfile.alpine'
34+
gcc-alpine-edge:
35+
- 'amd64/Dockerfile.alpine'
36+
gcc14:
37+
- 'amd64/Dockerfile.ubuntu'
38+
gcc-cuda:
39+
- 'amd64/Dockerfile.nvidia-cuda'
40+
41+
test-build:
42+
needs: validate-pr
43+
runs-on: ubuntu-latest
44+
if: |
45+
needs.validate-pr.outputs.gcc-alpine == 'true' ||
46+
needs.validate-pr.outputs.gcc-alpine-edge == 'true' ||
47+
needs.validate-pr.outputs.gcc14 == 'true' ||
48+
needs.validate-pr.outputs.gcc-cuda == 'true'
49+
50+
strategy:
51+
matrix:
52+
include:
53+
- service: gcc-alpine
54+
dockerfile: Dockerfile.alpine
55+
platforms: linux/amd64
56+
condition: ${{ needs.validate-pr.outputs.gcc-alpine == 'true' }}
57+
- service: gcc-alpine-edge
58+
dockerfile: Dockerfile.alpine
59+
platforms: linux/amd64
60+
build_args: IMG_TAG=edge
61+
condition: ${{ needs.validate-pr.outputs.gcc-alpine-edge == 'true' }}
62+
- service: gcc14
63+
dockerfile: Dockerfile.ubuntu
64+
platforms: linux/amd64
65+
build_args: GCC_VERSION=14
66+
condition: ${{ needs.validate-pr.outputs.gcc14 == 'true' }}
67+
- service: gcc-cuda
68+
dockerfile: Dockerfile.nvidia-cuda
69+
platforms: linux/amd64
70+
build_args: IMG_TAG=13.0.2-devel-ubuntu24.04,GCC_VERSION=14
71+
condition: ${{ needs.validate-pr.outputs.gcc-cuda == 'true' }}
72+
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@v4
76+
77+
- name: Set up Docker Buildx
78+
uses: docker/setup-buildx-action@v3
79+
with:
80+
platforms: ${{ matrix.platforms }}
81+
82+
- name: Test build (no push)
83+
uses: docker/build-push-action@v5
84+
with:
85+
context: .
86+
file: ./amd64/${{ matrix.dockerfile }}
87+
platforms: ${{ matrix.platforms }}
88+
push: false
89+
load: true
90+
tags: |
91+
krthkj/cpp:${{ matrix.service }}:test-${{ env.BUILD_VERSION }}
92+
build-args: ${{ matrix.build_args }}
93+
cache-from: type=gha
94+
95+
- name: Test container functionality
96+
run: |
97+
echo "Testing ${{ matrix.service }} container..."
98+
docker run --rm krthkj/cpp:${{ matrix.service }}:test-${{ env.BUILD_VERSION }} gcc --version
99+
docker run --rm krthkj/cpp:${{ matrix.service }}:test-${{ env.BUILD_VERSION }} cmake --version
100+
101+
- name: Security scan
102+
uses: aquasecurity/trivy-action@master
103+
with:
104+
image-ref: krthkj/cpp:${{ matrix.service }}:test-${{ env.BUILD_VERSION }}
105+
format: 'sarif'
106+
output: 'trivy-results.sarif'
107+
108+
- name: Upload Trivy scan results
109+
uses: github/codeql-action/upload-sarif@v2
110+
if: always()
111+
with:
112+
sarif_file: 'trivy-results.sarif'
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Docker Scheduled Maintenance
2+
3+
on:
4+
schedule:
5+
- cron: '0 2 * * 1' # Weekly Monday 2 AM UTC
6+
workflow_dispatch: # Manual trigger
7+
8+
env:
9+
BUILD_VERSION: scheduled-${{ github.run_number }}
10+
BUILD_TIMESTAMP: ${{ github.event.head_commit.timestamp }}
11+
12+
jobs:
13+
maintenance-build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
include:
19+
- service: gcc-alpine
20+
dockerfile: Dockerfile.alpine
21+
platforms: linux/amd64,linux/arm64
22+
- service: gcc-alpine-edge
23+
dockerfile: Dockerfile.alpine
24+
platforms: linux/amd64,linux/arm64
25+
build_args: IMG_TAG=edge
26+
- service: gcc14
27+
dockerfile: Dockerfile.ubuntu
28+
platforms: linux/amd64,linux/arm64
29+
build_args: GCC_VERSION=14
30+
- service: gcc-cuda
31+
dockerfile: Dockerfile.nvidia-cuda
32+
platforms: linux/amd64
33+
build_args: IMG_TAG=13.0.2-devel-ubuntu24.04,GCC_VERSION=14
34+
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
with:
42+
platforms: ${{ matrix.platforms }}
43+
44+
- name: Login to Docker Hub
45+
uses: docker/login-action@v3
46+
with:
47+
username: ${{ secrets.DOCKERHUB_USERNAME }}
48+
password: ${{ secrets.DOCKERHUB_TOKEN }}
49+
50+
- name: Build and push
51+
uses: docker/build-push-action@v5
52+
with:
53+
context: .
54+
file: ./amd64/${{ matrix.dockerfile }}
55+
platforms: ${{ matrix.platforms }}
56+
push: true
57+
tags: |
58+
krthkj/cpp:${{ matrix.service }}:latest
59+
krthkj/cpp:${{ matrix.service }}:${{ env.BUILD_VERSION }}
60+
krthkj/cpp:${{ matrix.service }}:${{ env.BUILD_TIMESTAMP }}
61+
build-args: ${{ matrix.build_args }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
64+
65+
cleanup-old-images:
66+
runs-on: ubuntu-latest
67+
needs: maintenance-build
68+
if: github.event_name == 'schedule'
69+
70+
steps:
71+
- name: Checkout
72+
uses: actions/checkout@v4
73+
74+
- name: Delete old Docker Hub images
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
// This would require a custom script or Docker Hub API integration
79+
// For now, this is a placeholder for manual cleanup
80+
console.log('Cleanup task - implement Docker Hub API calls to remove old tags')

0 commit comments

Comments
 (0)