Skip to content

switch from full image caching to GHA layer caching #6

switch from full image caching to GHA layer caching

switch from full image caching to GHA layer caching #6

Workflow file for this run

name: Build

Check failure on line 1 in .github/workflows/internal-build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/internal-build.yml

Invalid workflow file

(Line: 56, Col: 20): Job 'complete' depends on unknown job 'load'.
# This workflow builds multiple quickstart images as defined in the images json
# passed to the workflow across the architectures defined in the archs input.
#
# See the images.json file in the repo for how to define the JSON for a set of
# images.
#
# This workflow is intended to be called by workflows inside this repo.
#
# The build process first builds the dependencies (xdr, core, rpc, horizon,
# friendbot, lab). When doing so the dependencies needed as specified by the
# images json are deduplicated so that any software shared by the images is
# only built once. Dependencies are cached and so only rebuilt when needed.
# Dependencies are defined by a tag or branch, but when building those git refs
# are resolved to a sha to ensure stability of the sha throughout the full
# build process. For all dependencies and the final image, amd64 and arm64
# variants may be built.
on:
workflow_call:
inputs:
repo:
description: "Quickstart repo where quickstart is hosted"
type: "string"
required: true
sha:
description: "Quickstart sha to build should match workflow"
type: "string"
required: true
images:
description: "A custom image.json (a single image from the same format as images.json), if not provided the full images.json is run"
type: "string"
required: true
archs:
description: 'Architectures to build for as an array (e.g. ["amd64", "arm64"])'
type: "string"
required: true
cache_id:
description: "A value insert into cache keys to namespace cache usage, or invalidate it by incrementing"
type: "string"
default: 15
cache_prefix:
description: "A prefix added to all cache keys generated by this workflow"
type: "string"
default: "quickstart-"
env:
artifact_retention_days_for_image: 7
jobs:
complete:
if: always()
name: complete
needs: [setup, load, build]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1
setup:
name: 1 setup
runs-on: ubuntu-latest
outputs:
images: ${{ steps.images.outputs.images }}
deps: ${{ steps.deps.outputs.deps }}
additional-tests: ${{ steps.tests.outputs.additional-tests }}
steps:
- uses: actions/checkout@v2
with:
repository: ${{ inputs.repo }}
ref: ${{ inputs.sha }}
- name: Images with Extras
id: images
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
images: ${{ inputs.images }}
run: |
images="$(<<< $images ./.scripts/images-with-extras)"
<<< $images jq
echo "images=$images" >> $GITHUB_OUTPUT
echo "images=$images" >> $GITHUB_ENV
- name: Deps
id: deps
run: |
deps="$(<<< $images ./.scripts/images-deps)"
<<< $deps jq
echo "deps=$deps" >> $GITHUB_OUTPUT
build:
needs: [setup]
if: always() && !failure() && !cancelled()
strategy:
matrix:
image: ${{ fromJSON(needs.setup.outputs.images) }}
arch: ${{ fromJSON(inputs.archs) }}
fail-fast: false
name: 5 build (quickstart, ${{ matrix.image.tag }}, ${{ matrix.arch }})
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
env:
image_json: ${{ toJSON(matrix.image) }}
steps:
- uses: actions/checkout@v3
with:
repository: ${{ inputs.repo }}
ref: ${{ inputs.sha }}
- name: Collect Dep IDs
id: ids
run:
echo "$(<<< $image_json jq -r '.deps[] | "\(.name)=\(.id)"')" | tee -a $GITHUB_OUTPUT
- name: Write Image Config
run: |
echo "$image_json" > .image.json
- name: Pull Base Image
run: docker pull --platform linux/${{ matrix.arch }} ubuntu:22.04
- name: Build Args for Deps
id: dep_args
run: |
args="$(<<< $image_json jq -c -r '[ .deps[] | [
"--build-arg \(.name | ascii_upcase)_REPO=\(.repo)",
"--build-arg \(.name | ascii_upcase)_REF=\(.sha)",
"--build-arg \(.name | ascii_upcase)_OPTIONS='"'"'\(.options)'"'"'"
] ] | flatten | join(" ")')"
echo "args=${args}" | tee -a $GITHUB_OUTPUT
- name: Build Image
run: >
docker build
--platform linux/${{ matrix.arch }}
--cache-from=type=gha --cache-to=type=gha,mode=max,compression=zstd
-f Dockerfile
-t quickstart:${{ matrix.image.tag }}-${{ matrix.arch }}
--label org.opencontainers.image.revision="${{ inputs.sha }}"
--build-arg REVISION="${{ inputs.sha }}"
${{ steps.dep_args.outputs.args }}
.
- name: Save Quickstart Image
run: docker save quickstart -o /tmp/image
- name: Upload Quickstart Image to Artifacts
uses: actions/upload-artifact@v4
with:
name: image-quickstart-${{ matrix.image.tag }}-${{ matrix.arch }}.tar
path: /tmp/image
retention-days: ${{ env.artifact_retention_days_for_image }}