Skip to content

Build Docker images #319

Build Docker images

Build Docker images #319

Workflow file for this run

name: Build Docker images
on:
push:
branches:
- main
paths:
- 'base_images/**'
- '!base_images/.gitignore'
- '!base_images/README*'
pull_request:
paths:
- 'base_images/**'
- '!base_images/.gitignore'
- '!base_images/README*'
schedule:
# build daily -- build a little after midnight to avoid usage spikes
- cron: '47 0 * * *'
workflow_dispatch:
jobs:
# phase 1
list:
runs-on: ubuntu-latest
outputs:
component_matrix: ${{ steps.ns_list.outputs.output_matrix }}
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
base_images
sparse-checkout-cone-mode: false
- name: setup base images directory
run: |
mv base_images/* .
rm -rf base_images
- uses: viash-io/viash-actions/setup@v6
- id: ns_list
uses: viash-io/viash-actions/ns-list@v6
with:
engine: docker
format: json
# phase 2
build:
needs: list
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
component: ${{ fromJson(needs.list.outputs.component_matrix) }}
steps:
# Remove unnecessary files to free up space.
- uses: data-intuitive/reclaim-the-bytes@v2
- uses: actions/checkout@v4
with:
sparse-checkout: |
base_images
sparse-checkout-cone-mode: false
- name: setup base images directory
run: |
mv base_images/* .
rm -rf base_images
- uses: viash-io/viash-actions/setup@v6
- name: Login to Docker Hub container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PAT }}
- name: Log in to NVIDIA container registry
uses: docker/login-action@v3
with:
registry: nvcr.io
username: '$oauthtoken'
password: ${{ secrets.NVCR_API_KEY }}
- name: Build image
run: |
viash run ${{matrix.component.config}} -- \
---engine docker \
---setup build \
---verbose
- name: Test component
run: |
viash test ${{matrix.component.config}} \
--engine docker
# only push the image if event is not a pull request
- name: Push image
if: github.event_name != 'pull_request'
run: |
viash run ${{matrix.component.config}} -- \
---engine docker \
---setup push \
---verbose
IMAGE_ID=$(
viash run ${{matrix.component.config}} -- \
---engine docker \
---docker_image_id 2> /dev/null
)
# also push major and major.minor tags
if [[ $IMAGE_ID =~ ^([^:]+):([0-9]+)\.([0-9]+)\.[0-9]+$ ]]; then
MAJOR_MINOR_TAG="${BASH_REMATCH[1]}:${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
echo "Tagging image with major.minor version: $MAJOR_MINOR_TAG"
docker tag "$IMAGE_ID" "$MAJOR_MINOR_TAG"
docker push "$MAJOR_MINOR_TAG"
MAJOR_TAG="${BASH_REMATCH[1]}:${BASH_REMATCH[2]}"
echo "Tagging image with major version: $MAJOR_TAG"
docker tag "$IMAGE_ID" "$MAJOR_TAG"
docker push "$MAJOR_TAG"
else
echo "Image ID does not match expected format, skipping major.minor tagging."
fi