Skip to content

Commit a132242

Browse files
committed
ci: Refactor build_base to action
1 parent 8e452da commit a132242

File tree

4 files changed

+195
-190
lines changed

4 files changed

+195
-190
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: ~build CUDA+Python base container
2+
description: Builds the base container
3+
4+
inputs:
5+
ARCHITECTURE:
6+
description: "CPU architecture to build the image for, e.g. amd64, arm64"
7+
required: true
8+
BASE_IMAGE:
9+
description: "Base CUDA image, e.g. nvidia/cuda:X.Y.Z-devel-ubuntu22.04"
10+
required: false
11+
default: latest
12+
BUILD_DATE:
13+
description: "Build date in YYYY-MM-DD format"
14+
required: false
15+
default: "NOT SPECIFIED"
16+
ARTIFACT_NAME:
17+
description: "Name of the artifact zip file"
18+
required: false
19+
default: "artifact-base-build"
20+
BADGE_FILENAME:
21+
description: "Name of the endpoint JSON file for shields.io badge"
22+
required: false
23+
default: "badge-base-build"
24+
GIT_USER_NAME:
25+
description: "Username in GIT to perform git pull/push"
26+
required: false
27+
default: "JAX Toolbox"
28+
GIT_USER_EMAIL:
29+
description: "User email in GIT to perform git pull/push"
30+
required: false
31+
default: "[email protected]"
32+
MANIFEST_ARTIFACT_NAME:
33+
description: Artifact name in current run w/ manifest/patches. Leaving empty uses manifest/patches in current branch
34+
default: ""
35+
required: false
36+
37+
outputs:
38+
DOCKER_TAG:
39+
description: "Tag of the image built"
40+
value: ${{ steps.meta.outputs.tags }}
41+
42+
runs:
43+
using: composite
44+
steps:
45+
- name: Print environment variables
46+
shell: bash
47+
run: env
48+
49+
- name: Check out the repository under ${GITHUB_WORKSPACE}
50+
uses: actions/checkout@v4
51+
52+
- name: Delete checked-out manifest and patches
53+
if: inputs.MANIFEST_ARTIFACT_NAME != ''
54+
shell: bash
55+
run: |
56+
rm .github/container/manifest.yaml
57+
rm -rf .github/container/patches
58+
59+
- name: Replace checked-out manifest file/patches with bumped one
60+
if: inputs.MANIFEST_ARTIFACT_NAME != ''
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: ${{ inputs.MANIFEST_ARTIFACT_NAME }}
64+
path: .github/container/
65+
66+
- name: Log the changes in manifest file and patch folder
67+
working-directory: .github/container
68+
shell: bash -x -e {0}
69+
run: |
70+
ls -lah
71+
ls -lah patches
72+
echo "Changes in manifest file and patch folder"
73+
git diff
74+
75+
- name: Login to GitHub Container Registry
76+
uses: docker/login-action@v3
77+
with:
78+
registry: ghcr.io
79+
username: ${{ github.repository_owner }}
80+
password: ${{ env.GITHUB_TOKEN }}
81+
82+
- name: Set up Docker Buildx
83+
uses: docker/setup-buildx-action@v3
84+
with:
85+
driver-opts: |
86+
image=moby/buildkit:v0.12.1
87+
88+
- name: Set docker metadata
89+
id: meta
90+
uses: docker/metadata-action@v5
91+
with:
92+
images: |
93+
${{ env.UPLD_IMAGE }}
94+
flavor: |
95+
latest=false
96+
tags: |
97+
type=raw,value=${{ github.run_id }}-base-${{ inputs.ARCHITECTURE }}
98+
labels: org.opencontainers.image.created=${{ inputs.BUILD_DATE }}
99+
100+
- name: Build docker images
101+
id: build
102+
uses: docker/build-push-action@v5
103+
with:
104+
context: .github/container
105+
push: true
106+
file: .github/container/Dockerfile.base
107+
platforms: linux/${{ inputs.ARCHITECTURE }}
108+
tags: ${{ steps.meta.outputs.tags }}
109+
labels: ${{ steps.meta.outputs.labels }}
110+
build-args: |
111+
GIT_USER_NAME=${{ inputs.GIT_USER_NAME }}
112+
GIT_USER_EMAIL=${{ inputs.GIT_USER_EMAIL }}
113+
BUILD_DATE=${{ inputs.BUILD_DATE }}
114+
${{ inputs.BASE_IMAGE != 'latest' && format('BASE_IMAGE={0}', inputs.BASE_IMAGE) || '' }}
115+
116+
- name: Generate sitrep
117+
if: "!cancelled()"
118+
shell: bash -x -e {0}
119+
run: |
120+
# bring in utility functions
121+
source .github/workflows/scripts/to_json.sh
122+
123+
badge_label='Base image ${{ inputs.ARCHITECTURE }} build'
124+
tags="${{ steps.meta.outputs.tags }}"
125+
digest="${{ steps.build.outputs.digest }}"
126+
outcome="${{ steps.build.outcome }}"
127+
128+
if [[ ${outcome} == "success" ]]; then
129+
badge_message="pass"
130+
badge_color=brightgreen
131+
summary="Base image build on ${{ inputs.ARCHITECTURE }}: $badge_message"
132+
else
133+
badge_message="fail"
134+
badge_color=red
135+
summary="Base image build on ${{ inputs.ARCHITECTURE }}: $badge_message"
136+
fi
137+
138+
to_json \
139+
summary \
140+
badge_label tags digest outcome \
141+
> sitrep.json
142+
143+
schemaVersion=1 \
144+
label="${badge_label}" \
145+
message="${badge_message}" \
146+
color="${badge_color}" \
147+
to_json schemaVersion label message color \
148+
> ${{ env.BADGE_FILENAME_FULL }}
149+
150+
- name: Upload sitrep and badge
151+
if: "!cancelled()"
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: ${{ inputs.ARTIFACT_NAME }}-${{ inputs.ARCHITECTURE }}
155+
path: |
156+
sitrep.json
157+
${{ env.BADGE_FILENAME_FULL }}

.github/workflows/_build_base.yaml

Lines changed: 0 additions & 178 deletions
This file was deleted.

.github/workflows/_ci.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,25 @@ permissions:
2828

2929
jobs:
3030
build-base:
31-
uses: ./.github/workflows/_build_base.yaml
32-
with:
33-
ARCHITECTURE: ${{ inputs.ARCHITECTURE }}
34-
BUILD_DATE: ${{ inputs.BUILD_DATE }}
35-
MANIFEST_ARTIFACT_NAME: ${{ inputs.MANIFEST_ARTIFACT_NAME }}
36-
secrets: inherit
31+
runs-on: [self-hosted, "${{ inputs.ARCHITECTURE }}", small]
32+
env:
33+
UPLD_IMAGE: ghcr.io/nvidia/jax-toolbox-internal
34+
BADGE_FILENAME_FULL: ${{ inputs.BADGE_FILENAME }}-${{ inputs.ARCHITECTURE }}.json
35+
outputs:
36+
DOCKER_TAG: ${{ steps.main.outputs.DOCKER_TAG }}
37+
steps:
38+
- name: Check out the repository under ${GITHUB_WORKSPACE}
39+
uses: actions/checkout@v4
40+
41+
- name: Main
42+
id: main
43+
uses: ./github/actions/build_base
44+
with:
45+
ARCHITECTURE: ${{ inputs.ARCHITECTURE }}
46+
BUILD_DATE: ${{ inputs.BUILD_DATE }}
47+
MANIFEST_ARTIFACT_NAME: ${{ inputs.MANIFEST_ARTIFACT_NAME }}
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3750

3851
build-jax:
3952
needs: build-base

0 commit comments

Comments
 (0)