Skip to content

Commit

Permalink
ci: Refactor build_base to action
Browse files Browse the repository at this point in the history
  • Loading branch information
ko3n1g committed Apr 22, 2024
1 parent 8e452da commit a132242
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 190 deletions.
157 changes: 157 additions & 0 deletions .github/actions/build_base/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: ~build CUDA+Python base container
description: Builds the base container

inputs:
ARCHITECTURE:
description: "CPU architecture to build the image for, e.g. amd64, arm64"
required: true
BASE_IMAGE:
description: "Base CUDA image, e.g. nvidia/cuda:X.Y.Z-devel-ubuntu22.04"
required: false
default: latest
BUILD_DATE:
description: "Build date in YYYY-MM-DD format"
required: false
default: "NOT SPECIFIED"
ARTIFACT_NAME:
description: "Name of the artifact zip file"
required: false
default: "artifact-base-build"
BADGE_FILENAME:
description: "Name of the endpoint JSON file for shields.io badge"
required: false
default: "badge-base-build"
GIT_USER_NAME:
description: "Username in GIT to perform git pull/push"
required: false
default: "JAX Toolbox"
GIT_USER_EMAIL:
description: "User email in GIT to perform git pull/push"
required: false
default: "[email protected]"
MANIFEST_ARTIFACT_NAME:
description: Artifact name in current run w/ manifest/patches. Leaving empty uses manifest/patches in current branch
default: ""
required: false

outputs:
DOCKER_TAG:
description: "Tag of the image built"
value: ${{ steps.meta.outputs.tags }}

runs:
using: composite
steps:
- name: Print environment variables
shell: bash
run: env

- name: Check out the repository under ${GITHUB_WORKSPACE}
uses: actions/checkout@v4

- name: Delete checked-out manifest and patches
if: inputs.MANIFEST_ARTIFACT_NAME != ''
shell: bash
run: |
rm .github/container/manifest.yaml
rm -rf .github/container/patches
- name: Replace checked-out manifest file/patches with bumped one
if: inputs.MANIFEST_ARTIFACT_NAME != ''
uses: actions/download-artifact@v4
with:
name: ${{ inputs.MANIFEST_ARTIFACT_NAME }}
path: .github/container/

- name: Log the changes in manifest file and patch folder
working-directory: .github/container
shell: bash -x -e {0}
run: |
ls -lah
ls -lah patches
echo "Changes in manifest file and patch folder"
git diff
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ env.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.12.1
- name: Set docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.UPLD_IMAGE }}
flavor: |
latest=false
tags: |
type=raw,value=${{ github.run_id }}-base-${{ inputs.ARCHITECTURE }}
labels: org.opencontainers.image.created=${{ inputs.BUILD_DATE }}

- name: Build docker images
id: build
uses: docker/build-push-action@v5
with:
context: .github/container
push: true
file: .github/container/Dockerfile.base
platforms: linux/${{ inputs.ARCHITECTURE }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_USER_NAME=${{ inputs.GIT_USER_NAME }}
GIT_USER_EMAIL=${{ inputs.GIT_USER_EMAIL }}
BUILD_DATE=${{ inputs.BUILD_DATE }}
${{ inputs.BASE_IMAGE != 'latest' && format('BASE_IMAGE={0}', inputs.BASE_IMAGE) || '' }}
- name: Generate sitrep
if: "!cancelled()"
shell: bash -x -e {0}
run: |
# bring in utility functions
source .github/workflows/scripts/to_json.sh
badge_label='Base image ${{ inputs.ARCHITECTURE }} build'
tags="${{ steps.meta.outputs.tags }}"
digest="${{ steps.build.outputs.digest }}"
outcome="${{ steps.build.outcome }}"
if [[ ${outcome} == "success" ]]; then
badge_message="pass"
badge_color=brightgreen
summary="Base image build on ${{ inputs.ARCHITECTURE }}: $badge_message"
else
badge_message="fail"
badge_color=red
summary="Base image build on ${{ inputs.ARCHITECTURE }}: $badge_message"
fi
to_json \
summary \
badge_label tags digest outcome \
> sitrep.json
schemaVersion=1 \
label="${badge_label}" \
message="${badge_message}" \
color="${badge_color}" \
to_json schemaVersion label message color \
> ${{ env.BADGE_FILENAME_FULL }}
- name: Upload sitrep and badge
if: "!cancelled()"
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.ARTIFACT_NAME }}-${{ inputs.ARCHITECTURE }}
path: |
sitrep.json
${{ env.BADGE_FILENAME_FULL }}
178 changes: 0 additions & 178 deletions .github/workflows/_build_base.yaml

This file was deleted.

25 changes: 19 additions & 6 deletions .github/workflows/_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,25 @@ permissions:

jobs:
build-base:
uses: ./.github/workflows/_build_base.yaml
with:
ARCHITECTURE: ${{ inputs.ARCHITECTURE }}
BUILD_DATE: ${{ inputs.BUILD_DATE }}
MANIFEST_ARTIFACT_NAME: ${{ inputs.MANIFEST_ARTIFACT_NAME }}
secrets: inherit
runs-on: [self-hosted, "${{ inputs.ARCHITECTURE }}", small]
env:
UPLD_IMAGE: ghcr.io/nvidia/jax-toolbox-internal
BADGE_FILENAME_FULL: ${{ inputs.BADGE_FILENAME }}-${{ inputs.ARCHITECTURE }}.json
outputs:
DOCKER_TAG: ${{ steps.main.outputs.DOCKER_TAG }}
steps:
- name: Check out the repository under ${GITHUB_WORKSPACE}
uses: actions/checkout@v4

- name: Main
id: main
uses: ./github/actions/build_base
with:
ARCHITECTURE: ${{ inputs.ARCHITECTURE }}
BUILD_DATE: ${{ inputs.BUILD_DATE }}
MANIFEST_ARTIFACT_NAME: ${{ inputs.MANIFEST_ARTIFACT_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-jax:
needs: build-base
Expand Down
Loading

0 comments on commit a132242

Please sign in to comment.