|
| 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() }}" |
0 commit comments