Build and push to dockerhub with a generated name, then prepare draft release on GitHub. #41
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 to dockerhub with a generated name, then prepare draft release on GitHub. | |
on: | |
workflow_dispatch: | |
jobs: | |
coolname: | |
runs-on: ubuntu-latest | |
timeout-minutes: 2 | |
outputs: | |
name: ${{ steps.generator.outputs.name }} | |
steps: | |
- name: Generate name | |
uses: thclark/coolname-generator-action@main | |
id: generator | |
with: | |
separator: "-" | |
length: "2" | |
style: "lowerCase" | |
docker: | |
needs: coolname | |
strategy: | |
matrix: | |
python: ["3.10", "3.11", "3.12"] | |
gdal: ["2.4.1"] | |
mode: ["slim", "dev"] | |
runs-on: ubuntu-latest | |
timeout-minutes: 300 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Generate name | |
uses: thclark/coolname-generator-action@main | |
id: generator | |
with: | |
separator: "-" | |
length: "2" | |
style: "lowerCase" | |
- name: Set mode-specific variables | |
id: vars | |
run: | | |
if (test ${{ matrix.mode }} = slim) then | |
echo "base_image=python:${{ matrix.python }}-slim-bookworm" >> $GITHUB_OUTPUT | |
echo "install_dev_tools=false" >> $GITHUB_OUTPUT | |
elif (test ${{ matrix.mode }} = dev) then | |
echo "base_image=mcr.microsoft.com/vscode/devcontainers/python:1-${{ matrix.python }}-bookworm" >> $GITHUB_OUTPUT | |
echo "install_dev_tools=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/[email protected] | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
build-args: | | |
GDAL_VERSION=${{ matrix.gdal }} | |
BASE_IMAGE=${{ steps.vars.outputs.base_image }} | |
INSTALL_DEV_TOOLS=${{ steps.vars.outputs.install_dev_tools }} | |
push: true | |
tags: windpioneers/gdal-python:${{ needs.coolname.outputs.name }}-gdal-${{ matrix.gdal }}-python-${{ matrix.python }}-${{ matrix.mode }} | |
# - name: Duplicate image from DockerHub to GCR | |
# TODO as we've used buildx we can copy the image to gcr.io with the same hash. See: | |
# - https://ianwhitestone.work/docker-builds-gcr-github-actions/ | |
# - https://github.com/docker/build-push-action/blob/master/docs/advanced/copy-between-registries.md | |
- name: Image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
release: | |
needs: [coolname, docker] | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- name: test generator output | |
run: echo "${{ needs.docker.outputs.name }}" | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, no need to create your own. | |
with: | |
tag_name: ${{ needs.coolname.outputs.name }} | |
release_name: ${{ needs.coolname.outputs.name }} | |
draft: true |