From d9d5b442354e8dea173072ddc2fa6b8621c8a44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marques?= Date: Thu, 3 Dec 2020 15:10:27 +0000 Subject: [PATCH] Build image before testing and push at the end Builds the image (in single arch) before testing Loads the image into local docker (See https://github.com/docker/build-push-action#export-image-to-docker) Rebuilds and pushes the final image in multi-arch at the end. --- .github/workflows/test.yaml | 42 ++++++++++++++++++++++++------------- tests/conftest.py | 4 +++- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 616c22f..0ff646e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,11 +24,27 @@ env: PYTHONIOENCODING: "UTF-8" jobs: - test: + build-test-push: runs-on: ubuntu-latest + env: + DOCKER_REPO: tecnativa/docker-socket-proxy steps: - # Shared steps - - uses: actions/checkout@v1 + # Prepare Docker environment and build + - uses: actions/checkout@v2 + - uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build image(s) + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + # HACK: Build single platform image for testing. See https://github.com/docker/buildx/issues/59 + load: true + push: false + tags: | + ${{ env.DOCKER_REPO }}:local + # Set up and run tests - name: Install python uses: actions/setup-python@v1 with: @@ -51,30 +67,28 @@ jobs: - run: poetry install # Run tests - run: poetry run pytest - build-push: - runs-on: ubuntu-latest - needs: test - env: - DOCKER_REPO: tecnativa/docker-socket-proxy - steps: - # Prepare - - uses: actions/checkout@v2 - - uses: docker/setup-qemu-action@v1 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 # Build and push - name: Login to DockerHub + if: + github.repository == 'Tecnativa/docker-socket-proxy' && github.ref == + 'refs/heads/master' uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_LOGIN }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GitHub Container Registry + if: + github.repository == 'Tecnativa/docker-socket-proxy' && github.ref == + 'refs/heads/master' uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ secrets.BOT_LOGIN }} password: ${{ secrets.BOT_TOKEN }} - name: Build and push + if: + github.repository == 'Tecnativa/docker-socket-proxy' && github.ref == + 'refs/heads/master' uses: docker/build-push-action@v2 with: context: . diff --git a/tests/conftest.py b/tests/conftest.py index 69a779b..7069363 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import json +import os from contextlib import contextmanager from logging import info from pathlib import Path @@ -7,7 +8,8 @@ import pytest from plumbum import local from plumbum.cmd import docker -IMAGE_NAME = "docker-socket-proxy:local" +DOCKER_REPO = os.environ.get("DOCKER_REPO", "docker-socket-proxy") +IMAGE_NAME = f"{DOCKER_REPO}:local" @pytest.fixture(autouse=True, scope="session")