Build and push container images #38
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2023 The Cross-Media Measurement Authors | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
name: Build and push container images | |
on: | |
workflow_dispatch: | |
workflow_call: | |
outputs: | |
image-tag: | |
description: "Tag of container images" | |
value: ${{ jobs.push-images.outputs.image-tag }} | |
jobs: | |
push-images: | |
runs-on: ubuntu-20.04 | |
outputs: | |
image-tag: ${{ steps.get-image-tag.outputs.image-tag }} | |
permissions: | |
id-token: write | |
env: | |
CONTAINER_REGISTRY: ghcr.io | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: ./.github/actions/free-disk-space | |
# Authenticate to Google Cloud for access to remote cache. | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: ${{ vars.BAZEL_BUILD_WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ vars.BAZEL_BUILD_SERVICE_ACCOUNT }} | |
- id: get-image-tag | |
name: Get image tag | |
run: | | |
declare image_tag | |
if [[ "$GITHUB_REF_TYPE" == 'tag' ]]; then | |
image_tag="${GITHUB_REF_NAME#v}" | |
else | |
image_tag="$GITHUB_SHA" | |
fi | |
echo "image-tag=${image_tag}" >> "$GITHUB_OUTPUT" | |
- name: Write ~/.bazelrc | |
env: | |
IMAGE_TAG: ${{ steps.get-image-tag.outputs.image-tag }} | |
run: | | |
cat << EOF > ~/.bazelrc | |
common --config=ci | |
common --config=remote-cache | |
build --define container_registry=$CONTAINER_REGISTRY | |
build --define image_repo_prefix=$GITHUB_REPOSITORY_OWNER | |
build --define image_tag=$IMAGE_TAG | |
EOF | |
- name: Get Bazel cache params | |
id: get-cache-params | |
run: | | |
repo_cache_path="$(bazelisk info repository_cache)" | |
echo "repo-cache-path=${repo_cache_path}" >> $GITHUB_OUTPUT | |
cache_path="$(bazelisk info output_base)" | |
echo "cache-path=${cache_path}" >> $GITHUB_OUTPUT | |
# Hack to work around disk space consumed by bazel-contrib/rules_oci#439. | |
# The alternative is to use a runner with more disk space. | |
- name: Mount scratch disk | |
uses: ./.github/actions/mount-scratch-disk | |
with: | |
mount-path: ${{ steps.get-cache-params.outputs.cache-path }} | |
- name: Restore repository cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: ${{ steps.get-cache-params.outputs.repo-cache-path }} | |
key: ${{ vars.BAZEL_REPO_CACHE_KEY }} | |
- name: Authenticate to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.CONTAINER_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Build images | |
run: > | |
bazelisk build | |
//src/main/docker:push_all_gke_images | |
//src/main/docker/panel_exchange_client:push_all_images | |
//src/main/docker:push_all_eks_images | |
- name: Push images | |
run: | | |
bazelisk run //src/main/docker:push_all_gke_images | |
bazelisk run //src/main/docker/panel_exchange_client:push_all_images | |
bazelisk run //src/main/docker:push_all_eks_images |