diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 3a18b9f..16e6ee9 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -13,3 +13,64 @@ jobs: with: error_level: 0 dockerfile: 'Dockerfile' + + publish-docker-image: + if: startsWith( github.ref, 'refs/tags/v') + # needs: test + name: Publish Docker image + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + + # Caching strategy from: https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache + - name: Cache Docker layers for ${{ matrix.service }} + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-pg-amqp-bridge-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-pg-amqp-bridge- + + - name: Get image tags + id: image-tags + run: | + export GIT_SHA="${{ github.sha }}" + export GIT_SHA_SHORT=${GIT_SHA:0:7} + echo "::set-output name=sha::$GIT_SHA_SHORT" + export GIT_REF=${GITHUB_REF#refs/*/} + echo "$GIT_REF" + export APP_VERSION=${GIT_REF#"v"} + echo "::set-output name=version::$APP_VERSION" + + - name: Login to GAR + uses: docker/login-action@v1 + with: + registry: us-east4-docker.pkg.dev + username: _json_key + password: ${{ secrets.GCR_JSON_KEY }} + + - name: Build and push ${{ matrix.service }} + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: | + us-east4-docker.pkg.dev/assemble-services/apps/pg-amqp-bridge:latest + us-east4-docker.pkg.dev/assemble-services/apps/pg-amqp-bridge:${{ steps.image-tags.outputs.version }} + us-east4-docker.pkg.dev/assemble-services/apps/pg-amqp-bridge:${{ steps.image-tags.outputs.sha }} + 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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9e743b9..5549f00 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ jobs: cut-gh-release: runs-on: ubuntu-latest env: - DOCKER_IMAGE: gcr.io/assemble-services/pg-amqp-bridge-node + DOCKER_IMAGE: us-east4-docker.pkg.dev/assemble-services/apps/pg-amqp-bridge BODY_PATH: release-body.txt steps: - name: Checkout