Skip to content

Commit 4d4841f

Browse files
Merge pull request #543 from jiridanek/jd_try_dep_inside_nodes
RHOAIENG-7525: Build opendatahub-io/notebooks in GitHub Action with caching
2 parents ed22ccd + 5c4029b commit 4d4841f

10 files changed

+825
-1
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# inspired by
2+
# https://github.com/thesuperzapper/kubeflow/blob/master/.github/workflows/example_notebook_servers_publish_TEMPLATE.yaml
3+
---
4+
name: Build & Publish Notebook Servers (TEMPLATE)
5+
"on":
6+
workflow_call:
7+
inputs:
8+
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
9+
# https://docs.github.com/en/actions/learn-github-actions/contexts
10+
target:
11+
required: true
12+
description: "make target to build"
13+
type: string
14+
github:
15+
required: true
16+
description: "top workflow's `github`"
17+
type: string
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
env:
23+
# GitHub image registry used for storing $(CONTAINER_ENGINE)'s cache
24+
CACHE: "ghcr.io/${{ github.repository }}/workbench-images/build-cache"
25+
26+
steps:
27+
28+
- uses: actions/checkout@v4
29+
30+
- name: Login to GitHub Container Registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
# https://github.com/containers/buildah/issues/2521#issuecomment-884779112
38+
- name: Workaround https://github.com/containers/podman/issues/22152#issuecomment-2027705598
39+
run: sudo apt-get -qq remove podman crun
40+
41+
- uses: actions/cache@v4
42+
id: cached-linuxbrew
43+
with:
44+
path: /home/linuxbrew/.linuxbrew
45+
key: linuxbrew
46+
47+
- name: Install podman
48+
if: steps.cached-linuxbrew.outputs.cache-hit != 'true'
49+
run: |
50+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
51+
/home/linuxbrew/.linuxbrew/bin/brew install podman
52+
53+
- name: Add linuxbrew to PATH
54+
run: echo "/home/linuxbrew/.linuxbrew/bin/" >> $GITHUB_PATH
55+
56+
- name: Configure Podman
57+
run: |
58+
mkdir -p $HOME/.config/containers/
59+
cp ci/cached-builds/containers.conf $HOME/.config/containers/containers.conf
60+
cp ci/cached-builds/storage.conf $HOME/.config/containers/storage.conf
61+
# should at least reset storage when touching storage.conf
62+
sudo mkdir -p /mnt/containers/
63+
sudo chown -R $USER:$USER /mnt/containers
64+
podman system reset --force
65+
# podman bug? need to create this _after_ doing the reset
66+
mkdir -p /mnt/containers/tmp
67+
68+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
69+
- name: "push: make ${{ inputs.target }}"
70+
run: "make ${{ inputs.target }}"
71+
if: "${{ fromJson(inputs.github).event_name == 'push' }}"
72+
env:
73+
IMAGE_TAG: "${{ github.ref_name }}_${{ github.sha }}"
74+
IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images"
75+
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"
76+
77+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
78+
- name: "pull_request: make ${{ inputs.target }}"
79+
run: |
80+
# start a black hole container registry as make target always does a push
81+
mkdir -p $HOME/.config/containers/registries.conf.d/
82+
cp ci/cached-builds/insecure_localhost_registry.conf $HOME/.config/containers/registries.conf.d/insecure_localhost_registry.conf
83+
go run ci/cached-builds/dev_null_container_registry.go &
84+
# build and push the image
85+
make ${{ inputs.target }}
86+
if: "${{ fromJson(inputs.github).event_name == 'pull_request' }}"
87+
env:
88+
IMAGE_TAG: "${{ github.sha }}"
89+
IMAGE_REGISTRY: "localhost:5000/workbench-images"
90+
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }}"
91+
92+
- run: df -h
93+
if: "${{ !cancelled() }}"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
"name": "Build Notebooks"
3+
"permissions":
4+
"packages": "read"
5+
"on":
6+
"pull_request":
7+
8+
jobs:
9+
gen:
10+
name: Generate job matrix
11+
runs-on: ubuntu-latest
12+
outputs:
13+
matrix: ${{ steps.gen.outputs.matrix }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- run: python3 ci/cached-builds/gen_gha_matrix_jobs.py
17+
id: gen
18+
19+
# base images
20+
build:
21+
needs: ["gen"]
22+
strategy:
23+
fail-fast: false
24+
matrix: "${{ fromJson(needs.gen.outputs.matrix) }}"
25+
uses: ./.github/workflows/build-notebooks-TEMPLATE.yaml
26+
with:
27+
target: "${{ matrix.target }}"
28+
github: "${{ toJSON(github) }}"
29+
secrets: inherit

0 commit comments

Comments
 (0)