Skip to content

build images for multiple python versions #5

build images for multiple python versions

build images for multiple python versions #5

Workflow file for this run

---
name: "Build Docker images"
on:
push:
branches: ['**']
release:
types: [released]
env:
IMAGE_NAME: "${{ secrets.DOCKER_ORG }}/nansat_base"
jobs:
build_standard_docker_image:
runs-on: 'ubuntu-20.04'
strategy:
matrix:
python_version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
steps:
- name: 'Checkout repository'
uses: actions/checkout@v2
- name: "Extract tag name"
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]];then
TAG="${GITHUB_REF#refs/tags/}-python${{ matrix.python_version }}"
else
TAG='tmp-python${{ matrix.python_version }}'
fi
echo "::set-output name=VERSION::${TAG}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-standard-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-standard-
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Build docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
build-args: 'PYTHON_VERSION=${{ matrix.python_version }}'
push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build_slim_docker_image:
runs-on: 'ubuntu-20.04'
strategy:
matrix:
python_version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
steps:
- name: 'Checkout repository'
uses: actions/checkout@v2
- name: "Extract tag name"
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]];then
TAG="${GITHUB_REF#refs/tags/}-python${{ matrix.python_version }}"
else
TAG='tmp-python${{ matrix.python_version }}'
fi
echo "::set-output name=VERSION::${TAG}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-slim-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-slim-
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Build docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile_slim
build-args: 'PYTHON_VERSION=${{ matrix.python_version }}'
push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: |
${{ env.IMAGE_NAME }}:latest-slim
${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}-slim
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
...