Skip to content

Commit

Permalink
github actions: docker images need to be stored and retrieved from ar…
Browse files Browse the repository at this point in the history
…tifacts, to pass to another job

this is really dumb, but okay

docker/build-push-action#225 (comment)
  • Loading branch information
naisanzaa committed Sep 19, 2021
1 parent 96ac228 commit 15445c0
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 28 deletions.
101 changes: 75 additions & 26 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:
# github.repository as <account>/<repo>
#IMAGE_NAME: ${{ github.repository }}
IMAGE_NAME: theshellland/automonisaur
DOCKER_IMAGE: automonisaur

PKG: automon
PYPI: automonisaur
Expand All @@ -27,16 +28,41 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: docker build . --tag ${{ env.IMAGE_NAME }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
tags: ${{ env.DOCKER_IMAGE }}
outputs: type=docker,dest=/tmp/${{ env.DOCKER_IMAGE }}.tar
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.DOCKER_IMAGE }}
path: /tmp/${{ env.DOCKER_IMAGE }}.tar


test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: docker build . --tag ${{ env.IMAGE_NAME }}
- run: docker run ${{ env.IMAGE_NAME }} test

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.DOCKER_IMAGE }}
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/${{ env.DOCKER_IMAGE }}.tar
- name: Run tests
run: docker run ${{ env.DOCKER_IMAGE }} test


publish-coverage:
Expand All @@ -45,37 +71,60 @@ jobs:
# upload coverage report
steps:
- uses: actions/checkout@v2
- run: docker build . --tag ${{ env.IMAGE_NAME }}

- name: Codecov
uses: codecov/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Download artifact
uses: actions/download-artifact@v2
with:
# User defined upload name. Visible in Codecov UI
name: # optional
# Repository upload token - get it from codecov.io. Required only for private repositories
token: # optional
# Path to coverage file to upload
file: # optional
# Comma-separated list of files to upload
files: # optional
# Directory to search for coverage reports.
directory: # optional
# Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)
flags: # optional
# Write upload file to path before uploading
path_to_write_report: # optional
# Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)
env_vars: # optional
# Specify whether or not CI build should fail if Codecov runs into an error during upload
fail_ci_if_error: # optional
name: ${{ env.DOCKER_IMAGE }}
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/${{ env.DOCKER_IMAGE }}.tar
# - name: Codecov
# uses: codecov/[email protected]
# with:
# # User defined upload name. Visible in Codecov UI
# name: # optional
# # Repository upload token - get it from codecov.io. Required only for private repositories
# token: # optional
# # Path to coverage file to upload
# file: # optional
# # Comma-separated list of files to upload
# files: # optional
# # Directory to search for coverage reports.
# directory: # optional
# # Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)
# flags: # optional
# # Write upload file to path before uploading
# path_to_write_report: # optional
# # Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)
# env_vars: # optional
# # Specify whether or not CI build should fail if Codecov runs into an error during upload
# fail_ci_if_error: # optional


publish-pypi:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: docker run ${{ env.IMAGE_NAME }} upload

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.DOCKER_IMAGE }}
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/${{ env.DOCKER_IMAGE }}.tar
- name: Upload to pypi
run: docker run ${{ env.DOCKER_IMAGE }} upload


publish-docker:
Expand Down Expand Up @@ -104,7 +153,7 @@ jobs:
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ env.REGISTRY }}/${{ env.DOCKER_IMAGE }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
Expand Down
2 changes: 1 addition & 1 deletion entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# entrypoint

cd $(dirname $0) && set -e
cd $(dirname $0) && set -ex

if [ "$1" == "test" ]; then
exec /bin/bash unittests.sh "$2"
Expand Down
2 changes: 1 addition & 1 deletion unittests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

cd $(dirname $0) && set -ex
cd $(dirname $0) && set -e

# TODO: set pre-commit hook

Expand Down

0 comments on commit 15445c0

Please sign in to comment.