Skip to content

Commit

Permalink
Modify build workflow (DataBiosphere/azul#5905)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsotirho-ucsc committed Apr 15, 2024
1 parent 6140721 commit 614b255
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 19 deletions.
105 changes: 87 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
name: build and push image

on:
pull_request:
push:
branches:
- azul

env:
REGISTRY: ghcr.io
# The fully qualified image name of the image to build. The first component is
# the host name of the registry that primarily hosts the image.
#
azul_docker_bigquery_emulator_image: docker.io/ucscgi/azul-bigquery-emulator

# An optional prefix for the image name if the image is to be pushed to an
# alternate registry instead of the one noted in the image name above.
#
azul_docker_registry: ""

# The tag of the image that's used as the base for this image. Because this
# value isn't reflected in the tag for this image, you also need to bump the
# internal version below when changing this variable.
#
azul_docker_bigquery_emulator_base_image_tag: bullseye-20240311

# The version where this repo diverges from the upstream repo.
#
azul_docker_bigquery_emulator_upstream_version: 0.4.4

# The version of this image. The image will be tagged with the version of the
# upstream image followed by the value of this variable. Increment this value
# to update the OS packages installed in the image.
# Both this value (internal_version) and the combined value (upstream_version
# + internal_version) will be passed as arguments to the Dockerfile.
#
azul_docker_bigquery_emulator_internal_version: 1

jobs:
build-image:
Expand All @@ -14,13 +42,26 @@ jobs:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/metadata-action@v3
id: meta
# By setting an env variable using the shell, we can use the value of
# existing env variables in the new variable's value.
- run: >
echo azul_docker_bigquery_emulator_version=${{ format(
'{0}-{1}',
env.azul_docker_bigquery_emulator_upstream_version,
env.azul_docker_bigquery_emulator_internal_version
) }} >> "$GITHUB_ENV"
- name: Checkout repository
uses: actions/checkout@v4
with:
images: ${{ env.REGISTRY }}/hannes-ucsc/bigquery-emulator
- name: setup docker buildx
uses: docker/setup-buildx-action@v2
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# To facilitate local builds using the Makefile
driver-opts: ${{ startsWith(env.azul_docker_registry, 'localhost:') && 'network=host' || '' }}

- name: cache for linux
uses: actions/cache@v3
if: runner.os == 'Linux'
Expand All @@ -31,17 +72,45 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: docker/login-action@v2
- name: Log into registry
if: >
github.event_name != 'pull_request'
&& vars.AZUL_DOCKER_REGISTRY_USER
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v3
username: ${{ vars.AZUL_DOCKER_REGISTRY_USER }}
password: ${{ secrets.AZUL_DOCKER_REGISTRY_PASSWORD }}

- name: Build and conditionally push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=~/.cache/go-build
build-args: |
VERSION=v${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
azul_docker_bigquery_emulator_base_image_tag=${{ env.azul_docker_bigquery_emulator_base_image_tag }}
azul_docker_bigquery_emulator_internal_version=${{ env.azul_docker_bigquery_emulator_internal_version }}
VERSION=${{ env.azul_docker_bigquery_emulator_version }}
context: .
# We disable provenance for a single platform (non-multiarch) build
# https://github.com/docker/build-push-action/issues/755
provenance: false
push: ${{ github.event_name != 'pull_request' }}
tags: "${{ format(
'{0}{1}:{2}',
env.azul_docker_registry,
env.azul_docker_bigquery_emulator_image,
env.azul_docker_bigquery_emulator_version
) }}"
cache-from: |
type=local,src=~/.cache/go-build
${{ format(
'type=registry,ref={0}{1}_buildcache',
env.azul_docker_registry,
env.azul_docker_bigquery_emulator_image
) }}
# The value after '&&' in a ternary operator must be truthy, and since
# an empty string is falsy, we use ' ' instead.
cache-to: "${{ github.event_name == 'pull_request' && ' ' || format(
'type=registry,ref={0}{1}_buildcache,mode=max',
env.azul_docker_registry,
env.azul_docker_bigquery_emulator_image
) }}"
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ARG azul_docker_bigquery_emulator_base_image_tag

FROM ghcr.io/goccy/go-zetasql:latest

ARG VERSION
Expand All @@ -11,7 +13,11 @@ RUN go mod download

RUN make emulator/build

FROM debian:bullseye AS emulator
FROM debian:${azul_docker_bigquery_emulator_base_image_tag} AS emulator

ARG azul_docker_bigquery_emulator_internal_version

RUN apt-get update && apt-get upgrade -y

COPY --from=0 /work/bigquery-emulator /bin/bigquery-emulator

Expand Down

0 comments on commit 614b255

Please sign in to comment.