Skip to content

Dockerize the test environment for better reproducibility #10

Dockerize the test environment for better reproducibility

Dockerize the test environment for better reproducibility #10

name: Build and Push Base Docker Image
on:
push:
branches: [main, master, develop]
paths:
- 'Dockerfile.base'
- '.github/workflows/build_base_image.yml'
pull_request:
branches: [main, master, develop]
paths:
- 'Dockerfile.base'
- '.github/workflows/build_base_image.yml'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-push-base:
runs-on: ubuntu-latest
strategy:
matrix:
pyver: ["3.10.13", "3.11.9", "3.12.4", "3.13.0"]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract repo name
id: repo
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- name: Extract short Python version
id: pyver_short
run: |
echo "PYVER_SHORT=$(echo ${{ matrix.pyver }} | cut -d'.' -f1,2)" >> $GITHUB_OUTPUT
- name: Build and push base image (on push)
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.base
push: true
build-args: |
PYTHON_VERSION=${{ matrix.pyver }}
tags: |
ghcr.io/${{ steps.repo.outputs.REPO }}-base:${{ steps.pyver_short.outputs.PYVER_SHORT }}-latest
- name: Build base image (on PR)
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.base
push: false
build-args: |
PYTHON_VERSION=${{ matrix.pyver }}
tags: |
ghcr.io/${{ steps.repo.outputs.REPO }}-base:${{ steps.pyver_short.outputs.PYVER_SHORT }}-pr-test