|
| 1 | +name: Docker image CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - Dockerfile |
| 9 | + - requirements.txt |
| 10 | + - Pipfile |
| 11 | + - Pipfile.lock |
| 12 | + - .github/workflows/docker-image.yml |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - Dockerfile |
| 16 | + - requirements.txt |
| 17 | + - Pipfile |
| 18 | + - Pipfile.lock |
| 19 | + - .github/workflows/docker-image.yml |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: docker-image-${{ github.ref }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +env: |
| 26 | + IMAGE_NAME: ghcr.io/${{ github.repository }} |
| 27 | + |
| 28 | +jobs: |
| 29 | + build-test-push: |
| 30 | + name: Build, test and publish docker image |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + packages: write |
| 35 | + steps: |
| 36 | + - name: Checkout repository |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Set up Docker Buildx |
| 40 | + uses: docker/setup-buildx-action@v3 |
| 41 | + |
| 42 | + - name: Build image for tests |
| 43 | + run: | |
| 44 | + docker buildx build \ |
| 45 | + --load \ |
| 46 | + --cache-from type=gha \ |
| 47 | + --cache-to type=gha,mode=max \ |
| 48 | + --tag local-ci-image:${{ github.sha }} \ |
| 49 | + . |
| 50 | +
|
| 51 | + - name: Run tests inside built image |
| 52 | + run: | |
| 53 | + docker run --rm \ |
| 54 | + -v "${{ github.workspace }}:/app" \ |
| 55 | + -w /app \ |
| 56 | + local-ci-image:${{ github.sha }} \ |
| 57 | + pytest src/test/test_api.py |
| 58 | +
|
| 59 | + - name: Log in to GitHub Container Registry |
| 60 | + if: github.event_name == 'push' |
| 61 | + uses: docker/login-action@v3 |
| 62 | + with: |
| 63 | + registry: ghcr.io |
| 64 | + username: ${{ github.actor }} |
| 65 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + |
| 67 | + - name: Extract image metadata |
| 68 | + if: github.event_name == 'push' |
| 69 | + id: meta |
| 70 | + uses: docker/metadata-action@v5 |
| 71 | + with: |
| 72 | + images: ${{ env.IMAGE_NAME }} |
| 73 | + tags: | |
| 74 | + type=raw,value=latest |
| 75 | + type=sha,prefix=sha- |
| 76 | + type=raw,value=run-${{ github.run_number }} |
| 77 | +
|
| 78 | + - name: Build and push image |
| 79 | + if: github.event_name == 'push' |
| 80 | + uses: docker/build-push-action@v6 |
| 81 | + with: |
| 82 | + context: . |
| 83 | + push: true |
| 84 | + tags: ${{ steps.meta.outputs.tags }} |
| 85 | + labels: ${{ steps.meta.outputs.labels }} |
| 86 | + cache-from: type=gha |
| 87 | + cache-to: type=gha,mode=max |
0 commit comments