Skip to content

Commit

Permalink
ci: add docker build job
Browse files Browse the repository at this point in the history
  • Loading branch information
bchrobot committed Oct 19, 2021
1 parent 3e7e55d commit 531c403
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 531c403

Please sign in to comment.