.github/workflows/build-images.yml #394
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
on: | |
push: | |
branches: | |
- master | |
schedule: | |
- cron: '0 4 * * 0' | |
jobs: | |
build-image: | |
strategy: | |
fail-fast: false | |
matrix: | |
pyver: ["3.9","3.10", "3.12"] | |
include: | |
- pyver: "3.11" | |
main: true | |
runs-on: ubuntu-latest | |
name: Build Python ${{ matrix.pyver }} Image | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Set Names | |
id: names | |
run: | | |
MR="ghcr.io/oggm" | |
DI="$(date +%Y%m%d)" | |
PV="${{ matrix.pyver }}" | |
[[ "$PV" == py* ]] || PV="py$PV" | |
echo "vertag=$PV" >> $GITHUB_OUTPUT | |
echo "dev=$MR/dev_base" >> $GITHUB_OUTPUT | |
echo "empty=$MR/empty_base" >> $GITHUB_OUTPUT | |
echo "untested=$MR/untested_base" >> $GITHUB_OUTPUT | |
echo "base=$MR/base" >> $GITHUB_OUTPUT | |
if [[ "${{ matrix.main }}" == "true" ]]; then | |
echo "dev_latest=$MR/dev_base:latest" >> $GITHUB_OUTPUT | |
echo "dev_date=$MR/dev_base:$DI" >> $GITHUB_OUTPUT | |
echo "empty_latest=$MR/empty_base:latest" >> $GITHUB_OUTPUT | |
echo "empty_date=$MR/empty_base:$DI" >> $GITHUB_OUTPUT | |
echo "untested_latest=$MR/untested_base:latest" >> $GITHUB_OUTPUT | |
echo "untested_date=$MR/untested_base:$DI" >> $GITHUB_OUTPUT | |
echo "base_latest=$MR/base:latest" >> $GITHUB_OUTPUT | |
echo "base_date=$MR/base:$DI" >> $GITHUB_OUTPUT | |
fi | |
- name: Stop Commands | |
run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}" | |
- name: Generate Dockerfile | |
run: make -C untested_base PYTHON_VERSION="${{ matrix.pyver }}" Dockerfile_dev Dockerfile_empty | |
- name: Build dev_base | |
id: dev_base | |
uses: docker/build-push-action@v5 | |
with: | |
context: untested_base | |
file: untested_base/Dockerfile_dev | |
pull: true | |
push: true | |
provenance: false | |
tags: | | |
${{ steps.names.outputs.dev }}:${{ steps.names.outputs.vertag }} | |
${{ steps.names.outputs.dev_latest }} | |
${{ steps.names.outputs.dev_date }} | |
cache-to: type=registry,mode=max,ref=${{ steps.names.outputs.dev }}:cache_${{ steps.names.outputs.vertag }} | |
cache-from: type=registry,ref=${{ steps.names.outputs.dev }}:cache_${{ steps.names.outputs.vertag }} | |
- name: Build empty_base | |
id: empty_base | |
uses: docker/build-push-action@v5 | |
with: | |
context: untested_base | |
file: untested_base/Dockerfile_empty | |
pull: true | |
push: true | |
provenance: false | |
tags: | | |
${{ steps.names.outputs.empty }}:${{ steps.names.outputs.vertag }} | |
${{ steps.names.outputs.empty_latest }} | |
${{ steps.names.outputs.empty_date }} | |
cache-to: type=registry,mode=max,ref=${{ steps.names.outputs.empty }}:cache_${{ steps.names.outputs.vertag }} | |
cache-from: type=registry,ref=${{ steps.names.outputs.empty }}:cache_${{ steps.names.outputs.vertag }} | |
- name: Generate Final Dockerfile | |
run: make -C untested_base PYTHON_VERSION="${{ matrix.pyver }}" DEV_TAG="${{ steps.names.outputs.dev }}@${{ steps.dev_base.outputs.digest }}" EMPTY_TAG="${{ steps.names.outputs.empty }}@${{ steps.empty_base.outputs.digest }}" Dockerfile_final | |
- name: Build untested_base | |
uses: docker/build-push-action@v5 | |
with: | |
context: untested_base | |
file: untested_base/Dockerfile_final | |
pull: true | |
push: true | |
provenance: false | |
tags: | | |
${{ steps.names.outputs.untested }}:${{ steps.names.outputs.vertag }} | |
${{ steps.names.outputs.untested_latest }} | |
${{ steps.names.outputs.untested_date }} | |
cache-to: type=registry,mode=max,ref=${{ steps.names.outputs.untested }}:cache_${{ steps.names.outputs.vertag }} | |
cache-from: type=registry,ref=${{ steps.names.outputs.untested }}:cache_${{ steps.names.outputs.vertag }} | |
- name: Test image | |
run: docker run --rm "${{ steps.names.outputs.untested }}:${{ steps.names.outputs.vertag }}" /root/test.sh | |
- name: Build base | |
uses: docker/build-push-action@v5 | |
if: ${{ matrix.main }} | |
with: | |
context: base | |
push: true | |
provenance: false | |
tags: | | |
${{ steps.names.outputs.base_latest }} | |
${{ steps.names.outputs.base_date }} | |
- name: Trigger OGGM | |
if: ${{ matrix.main }} | |
uses: OGGM/repo-dispatch-action@v1 | |
with: | |
repo: OGGM/oggm | |
auth_user: ${{ secrets.DispatchUser }} | |
auth_secret: ${{ secrets.DispatchSecret }} | |
action: build-docker-image |