From 4778c5f5e85f1054d81dd19572c52806efe3e1ce Mon Sep 17 00:00:00 2001 From: Redblueflame Date: Sun, 28 Mar 2021 23:01:19 +0200 Subject: [PATCH] Github container repository support (#183) * Add GHCR support * Add layer caching --- .github/workflows/docker-compile-master.yml | 34 ---------- .github/workflows/docker-compile-tag.yml | 36 ----------- .github/workflows/docker-compile.yml | 72 ++++++++++++++++----- 3 files changed, 57 insertions(+), 85 deletions(-) delete mode 100644 .github/workflows/docker-compile-master.yml delete mode 100644 .github/workflows/docker-compile-tag.yml diff --git a/.github/workflows/docker-compile-master.yml b/.github/workflows/docker-compile-master.yml deleted file mode 100644 index 8484917eb..000000000 --- a/.github/workflows/docker-compile-master.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Docker image build - -on: - push: - branches: - - master -env: - CARGO_TERM_COLOR: always - SQLX_OFFLINE: true -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up 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-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: Build and push Docker images - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: modrinth/labrinth - tag_with_ref: false - tags: master - tag_with_sha: true \ No newline at end of file diff --git a/.github/workflows/docker-compile-tag.yml b/.github/workflows/docker-compile-tag.yml deleted file mode 100644 index 1a32e1142..000000000 --- a/.github/workflows/docker-compile-tag.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Docker image build - -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 -env: - CARGO_TERM_COLOR: always - SQLX_OFFLINE: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up 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-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: Build and push Docker images - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: modrinth/labrinth - tag_with_ref: true - tags: latest - tag_with_sha: true \ No newline at end of file diff --git a/.github/workflows/docker-compile.yml b/.github/workflows/docker-compile.yml index d4e05cf40..7598ff589 100644 --- a/.github/workflows/docker-compile.yml +++ b/.github/workflows/docker-compile.yml @@ -1,31 +1,73 @@ -name: Docker image build +name: docker-build on: + push: + branches: + - '**' + tags: + - 'v*' pull_request: -env: - CARGO_TERM_COLOR: always - SQLX_OFFLINE: true + jobs: - build: + docker: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Docker Buildx + - + name: Checkout + uses: actions/checkout@v2 + - + name: Docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: | + ghcr.io/modrinth/labrinth + docker.io/modrinth/labrinth + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Cache Docker layers + - + name: Cache Docker layers uses: actions/cache@v2 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx- - - name: Build Docker images - uses: docker/build-push-action@v1 + - + name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 with: - push: false + registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - registry: docker.pkg.github.com - repository: modrinth/labrinth/labrinth - tag_with_ref: true - tag_with_sha: true \ No newline at end of file + - + name: Login to DockerHub + uses: docker/login-action@v1 + if: github.event_name != 'pull_request' + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + - + # 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