generated from 2i2c-org/hub-user-image-template
-
Notifications
You must be signed in to change notification settings - Fork 2
113 lines (97 loc) · 4.54 KB
/
build-images.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# If changing this name, you MUST also update the trigger in comment-built-images-to-pr.yaml
# https://github.com/2i2c-org/community-showcase/blob/HEAD/.github/workflows/comment-built-images-to-pr.yaml#L1
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/**"
# 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
# push them to container registry. We also upload an artifact containing the
# built image name to be used in another workflow for better discoverability.
build-and-push:
runs-on: ubuntu-latest
needs: [generate-build-matrix]
strategy:
matrix:
jobs: ${{ fromJson(needs.generate-build-matrix.outputs.images-to-build) }}
steps:
# 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: Checkout repo
uses: actions/checkout@v4
- name: Build and conditionally push the image to quay.io
id: r2d-build
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: false
# 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 }}"
# Lets us monitor disks getting full as images get bigger over time
- name: Show how much disk space is left
run: df -h
# Write the image name and tag to a file
- name: Write the image name and tag to a file
run: |
echo "${{ steps.r2d-build.outputs.IMAGE_SHA_NAME }}" > image-name.txt
# Upload file containing image name and tag as an artifact
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3
with:
name: "${{ matrix.jobs.image-name }}-image-name"
path: image-name.txt