Build multi-arch image #28
Workflow file for this run
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 | |
on: | |
push: | |
pull_request: | |
jobs: | |
lint: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 2 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v4 | |
- uses: pre-commit/action@v3.0.0 | |
build: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 2 | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
cache: pip | |
cache-dependency-path: dev-requirements.txt | |
- name: Install | |
run: | | |
pip install -r dev-requirements.txt | |
# Make a wheel and install it to catch possible issues with releases | |
python -m build --wheel | |
pip install dist/*.whl | |
pip freeze | |
test: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Configure insecure Podman registry | |
run: | | |
REGISTRY_HOST=$(hostname -I | awk '{print $1}'):5000 | |
echo "REGISTRY_HOST=${REGISTRY_HOST}" >> $GITHUB_ENV | |
mkdir -p ~/.config/containers/ | |
cat <<EOF >> ~/.config/containers/registries.conf | |
[registries.insecure] | |
registries = [ | |
'localhost:5000', | |
'${REGISTRY_HOST}', | |
] | |
EOF | |
- name: Run registry for testing | |
run: | | |
./ci/run-local-registry.sh & | |
while ! curl -f http://localhost:5000; do | |
sleep 5 | |
done | |
- name: Podman info | |
run: podman info | |
- name: Build and test container | |
run: | | |
./ci/build-and-test.sh | |
# https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ | |
publish-pypi: | |
name: Pypi | |
needs: | |
# Only publish if other jobs passed | |
- lint | |
- build | |
- test | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v4 | |
- name: Install pypa/build | |
run: python -m pip install build | |
- name: Build a binary wheel and a source tarball | |
run: python -m build --sdist --wheel --outdir dist/ | |
- name: Publish to PyPI | |
if: startsWith(github.ref, 'refs/tags') | |
uses: pypa/gh-action-pypi-publish@v1.8.10 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
container: | |
name: Build container | |
needs: | |
# Only publish if other jobs passed | |
- lint | |
- build | |
- test | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 10 | |
permissions: | |
contents: read | |
packages: write | |
env: | |
DEFAULT_REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
services: | |
# So that we can test this in PRs/branches | |
local-registry: | |
image: registry:2 | |
ports: | |
- 5000:5000 | |
steps: | |
- name: Should we push this image to a public registry? | |
run: | | |
if [ "${{ startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main') }}" = "true" ]; then | |
REGISTRY=$DEFAULT_REGISTRY | |
else | |
REGISTRY=localhost:5000 | |
fi | |
echo "REGISTRY=$REGISTRY" >> $GITHUB_ENV | |
echo "Publishing to $REGISTRY" | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get short reference (e.g. branch or tag) | |
# If there are multiple / (e.g. refs/prs/123/merge) use the last component | |
run: | | |
echo "SHORT_REF=${GITHUB_REF##refs*/}" >> $GITHUB_ENV | |
- name: Set up QEMU to build multiple platforms | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx (for multi-arch builds) | |
uses: docker/setup-buildx-action@v3 | |
with: | |
# Allows pushing to registry on localhost:5000 | |
driver-opts: network=host | |
- name: Login to registry | |
if: env.REGISTRY != 'localhost:5000' | |
run: | | |
docker login -u "${{ github.actor }}" -p "${{ secrets.GITHUB_TOKEN }}" "${{ env.REGISTRY }}" | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.SHORT_REF }} |