feat: leverage cache to prevent unnecessary pushing and building (#14)

* feat: leverage cache to prevent unnecessary pushing and building

* fix: combine test build and test suite to leverage cache

* fix: revert inadvertently changed parts

* fix: review-requested changes

* fix: update test tags to use static ci tag
This commit is contained in:
Nick Pappas 2021-01-17 10:41:47 -06:00 committed by GitHub
parent 061fe12aa7
commit 717aeffae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 55 deletions

View File

@ -5,23 +5,13 @@ on:
branches: [ "master", "stable" ] branches: [ "master", "stable" ]
jobs: jobs:
build: build-and-test-image:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
outputs:
imagetag: ${{ steps.prep.outputs.imagetag }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
submodules: recursive submodules: recursive
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=docker.io/mailserver/testing
TAGS="${DOCKER_IMAGE}:${GITHUB_SHA::8},${DOCKER_IMAGE}:latest"
echo ::set-output name=tags::${TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
id: buildx id: buildx
@ -32,11 +22,6 @@ jobs:
key: ${{ runner.os }}-buildx-${{ github.sha }} key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: | restore-keys: |
${{ runner.os }}-buildx- ${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build image locally - name: Build image locally
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
@ -46,35 +31,26 @@ jobs:
build-args: | build-args: |
VCS_REF=${{ github.sha }} VCS_REF=${{ github.sha }}
VCS_VER=${{ github.ref }} VCS_VER=${{ github.ref }}
platforms: linux/amd64,linux/arm/v7,linux/arm64 platforms: linux/amd64
pull: true load: true
push: true tags: mailserver-testing:ci
tags: ${{ steps.prep.outputs.tags }}
cache-to: type=local,dest=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache
- name: Run test suite
test: run: >
needs: build NAME=mailserver-testing:ci
runs-on: ubuntu-20.04 bash -c 'make generate-accounts tests'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: run test suite
run: |
NAME=docker.io/mailserver/testing:${GITHUB_SHA::8} bash -c 'make generate-accounts tests'
env: env:
CI: true CI: true
publish: build-multiarch-and-publish:
needs: test needs: build-and-test-image
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
submodules: recursive submodules: recursive
- name: Prepare - name: Prepare tags
id: prep id: prep
run: | run: |
DOCKER_IMAGE=docker.io/mailserver/docker-mailserver DOCKER_IMAGE=docker.io/mailserver/docker-mailserver
@ -111,7 +87,6 @@ jobs:
VCS_REF=${{ github.sha }} VCS_REF=${{ github.sha }}
VCS_VER=${{ github.ref }} VCS_VER=${{ github.ref }}
platforms: linux/amd64,linux/arm/v7,linux/arm64 platforms: linux/amd64,linux/arm/v7,linux/arm64
pull: true
push: true push: true
tags: ${{ steps.prep.outputs.tags }} tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache cache-from: type=local,src=/tmp/.buildx-cache

View File

@ -6,35 +6,24 @@ jobs:
build-and-test: build-and-test:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- - name: Checkout
name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
submodules: recursive submodules: recursive
- - name: Build image locally
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
id: buildx
-
name: Build image locally
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
builder: ${{ steps.buildx.outputs.name }} context: .
file: ./Dockerfile
build-args: | build-args: |
VCS_REF=${{ github.sha }} VCS_REF=${{ github.sha }}
VCS_VER=${{ github.ref }} VCS_VER=${{ github.ref }}
context: .
file: ./Dockerfile
load: true
platforms: linux/amd64 platforms: linux/amd64
tags: docker.io/mailserver/testing:ci load: true
- tags: mailserver-testing:ci
name: Run all tests - name: Run test suite
run: > run: >
NAME=docker.io/mailserver/testing:ci NAME=mailserver-testing:ci
bash -c 'make generate-accounts tests' bash -c 'make generate-accounts tests'
env: env:
CI: true CI: true