Skip to content

Test Python 3.11 image 👀 #966

Test Python 3.11 image 👀

Test Python 3.11 image 👀 #966

Workflow file for this run

---
# Build and test all Docker images on every push and pull request.
#
# Builds the images with docker buildx bake and pushes them to a local Docker
# image registry, and runs the automated tests with pytest.
name: continuous-integration
on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 60
outputs:
build_vars: ${{ steps.build_vars.outputs.vars }}
targets: ${{ steps.bake_metadata.outputs.targets }}
images: ${{ steps.bake_metadata.outputs.images }}
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Read build variables
id: build_vars
run: |
vars=$(cat build.json | jq -c '[.variable | to_entries[] | {"key": .key, "value": .value.default}] | from_entries')
echo "vars=$vars" >> "${GITHUB_OUTPUT}"
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
bake-target: __template__-meta
images: |
name=ghcr.io/aiidalab/__template__
tags: |
type=edge
type=ref,event=pr
type=raw,value={{tag}},enable=${{ github.ref_type == 'tag' && ! startsWith(github.ref_name, 'v') }}
type=match,pattern=v(\d{4}\.\d{4}(-.+)?),group=1
type=sha
- name: Generate docker-bake meta file.
env:
BAKE_TEMPLATE_META: ${{ steps.meta.outputs.bake-file }}
run: |
cat ${BAKE_TEMPLATE_META} | jq -c \
| .github/workflows/merge-bake-template-target.sh \
| tee docker-bake-template-meta.json
- name: Build images with buildx bake
id: bake
uses: docker/[email protected]
with:
# Using provenance to disable default attestation so it will build only desired images:
# https://github.com/orgs/community/discussions/45969
provenance: false
files: |
docker-bake.hcl
build.json
docker-bake-template-meta.json
push: true
- name: Set output variables
id: bake_metadata
run: |
cat docker-bake-template-meta.json \
| jq -c '.target | [to_entries[] | {"key": (.key|split("-")[:-1] | join("-")), "value": [.value.tags[]][1]}] | from_entries' \
| tee bake-meta.json
targets=$(echo $(cat bake-meta.json | jq -c 'keys'))
echo "targets=$targets" >> "${GITHUB_OUTPUT}"
images=$(echo $(cat bake-meta.json | jq -c '. | [to_entries[] | {"key": (.key| split("-")| join("_") |ascii_upcase + "_IMAGE"), "value": .value}] | from_entries'))
echo "images=$images" >> "${GITHUB_OUTPUT}"
test:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python test environment
uses: mamba-org/provision-with-micromamba@v14
with:
cache-env: true
- name: Run tests
shell: bash -l {0} # required to activate the conda environment
env: ${{ fromJSON(needs.build.outputs.images) }}
run: |
pytest -v -m "not integration"
test-arm64:
needs: build
runs-on: buildjet-2vcpu-ubuntu-2204-arm
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python test environment
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: aiidalab-docker-stack
architecture: ARM64
miniconda-version: "latest"
environment-file: environment.yml
python-version: 3.9
auto-activate-base: true
- name: Run tests
shell: bash -l {0} # required to activate the conda environment
env: ${{ fromJSON(needs.build.outputs.images) }}
run: |
pytest -v -m "not integration"
integration-test:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python test environment
uses: mamba-org/provision-with-micromamba@v14
with:
cache-env: true
- name: Run integration tests
shell: bash -l {0} # required to activate the conda environment
env: ${{ fromJSON(needs.build.outputs.images) }}
run: pytest -v -m "integration"
integration-test-arm64:
needs: build
runs-on: buildjet-2vcpu-ubuntu-2204-arm
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python test environment
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: aiidalab-docker-stack
architecture: ARM64
miniconda-version: "latest"
environment-file: environment.yml
python-version: 3.9
auto-activate-base: true
- name: Run integration tests
shell: bash -l {0} # required to activate the conda environment
env: ${{ fromJSON(needs.build.outputs.images) }}
run: pytest -v -m "integration"
release:
if: >-
github.repository == 'aiidalab/aiidalab-docker-stack'
&& (github.ref_type == 'tag' || github.ref_name == 'main')
needs:
- build
- test
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
target: ${{ fromJSON(needs.build.outputs.targets) }}
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
env: ${{ fromJSON(needs.build.outputs.build_vars) }}
with:
images: docker.io/aiidalab/${{ matrix.target }}
tags: |
type=edge
type=raw,value={{tag}},enable=${{ github.ref_type == 'tag' && ! startsWith(github.ref_name, 'v') }}
type=raw,value=aiida-${{ env.AIIDA_VERSION }},enable=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}
type=raw,value=python-${{ env.PYTHON_VERSION }},enable=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}
type=raw,value=postgresql-${{ env.PGSQL_VERSION }},enable=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}
type=match,pattern=v(\d{4}\.\d{4}(-.+)?),group=1
- name: Determine src image tag
id: images
run: |
src=$(echo '${{ needs.build.outputs.images }}'| jq -cr '.[("${{ matrix.target }}"|ascii_upcase|sub("-"; "_"; "g")) + "_IMAGE"]')
echo "src=$src" >> "${GITHUB_OUTPUT}"
- name: Push image
uses: akhilerm/[email protected]
with:
src: ${{ steps.images.outputs.src }}
dst: ${{ steps.meta.outputs.tags }}
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: aiidalab/${{ matrix.target }}
short-description: ${{ github.event.repository.description }}
- uses: softprops/[email protected]
name: Create release
if: startsWith(github.ref, 'refs/tags/v')
with:
generate_release_notes: true