Skip to content

Commit

Permalink
native multi-arch
Browse files Browse the repository at this point in the history
  • Loading branch information
AyodeAwe committed Aug 21, 2023
1 parent 75cad91 commit e554f11
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 88 deletions.
30 changes: 30 additions & 0 deletions .github/actions/compute-matrix/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'Compute Matrix Action'
description: 'Computes matrix'
outputs:
MATRIX:
description: "Computed matrix"
value: ${{ steps.compute-matrix.outputs.MATRIX }}
LATEST_LINUX_VER:
description: "Latest Linux version"
value: ${{ steps.latest-values.outputs.LATEST_LINUX_VER }}
LATEST_CUDA_VER:
description: "Latest CUDA version"
value: ${{ steps.latest-values.outputs.LATEST_CUDA_VER }}
LATEST_PYTHON_VER:
description: "Latest Python version"
value: ${{ steps.latest-values.outputs.LATEST_PYTHON_VER }}
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Compute latest values
id: latest-values
run: ./ci/compute-latest-versions.sh
shell: bash
- name: Compute matrix
id: compute-matrix
run: |
MATRIX=$(ci/compute-matrix.sh)
echo "MATRIX=${MATRIX}" | tee -a ${GITHUB_OUTPUT}
shell: bash
109 changes: 59 additions & 50 deletions .github/workflows/build-and-publish-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: build and publish imgs workflow
on:
workflow_call:
inputs:
push:
build_type:
required: true
type: boolean
type: string

defaults:
run:
Expand All @@ -15,71 +15,80 @@ jobs:
compute-matrix:
runs-on: ubuntu-latest
outputs:
LATEST_LINUX_VER: ${{ steps.latest-values.outputs.LATEST_LINUX_VER }}
LATEST_CUDA_VER: ${{ steps.latest-values.outputs.LATEST_CUDA_VER }}
LATEST_PYTHON_VER: ${{ steps.latest-values.outputs.LATEST_PYTHON_VER }}
MATRIX: ${{ steps.compute-matrix.outputs.MATRIX }}
LATEST_LINUX_VER: ${{ steps.compute-matrix.outputs.LATEST_LINUX_VER }}
LATEST_CUDA_VER: ${{ steps.compute-matrix.outputs.LATEST_CUDA_VER }}
LATEST_PYTHON_VER: ${{ steps.compute-matrix.outputs.LATEST_PYTHON_VER }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Compute latest values
id: latest-values
run: ./ci/compute-latest-versions.sh
run: ci/compute-latest-versions.sh
- name: Compute matrix
id: compute-matrix
run: ./ci/compute-matrix.sh
run: |
MATRIX=$(ci/compute-matrix.sh)
echo "MATRIX=${MATRIX}" | tee -a ${GITHUB_OUTPUT}
env:
BUILD_TYPE: ${{ inputs.BUILD_TYPE }}
docker:
name: docker
needs: compute-matrix
runs-on: ubuntu-latest
env:
DOCKERHUB_USERNAME: ${{ secrets.GPUCIBOT_DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.GPUCIBOT_DOCKERHUB_TOKEN }}
strategy:
matrix: ${{ fromJSON(needs.compute-matrix.outputs.MATRIX) }}
fail-fast: false
secrets: inherit
uses: ./.github/workflows/build-image.yml
with:
ARCHES: ${{ toJSON(matrix.ARCHES) }}
CUDA_VER: ${{ matrix.CUDA_VER }}
LINUX_VER: ${{ matrix.LINUX_VER }}
PYTHON_VER: ${{ matrix.PYTHON_VER }}
IMAGE_REPO: ${{ matrix.IMAGE_REPO }}
IMAGE_NAME: ${{ matrix.IMAGE_NAME }}

build-multiarch-manifest:
name: manifest (${{ matrix.CUDA_VER }}, ${{ matrix.PYTHON_VER }}, ${{ matrix.LINUX_VER }}, ${{ matrix.IMAGE_REPO }})
needs: [docker, compute-matrix]
strategy:
matrix: ${{ fromJSON(needs.compute-matrix.outputs.MATRIX) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- if: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }}
name: Login to DockerHub
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Compute Tags
id: compute-tags
run: |
set -x
TAGS="rapidsai/ci:cuda${{ matrix.CUDA_VER }}-${{ matrix.LINUX_VER }}-py${{ matrix.PYTHON_VER }}"
if [[
"${{ needs.compute-matrix.outputs.LATEST_LINUX_VER }}" == "${{ matrix.LINUX_VER }}" &&
"${{ needs.compute-matrix.outputs.LATEST_CUDA_VER }}" == "${{ matrix.CUDA_VER }}" &&
"${{ needs.compute-matrix.outputs.LATEST_PYTHON_VER }}" == "${{ matrix.PYTHON_VER }}"
]]; then
TAGS+=",rapidsai/ci:latest"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_OUTPUT}
- name: Compute Platforms
id: compute-platforms
run: ./ci/compute-arch.sh
username: ${{ secrets.GPUCIBOT_DOCKERHUB_USER }}
password: ${{ secrets.GPUCIBOT_DOCKERHUB_TOKEN }}
- name: Create multiarch manifest
env:
ARCHES: ${{ toJSON(matrix.ARCHES) }}
CUDA_VER: ${{ matrix.CUDA_VER }}
LINUX_VER: ${{ matrix.LINUX_VER }}
- name: Build and push
timeout-minutes: 20
uses: docker/build-push-action@v4
with:
context: context
file: Dockerfile
platforms: ${{ steps.compute-platforms.outputs.PLATFORMS }}
push: ${{ inputs.push }}
pull: true
build-args: |
CUDA_VER=${{ matrix.CUDA_VER }}
LINUX_VER=${{ matrix.LINUX_VER }}
PYTHON_VER=${{ matrix.PYTHON_VER }}
tags: ${{ steps.compute-tags.outputs.TAGS }}
PYTHON_VER: ${{ matrix.PYTHON_VER }}
IMAGE_REPO: ${{ matrix.IMAGE_REPO }}
BUILD_TYPE: ${{ inputs.build_type }}
IMAGE_NAME: ${{ matrix.IMAGE_NAME }}
LATEST_CUDA_VER: ${{ needs.compute-matrix.outputs.LATEST_CUDA_VER }}
LATEST_PYTHON_VER: ${{ needs.compute-matrix.outputs.LATEST_PYTHON_VER }}
LATEST_UBUNTU_VER: ${{ needs.compute-matrix.outputs.LATEST_LINUX_VER }}
run: ci/create-multiarch-manifest.sh

delete-temp-images:
needs: [compute-matrix, build-multiarch-manifest]
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.compute-matrix.outputs.MATRIX) }}
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Remove temporary images
run: ci/remove-temp-images.sh
env:
GPUCIBOT_DOCKERHUB_USER: ${{ secrets.GPUCIBOT_DOCKERHUB_USER }}
GPUCIBOT_DOCKERHUB_TOKEN: ${{ secrets.GPUCIBOT_DOCKERHUB_TOKEN }}
IMAGE_NAME: ${{ matrix.IMAGE_NAME }}
ARCHES: ${{ toJSON(matrix.ARCHES) }}
64 changes: 64 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build and push image variant

on:
workflow_call:
inputs:
ARCHES:
required: true
type: string
CUDA_VER:
required: true
type: string
LINUX_VER:
required: true
type: string
PYTHON_VER:
required: true
type: string
IMAGE_REPO:
required: true
type: string
IMAGE_NAME:
required: true
type: string

jobs:
run:
name: build (${{ matrix.CUDA_VER }}, ${{ matrix.PYTHON_VER }}, ${{ matrix.LINUX_VER }}, ${{ matrix.ARCH }})
strategy:
matrix:
ARCH: ${{ fromJSON(inputs.ARCHES) }}
CUDA_VER: ["${{ inputs.CUDA_VER }}"]
LINUX_VER: ["${{ inputs.LINUX_VER }}"]
PYTHON_VER: ["${{ inputs.PYTHON_VER }}"]
fail-fast: false
runs-on: linux-${{ matrix.ARCH }}-cpu4
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.GPUCIBOT_DOCKERHUB_USER }}
password: ${{ secrets.GPUCIBOT_DOCKERHUB_TOKEN }}
- name: Set up Docker Context for Buildx
run: |
docker context create builders
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver: docker
endpoint: builders
- name: Build image
uses: docker/build-push-action@v4
with:
context: ./${{ inputs.IMAGE_REPO }}
file: ./${{ inputs.IMAGE_REPO }}/Dockerfile
push: true
pull: true
build-args: |
CUDA_VER=${{ inputs.CUDA_VER }}
LINUX_VER=${{ inputs.LINUX_VER }}
PYTHON_VER=${{ inputs.PYTHON_VER }}
TARGETPLATFORM=${{ matrix.ARCH }}
tags: ${{ inputs.IMAGE_NAME }}-${{ matrix.ARCH }}
6 changes: 4 additions & 2 deletions .github/workflows/prs.yml → .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: ci

on:
pull_request:
push:
branches:
- "pull-request/[0-9]+"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -11,5 +13,5 @@ jobs:
build-images:
uses: ./.github/workflows/build-and-publish-images.yml
with:
push: false
build_type: pull-request
secrets: inherit
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml → .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: publish

on:
workflow_dispatch:
push:
branches:
- "main"
workflow_dispatch:
- main

concurrency:
group: "${{ github.workflow }} @ ${{ github.ref }}"
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-images:
uses: ./.github/workflows/build-and-publish-images.yml
with:
push: true
build_type: branch
secrets: inherit
24 changes: 0 additions & 24 deletions ci/compute-arch.sh

This file was deleted.

61 changes: 61 additions & 0 deletions ci/compute-matrix.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
def compute_arch($x):
["amd64"] |
if
["ubuntu18.04", "centos7"] | index($x.LINUX_VER) != null
then
.
else
. + ["arm64"]
end |
$x + {ARCHES: .};

def compute_repo($x):
if
env.BUILD_TYPE == "pull-request"
then
"staging"
else
$x.IMAGE_REPO
end;

def compute_tag_prefix($x):
if
env.BUILD_TYPE == "branch"
then
""
else
$x.IMAGE_REPO + "-" + env.PR_NUM + "-"
end;

def compute_image_name($x):
compute_repo($x) as $repo |
compute_tag_prefix($x) as $tag_prefix |
"rapidsai/" + $repo + ":" + $tag_prefix + "cuda" + $x.CUDA_VER + "-" + $x.LINUX_VER + "-" + "py" + $x.PYTHON_VER |
$x + {IMAGE_NAME: .};

# Checks the current entry to see if it matches the given exclude
def matches($entry; $exclude):
all($exclude | to_entries | .[]; $entry[.key] == .value);

# Checks the current entry to see if it matches any of the excludes.
# If so, produce no output. Otherwise, output the entry.
def filter_excludes($entry; $excludes):
select(any($excludes[]; matches($entry; .)) | not);

def lists2dict($keys; $values):
reduce range($keys | length) as $ind ({}; . + {($keys[$ind]): $values[$ind]});

def compute_matrix($input):
($input.exclude // []) as $excludes |
$input | del(.exclude) |
keys_unsorted as $matrix_keys |
to_entries |
map(.value) |
[
combinations |
lists2dict($matrix_keys; .) |
filter_excludes(.; $excludes) |
compute_arch(.) |
compute_image_name(.)
] |
{include: .};
22 changes: 14 additions & 8 deletions ci/compute-matrix.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/bin/bash
# Computes matrix based on "axis.yaml" values. Will also
# remove any keys (e.g. LATEST_VERSIONS) that are not used
# for the matrix build.
# Example Usage:
# ./ci/compute-matrix.sh
set -eu
set -euo pipefail

MATRIX=$(yq -o json '. | del(.LATEST_VERSIONS)' axis.yaml | jq -c)
echo "MATRIX=${MATRIX}" | tee --append ${GITHUB_OUTPUT:-/dev/null}
case "${BUILD_TYPE}" in
pull-request)
export PR_NUM="${GITHUB_REF_NAME##*/}"
;;
branch)
;;
*)
echo "Invalid build type: '${BUILD_TYPE}'"
exit 1
;;
esac

yq -o json matrix.yaml | jq -c 'include "ci/compute-matrix"; compute_matrix(.)'
Loading

0 comments on commit e554f11

Please sign in to comment.