test matrix #43
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: Publish Release | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- v** | |
branches: | |
- henry/debug_docker_arm | |
env: | |
REGISTRY_IMAGE: daya0576/beaverhabits | |
jobs: | |
pre-deploy-test: | |
name: Unit tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry | |
poetry install --no-interaction --no-ansi | |
- name: Test with pytest | |
run: poetry run pytest tests | |
build: | |
needs: pre-deploy-test | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
platform: [linux/amd64, linux/arm64] | |
dockerfile: [Dockerfile] | |
# include: | |
# - platform: linux/arm/v7 | |
# dockerfile: Dockerfile.nobuildkit.arm32 | |
steps: | |
- name: Prepare | |
id: prep | |
run: | | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/v} | |
TAGS="${{ env.REGISTRY_IMAGE }}:${VERSION},${{ env.REGISTRY_IMAGE }}:latest" | |
else | |
VERSION=debug | |
TAGS="${{ env.REGISTRY_IMAGE }}:${VERSION}" | |
fi | |
echo $TAGS | |
echo ::set-output name=tags::${TAGS} | |
platform=${{ matrix.platform }} | |
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY_IMAGE }} | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
platforms: ${{ matrix.platform }} | |
labels: ${{ steps.meta.outputs.labels }} | |
file: ${{ matrix.dockerfile }} | |
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true | |
- name: Export digest | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.build.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload digest | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests-${{ env.PLATFORM_PAIR }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge: | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
steps: | |
- name: Download meta bake definition | |
uses: actions/download-artifact@v4 | |
with: | |
name: bake-meta | |
path: /tmp | |
- name: Download digests | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/digests | |
pattern: digests-* | |
merge-multiple: true | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create $(jq -cr '.target."docker-metadata-action".tags | map(select(startswith("${{ env.REGISTRY_IMAGE }}")) | "-t " + .) | join(" ")' /tmp/bake-meta.json) \ | |
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) | |
- name: Inspect image | |
run: | | |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:$(jq -r '.target."docker-metadata-action".args.DOCKER_META_VERSION' /tmp/bake-meta.json) | |
verify: | |
needs: merge | |
runs-on: ubuntu-latest | |
steps: | |
- name: Pull and Test Container | |
env: | |
VERSION: latest | |
run: | | |
docker pull ${{ env.REGISTRY_IMAGE }}:${VERSION} | |
docker run -d --name test_container ${{ env.REGISTRY_IMAGE }}:${VERSION} | |
sleep 3 | |
CONTAINER_OUTPUT=$(docker logs test_container) | |
# Check if the container is still running | |
CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' test_container) | |
if [ "${CONTAINER_STATUS}" != "true" ]; then | |
echo "The container is not running!" | |
exit 1 | |
fi | |
# Check if the "Error" string is present in the container output | |
if echo "${CONTAINER_OUTPUT}" | grep -i -q "Error"; then | |
echo "Error found in container output!" | |
echo "${CONTAINER_OUTPUT}" | |
exit 1 | |
fi | |
docker stop test_container | |
docker rm test_container |