Docker Build Matrices #364
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
name: Docker Build Matrices | |
# This job generates build matrices using base images built two hours earlier | |
on: | |
schedule: | |
- cron: 0 3 * * * | |
# On pull request we test updates to images | |
pull_request: [] | |
# On push to main we build and deploy images | |
push: | |
branches: | |
- main | |
jobs: | |
generate: | |
name: Test Changed Docker Builds | |
runs-on: ubuntu-latest | |
outputs: | |
dockerbuild_matrix: ${{ steps.dockerbuild.outputs.dockerbuild_matrix }} | |
empty_matrix: ${{ steps.dockerbuild.outputs.dockerbuild_matrix_empty }} | |
steps: | |
# START PULL REQUEST / PUSH checkout and file derivation ======================= | |
- uses: actions/checkout@v3 | |
if: github.event_name != 'schedule' | |
with: | |
fetch-depth: 0 | |
- name: Get changed files | |
id: changed-files | |
if: github.event_name != 'schedule' | |
uses: tj-actions/changed-files@aa52cfcd81f1a00a6bf1241a8cad6adec4d80638 # v33 | |
with: | |
separator: " " | |
- name: Convert changed Dockerfile to uptodate | |
if: github.event_name != 'schedule' | |
id: parsed_files | |
env: | |
changed_files: ${{ steps.changed-files.outputs.all_changed_files }} | |
run: /bin/bash .github/scripts/prepare_paths.sh | |
- name: Generate Build Matrix | |
if: github.event_name != 'schedule' | |
uses: vsoch/uptodate@main | |
id: dockerbuild_pr | |
with: | |
root: ${{ steps.parsed_files.outputs.parsed_files }} | |
parser: dockerbuild | |
flags: "--registry ghcr.io/llnl --all" | |
# END PULL REQUEST / PUSH checkout and file derivation ======================= | |
# START SCHEDULED checkout and file derivation ======================= | |
- uses: actions/checkout@v3 | |
if: github.event_name == 'schedule' | |
with: | |
fetch-depth: 0 | |
- name: Generate Build Matrix | |
uses: vsoch/uptodate@main | |
if: github.event_name == 'schedule' | |
id: dockerbuild_scheduled | |
with: | |
root: . | |
parser: dockerbuild | |
flags: "--registry ghcr.io/llnl --all" | |
# END SCHEDULED checkout and file derivation | |
- name: View Build Matrix Result | |
id: dockerbuild | |
env: | |
result: ${{ steps.dockerbuild_pr.outputs.dockerbuild_matrix }} | |
result_scheduled: ${{ steps.dockerbuild_scheduled.outputs.dockerbuild_matrix }} | |
run: /bin/bash .github/scripts/combine_results.sh | |
build: | |
needs: | |
- generate | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
result: ${{ fromJson(needs.generate.outputs.dockerbuild_matrix) }} | |
if: ${{ needs.generate.outputs.dockerbuild_matrix != '[]' }} | |
name: "Build ${{ matrix.result.container_name }}" | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: GHCR Login | |
if: (github.event_name != 'pull_request') | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.GHCR_USERNAME }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Make Space For Build | |
run: | | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /usr/local/lib/android | |
sudo rm -rf /opt/ghc | |
sudo rm -rf /opt/hostedtoolcache/CodeQL | |
sudo docker image prune --all --force | |
- name: Pull Docker Layers | |
env: | |
container: ${{ matrix.result.container_name }} | |
run: docker pull ${container} || exit 0 | |
- name: Update to relative path | |
id: relative_path | |
env: | |
filename: ${{ matrix.result.filename }} | |
run: /bin/bash .github/scripts/relative_path.sh | |
- name: Build ${{ matrix.result.container_name }} | |
id: builder | |
env: | |
container: ${{ matrix.result.container_name }} | |
prefix: ${{ matrix.result.command_prefix }} | |
filename: ${{ steps.relative_path.outputs.relative_path }} | |
run: | | |
/bin/bash .github/scripts/build_simple.sh || ( | |
res=$? | |
df -h # In case of out of space, hopefully show *where* | |
exit $res | |
) | |
- name: Deploy Container | |
if: (github.event_name != 'pull_request') | |
env: | |
container: ${{ matrix.result.container_name }} | |
run: docker push ${container} |