Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: switch to use cloud builders for native multi-arch support #7

Merged
merged 11 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/publish-cloud-builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
# Automatically build Docker images using a cloud builder and publish them to a
# container registry using HCL Bake file.

name: Build Docker Images using Cloud Builder

on:
# workflow_dispatch:
# pull_request:
# branches: ['main']
push:
branches: ['main']
tags: ['*']

jobs:
# When pushing into main will build the regular multi-arch image
# For pull requests will use the default target to only
# generate local architecture version
bake-target:
name: Determine bake target
runs-on: ubuntu-22.04 # don't use the big runners for this small step
outputs:
target: ${{ steps.generate.outputs.bake_target }}
steps:
- name: Determine target
id: generate
run: |
# NOTE: Using direct target names instead of group names as its a single
# image build and want to use the target as part of the output image tag
if [[ '${{ github.event_name }}' == 'pull_request' ]]; then
TGT=askem-julia-base
else
TGT=askem-julia
fi

echo "$TGT"
echo "bake_target=${TGT,,}" >> ${GITHUB_OUTPUT}

- name: Show Generated Tag
run: echo ${{ steps.generate.outputs.bake_target }}

# Build and Publish all targets associated with specified group
bake:
needs:
- bake-target
uses: darpa-askem/.github/.github/workflows/bake-publish-cloud-builder.yaml@main
with:
file: 'docker/docker-bake.hcl'
group: ${{ needs.bake-target.outputs.target }}
registry: 'ghcr.io'
organization: ${{ github.repository_owner }}
secrets:
username: ${{ secrets.DOCKER_CLOUD_BUILD_USERNAME }}
token: ${{ secrets.DOCKER_CLOUD_BUILD_TOKEN }}
endpoint: "${{ secrets.DOCKER_CLOUD_BUILD_ENDPOINT }}"


54 changes: 0 additions & 54 deletions .github/workflows/publish.yaml

This file was deleted.

54 changes: 0 additions & 54 deletions docker/docker-bake-amd64.hcl

This file was deleted.

54 changes: 0 additions & 54 deletions docker/docker-bake-arm64.hcl

This file was deleted.

32 changes: 20 additions & 12 deletions docker/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ variable "VERSION" {

# ----------------------------------------------------------------------------------------------------------------------

function "buildtag" {
params = [image_name, prefix, suffix]
result = [ "${DOCKER_REGISTRY}/${DOCKER_ORG}/${image_name}:${check_prefix(prefix)}${VERSION}${check_suffix(suffix)}", "${image_name}:build" ]
}

function "tag" {
params = [image_name, prefix, suffix]
result = [ "${DOCKER_REGISTRY}/${DOCKER_ORG}/${image_name}:${check_prefix(prefix)}${VERSION}${check_suffix(suffix)}" ]
result = [ "${gen_image_name(image_name)}:${check_prefix(prefix)}${VERSION}${check_suffix(suffix)}" ]
}

function "check_prefix" {
Expand All @@ -30,25 +25,38 @@ function "check_suffix" {
result = notequal("",tag) ? "-${tag}": ""
}

# ----------------------------------------------------------------------------------------------------------------------
function "gen_image_name" {
params = [image_name]
result = "${DOCKER_REGISTRY}/${DOCKER_ORG}/${image_name}"
}

# ----------------------------------------------------------------------------------------------------------------------
group "prod" {
targets = ["askem-julia"]
}

group "default" {
targets = []
targets = ["askem-julia-base"]
}

# ----------------------------------------------------------------------------------------------------------------------
# Used by the metafile GH action
# DO NOT ADD ANYTHING HERE THIS WILL BE POPULATED DYNAMICALLY
# MAKE SURE THIS IS INHERITED NEAR THE END SO THAT IT DOES NOT GET OVERRIDEN
target "docker-metadata-action" {}

target "_platforms" {
platforms = ["linux/amd64", "linux/arm64"]
}

target "askem-julia-base" {
context = "."
dockerfile = "docker/Dockerfile"
tags = tag("askem-julia", "", "")
}

# NOTE: This is the target that CI will trigger and the metadata action will override image names
target "askem-julia" {
inherits = ["_platforms"]
context = "."
tags = tag("askem-julia", "", "")
dockerfile = "docker/Dockerfile"
inherits = ["askem-julia-base", "docker-metadata-action", "_platforms"]
}