Skip to content

Push base image to GHCR and GCP #68

Push base image to GHCR and GCP

Push base image to GHCR and GCP #68

Workflow file for this run

name: Create and publish the Ruby base image
on: push
permissions:
contents: read
packages: write
id-token: write
env:
IMAGE_NAME: baseimage-ruby
GCP_REGISTRY: europe-west1-docker.pkg.dev/hunter-io/hunter
GHCR_REGISTRY: ghcr.io/hunter-io
jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Configure Docker to use Google Artifact Registry
run: gcloud auth configure-docker europe-west1-docker.pkg.dev
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract branch name
id: extract_branch_name
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
- if: github.ref != 'refs/heads/main'
name: Build and push tagged version
uses: docker/build-push-action@v5
with:
push: true
tags: |
${{ env.GCP_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.extract_branch_name.outputs.branch }}
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.extract_branch_name.outputs.branch }}
- if: github.ref == 'refs/heads/main'
name: Build and push latest
uses: docker/build-push-action@v5
with:
push: true
tags: |
${{ env.GCP_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:latest