Update Dockerfile #3
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: CI | |
on: | |
push: | |
paths: | |
- .github/workflows/ci.yml | |
- cmd/** | |
- internal/** | |
- pkg/** | |
- .dockerignore | |
- .golangci.yml | |
- Dockerfile | |
- go.mod | |
- go.sum | |
- integration_test.sh | |
pull_request: | |
paths: | |
- .github/workflows/ci.yml | |
- cmd/** | |
- internal/** | |
- pkg/** | |
- .dockerignore | |
- .golangci.yml | |
- Dockerfile | |
- go.mod | |
- go.sum | |
- integration_test.sh | |
jobs: | |
verify: | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_BUILDKIT: "1" | |
steps: | |
- uses: actions/[email protected] | |
- name: Linting | |
run: docker build --target lint . | |
- name: Build test image | |
run: docker build --target test -t test-container . | |
- name: Run tests in test container | |
run: | | |
touch coverage.txt | |
docker run --rm \ | |
-v "$(pwd)/coverage.txt:/tmp/gobuild/coverage.txt" \ | |
test-container | |
# We run this here to use the caching of the previous steps | |
- name: Build final image | |
run: docker build -t qmcgaw/deunhealth . | |
- name: Integration test | |
run: | | |
chmod +x integration_test.sh | |
./integration_test.sh | |
publish: | |
needs: [verify] | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/[email protected] | |
- uses: docker/setup-qemu-action@v1 | |
- uses: docker/setup-buildx-action@v1 | |
- uses: docker/[email protected] | |
with: | |
username: qmcgaw | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Set variables | |
id: vars | |
run: | | |
BRANCH=${GITHUB_REF#refs/heads/} | |
TAG=${GITHUB_REF#refs/tags/} | |
echo ::set-output name=commit::$(git rev-parse --short HEAD) | |
echo ::set-output name=created::$(date -u +%Y-%m-%dT%H:%M:%SZ) | |
if [ "$TAG" != "$GITHUB_REF" ]; then | |
echo ::set-output name=version::$TAG | |
echo ::set-output name=platforms::linux/amd64,linux/386,linux/arm64,linux/arm/v6,linux/arm/v7,linux/s390x,linux/ppc64le,linux/riscv64 | |
elif [ "$BRANCH" = "main" ]; then | |
echo ::set-output name=version::latest | |
echo ::set-output name=platforms::linux/amd64,linux/386,linux/arm64,linux/arm/v6,linux/arm/v7,linux/s390x,linux/ppc64le,linux/riscv64 | |
else | |
echo ::set-output name=version::$BRANCH | |
echo ::set-output name=platforms::linux/amd64 | |
fi | |
- name: Build and push final image | |
uses: docker/[email protected] | |
with: | |
platforms: ${{ steps.vars.outputs.platforms }} | |
build-args: | | |
CREATED=${{ steps.vars.outputs.created }} | |
COMMIT=${{ steps.vars.outputs.commit }} | |
VERSION=${{ steps.vars.outputs.version }} | |
tags: qmcgaw/deunhealth:${{ steps.vars.outputs.version }} | |
push: true |