From a06ef2ba1ad1e8f82bb507d98d6cdbea23152b9f Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Thu, 2 Jun 2022 11:14:35 +0100 Subject: [PATCH] chore: add docker workflow --- .github/workflows/docker.yaml | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .github/workflows/docker.yaml diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 00000000..bc9e8055 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,106 @@ +name: Docker Test & Publish + +on: + push: + branches: + - "master" + tags: + - "*" + paths-ignore: + - ".github/**" + - "!.github/workflows/docker.yml" + - ".vscode/**" + - ".gitignore" + - "LICENSE" + - "README" + pull_request: + branches: + - "master" + paths: + - "Dockerfile" + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + # Configure build environment + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Build all projects and cache + - name: Build Base Image + uses: docker/build-push-action@v3 + with: + context: . + push: false + tags: revolt.chat/base:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + publish_amd64: + needs: [test] + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + strategy: + matrix: + project: [delta, bonfire] + steps: + # Configure build environment + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Authenticate with Docker Hub and GHCR + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to Github Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Resolve the correct project + - uses: kanga333/variable-mapper@master + id: export + with: + key: "${{github.base_ref}}" + map: | + { + "delta": { + "path": "crates/delta", + "tag": "revoltchat/server" + }, + "bonfire": { + "path": "crates/bonfire", + "tag": "revoltchat/bonfire" + } + } + export_to: output + + # Configure metadata + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ steps.export.outputs.tag }}, ghcr.io/${{ steps.export.outputs.tag }} + + # Build crate image + - name: Publish + uses: docker/build-push-action@v3 + with: + context: . + push: true + platforms: linux/amd64 + file: {context}/${{ steps.export.outputs.path }}/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max