diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3e17d475..a1565f04 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,6 +10,7 @@ on: - adopt13 - adopt14 - adopt15 + - test/* tags: - "[0-9]+.[0-9]+.[0-9]+" - "[0-9]+.[0-9]+.[0-9]+-openj9" @@ -21,7 +22,7 @@ on: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 @@ -32,20 +33,63 @@ jobs: build: needs: - test - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: Build and push Docker images - uses: docker/build-push-action@v1.1.0 + - name: Prepare + id: prep + run: | + DOCKER_IMAGE=itzg/minecraft-server + VERSION=edge + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + fi + if [[ $GITHUB_REF == refs/heads/* ]]; then + VERSION=${GITHUB_REF#refs/heads/} + if [[ $VERSION == master ]]; then + VERSION=latest + fi + fi + TAGS="${DOCKER_IMAGE}:${VERSION//\//-}" + echo ::set-output name=tags::${TAGS} + echo ::set-output name=cache_from::${TAGS} + echo ::set-output name=version::${VERSION//\//-} + echo ::set-output name=cache_version::${VERSION//\//-} + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ steps.prep.outputs.cache_version }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-${{ steps.prep.outputs.cache_version }}- + + - name: Login to DockerHub + uses: docker/login-action@v1 with: - repository: itzg/minecraft-server username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASSWORD }} - tag_with_ref: true - tag_with_sha: false - cache_froms: itzg/minecraft-server:latest - add_git_labels: true - labels: org.opencontainers.image.url=https://github.com/itzg/docker-minecraft-server,org.opencontainers.image.documentation=https://github.com/itzg/docker-minecraft-server + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile push: true + tags: ${{ steps.prep.outputs.tags }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + labels: | + org.opencontainers.image.documentation=https://github.com/itzg/docker-minecraft-server + org.opencontainers.image.version=${{ steps.prep.outputs.version }} + org.opencontainers.image.source=https://github.com/itzg/docker-minecraft-server + org.opencontainers.image.revision=${{ github.sha }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }}