Simplify repo2docker workflow #9
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
name: Build and push container images | |
# Trigger this workflow on pushes to main branches under the images folder or | |
# in PRs to the main branch that change the image folder | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "images/**" | |
pull_request: | |
branches: | |
- main | |
paths: | |
- "images/**" | |
# When multiple PRs triggering this workflow are merged, queue them instead | |
# of running them in parallel in case of clashes when pushing | |
# https://github.blog/changelog/2021-04-19-github-actions-limit-workflow-run-or-job-concurrency/ | |
concurrency: image-build | |
jobs: | |
# This job establishes from filepaths changed which images will be built by the | |
# next job | |
generate-build-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
images-to-build: ${{ env.images-to-build }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Install Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install script requirements | |
run: python -m pip install -r scripts/requirements.txt | |
- name: Identify files that have been added or modified | |
# Action repo: https://github.com/dorny/paths-filter | |
# Fork of the repo above that we use: https://github.com/frouioui/paths-filter/tree/main | |
# In order to take advantage of https://github.com/dorny/paths-filter/pull/133 | |
uses: frouioui/paths-filter@main | |
id: changed-files | |
with: | |
token: "" | |
list-files: csv | |
filters: | | |
changed: | |
- added|modified: images/** | |
- name: Generate matrix jobs | |
run: | | |
python scripts/generate-image-build-matrix-jobs.py "${{ steps.changed-files.outputs.changed_files }}" | |
# This job will build the images identified by the previous job and optionally | |
# push them to container registry | |
build-and-push: | |
runs-on: ubuntu-latest | |
needs: [generate-build-matrix] | |
strategy: | |
matrix: | |
jobs: ${{ fromJson(needs.generate-build-matrix.outputs.images-to-build) }} | |
steps: | |
- run: echo "${{ github.event_name == 'pull_request' }}" | |
# For biggish images, github actions runs out of disk space. | |
# So we cleanup some unwanted things in the disk image, and reclaim that space for our docker use | |
# https://github.com/actions/virtual-environments/issues/2606#issuecomment-772683150 | |
# and https://github.com/easimon/maximize-build-space/blob/b4d02c14493a9653fe7af06cc89ca5298071c66e/action.yml#L104 | |
# This gives us a total of about 52G of free space, which should be enough for now | |
- name: cleanup disk space | |
run: | | |
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc | |
df -h | |
- name: Login to quay.io | |
uses: docker/[email protected] | |
with: | |
registry: quay.io | |
username: ${{ secrets.QUAY_USERNAME }} | |
password: ${{ secrets.QUAY_PASSWORD }} | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Build and conditionally push the image to quay.io | |
uses: jupyterhub/repo2docker-action@master | |
with: | |
# Make sure username & password/token pair matches your registry credentials | |
DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.QUAY_PASSWORD }} | |
DOCKER_REGISTRY: "quay.io" | |
# Disable pushing a 'latest' tag, as this often just causes confusion | |
LATEST_TAG_OFF: true | |
# NOTE: This line assumes that the subfolder that contains the image has | |
# the same name as the image when it is pushed to the registry. We | |
# can update the logic here later if needed. | |
IMAGE_NAME: "2i2c/${{ matrix.jobs.image-name }}" | |
# Tell repo2docker which subdirectory to examine | |
# ref: https://repo2docker.readthedocs.io/en/latest/usage.html#cmdoption-jupyter-repo2docker-subdir | |
REPO2DOCKER_EXTRA_ARGS: "--subdir images/${{ matrix.jobs.image-name }}" | |
# # If the event that triggered this workflow was a pull request, the image | |
# # will be built but not pushed to the registry | |
# NO_PUSH: ${{ github.event_name == 'pull_request' }} | |
# Lets us monitor disks getting full as images get bigger over time | |
- name: Show how much disk space is left | |
run: df -h |