From c4dd0d2bae3fbc41de493cb6b2482c76821dddfa Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sat, 4 Dec 2021 18:42:03 -0600 Subject: [PATCH] build: Switched to GHA cache (#1153) --- .github/workflows/build-multiarch.yml | 45 ++++++++++++++++----------- .github/workflows/main.yml | 42 ++++++++++++++----------- .github/workflows/pr.yml | 16 ++++++++++ tests/docker-compose.test.yml | 14 +++------ tests/docker-compose.yml | 14 +++++++++ tests/test.sh | 17 ++++++---- 6 files changed, 95 insertions(+), 53 deletions(-) create mode 100644 tests/docker-compose.yml diff --git a/.github/workflows/build-multiarch.yml b/.github/workflows/build-multiarch.yml index 08c6072a..251e026d 100644 --- a/.github/workflows/build-multiarch.yml +++ b/.github/workflows/build-multiarch.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0f43c66d..14c1cafd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0bcd9c96..c619ca43 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 diff --git a/tests/docker-compose.test.yml b/tests/docker-compose.test.yml index bc6fc775..1638b74b 100644 --- a/tests/docker-compose.test.yml +++ b/tests/docker-compose.test.yml @@ -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" diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 00000000..63b75fc0 --- /dev/null +++ b/tests/docker-compose.yml @@ -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" + diff --git a/tests/test.sh b/tests/test.sh index 376aed99..9db35dec 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -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