Skip to content

Publish to GCR

Publish to GCR #6

Workflow file for this run

name: CD
on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
branches:
- 'main'
workflow_dispatch:
env:
GH_REGISTRY: ghcr.io
GCP_REGISTRY: us-east1-docker.pkg.dev
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-publish-image:
name: "publish docker images"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Google Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.GCP_REGISTRY }}
username: _json_key_base64
password: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.GH_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- 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: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ env.GH_REGISTRY }}/${{ env.IMAGE_NAME }}
${{ env.GCP_REGISTRY }}/encorecloud-shared/starter/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.title=Placeholder Service
org.opencontainers.image.vendor=Encoretivity AB
[email protected]
org.opencontainers.image.description=This image is initially deployed into newly provisioned infrastructure as a placeholder servier which can respond to healthz requests while we build the encore service
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=ref,event=pr
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache