build: Switched to GHA cache (#1153)

This commit is contained in:
Geoff Bourne 2021-12-04 18:42:03 -06:00 committed by GitHub
parent 6c636c3d9c
commit c4dd0d2bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 95 additions and 53 deletions

View File

@ -20,8 +20,11 @@ on:
- "docs/**"
- "examples/**"
env:
IMAGE_TO_TEST: itzg/minecraft-server:test-${{ github.repository_owner }}-${{ github.run_id }}
jobs:
docker-buildx:
build:
if: github.repository == 'itzg/docker-minecraft-server'
runs-on: ubuntu-20.04
steps:
@ -43,14 +46,6 @@ jobs:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2.1.7
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up QEMU
uses: docker/setup-qemu-action@v1.2.0
@ -60,6 +55,26 @@ jobs:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build for test
uses: docker/build-push-action@v2.7.0
if: github.ref_name == 'master'
with:
context: .
platforms: linux/amd64
tags: ${{ env.IMAGE_TO_TEST }}
# ensure latest base image is used
pull: true
load: true
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run tests
# It is assumed that image variants are merged from master and tested there
if: github.ref_name == 'master'
run: |
tests/test.sh
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2.7.0
@ -70,17 +85,9 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
# ensure latest base image is used
pull: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
cache-from: type=gha
cache-to: type=gha,mode=max
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

View File

@ -15,6 +15,9 @@ on:
- "[0-9]+.[0-9]+.[0-9]+-openj9-nightly"
- "[0-9]+.[0-9]+.[0-9]+-adopt11"
env:
IMAGE_TO_TEST: itzg/minecraft-server:test-${{ github.repository_owner }}-${{ github.run_id }}
jobs:
test:
runs-on: ubuntu-20.04
@ -54,20 +57,31 @@ jobs:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2.1.7
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build for test
uses: docker/build-push-action@v2.7.0
if: github.ref_name == 'master'
with:
context: .
platforms: linux/amd64
tags: ${{ env.IMAGE_TO_TEST }}
# ensure latest base image is used
pull: true
load: true
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run tests
if: github.ref_name == 'master'
run: |
tests/test.sh
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2.7.0
@ -80,8 +94,8 @@ jobs:
push: true
# tags determined by prep step
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
cache-from: type=gha
cache-to: type=gha,mode=max
labels: |
org.opencontainers.image.documentation=https://github.com/itzg/docker-minecraft-server
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
@ -90,11 +104,3 @@ jobs:
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

View File

@ -4,6 +4,9 @@ on:
pull_request:
branches: [ master ]
env:
IMAGE_TO_TEST: itzg/minecraft-server:test-${{ github.repository_owner }}-${{ github.run_id }}
jobs:
test:
runs-on: ubuntu-latest
@ -11,6 +14,19 @@ jobs:
steps:
- uses: actions/checkout@v2.4.0
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build
uses: docker/build-push-action@v2.7.0
with:
context: .
platforms: linux/amd64
tags: ${{ env.IMAGE_TO_TEST }}
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run tests
run: |
tests/test.sh

View File

@ -1,20 +1,14 @@
version: "3.8"
services:
sut:
monitor:
depends_on:
- mc
image: itzg/mc-monitor:0.6.0
command: status --host mc --retry-interval 1s --retry-limit 120
image: itzg/mc-monitor:${MC_MONITOR_VERSION:-0.10.4}
command: --debug status --host mc --retry-interval 1s --retry-limit 240
mc:
restart: "no"
build:
context: ..
args:
TARGETOS: linux
TARGETARCH: amd64
cache_from:
- itzg/minecraft-server:latest
image: ${IMAGE_TO_TEST:-itzg/minecraft-server}
environment:
EULA: "TRUE"

14
tests/docker-compose.yml Normal file
View File

@ -0,0 +1,14 @@
version: "3.8"
services:
monitor:
depends_on:
- mc
image: itzg/mc-monitor:${MC_MONITOR_VERSION:-0.10.4}
command: status --host mc --retry-interval 1s --timeout 1s --retry-limit 240
mc:
restart: "no"
image: ${IMAGE_TO_TEST:-itzg/minecraft-server}
environment:
EULA: "TRUE"

View File

@ -1,17 +1,22 @@
#!/bin/bash
cd $(dirname $0)
cd "$(dirname "$0")" || exit 1
failed=false
args="-f docker-compose.test.yml"
docker-compose $args run sut || failed=true
down() {
docker-compose down -v
}
docker-compose run monitor || failed=true
echo "
Result: failed=$failed"
$failed && docker-compose $args logs mc
docker-compose $args down -v
if $failed; then
docker-compose logs mc
down
exit 1
else
down
fi