Skip to content
45 changes: 26 additions & 19 deletions .github/workflows/build-multiarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
42 changes: 24 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -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
16 changes: 16 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ 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

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
14 changes: 4 additions & 10 deletions tests/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"

17 changes: 11 additions & 6 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -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