Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Update Publish Action to Push to GCP Artifact Registry #533

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
23 changes: 14 additions & 9 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ on:
jobs:
Build-and-push:
runs-on: ubuntu-latest

env:
ECR_REPOSITORY: ${{ secrets.AWS_REPO_NAME }}
PUBLIC_ECR_URL: ${{ secrets.AWS_REPO_URL }}
Expand All @@ -46,7 +46,7 @@ jobs:

steps:
- name: Git checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

# Build docker image
- name: Build Docker image
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Tag and push the image to Docker Hub
if: github.event.inputs.dockerHub == 'true'
id: dockerhub-push-image
Expand All @@ -113,32 +113,37 @@ jobs:
- id: auth
name: Authenticate to Google Cloud
if: github.event.inputs.gcp == 'true'
uses: 'google-github-actions/auth@v0'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'

# Set up Cloud SDK
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
uses: google-github-actions/setup-gcloud@v2
if: github.event.inputs.gcp == 'true'
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}

- name: Docker Auth
if: github.event.inputs.gcp == 'true'
run: |-
gcloud auth configure-docker us-docker.pkg.dev --quiet

# Push image to Google Container Registry
- name: Tag and push image to GCP container registry
if: github.event.inputs.gcp == 'true'
run: |
gcloud auth configure-docker -q

# Setting image tag to image tag input
docker tag $IMAGE_NAME gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:$IMAGE_TAG
docker tag $IMAGE_NAME us-docker.pkg.dev/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER/$IMAGE_NAME:$IMAGE_TAG
# Setting image to with github branch name
docker tag $IMAGE_NAME gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:branch-${GITHUB_REF##*/}
docker tag $IMAGE_NAME us-docker.pkg.dev/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER/$IMAGE_NAME:branch-${GITHUB_REF##*/}
# Setting image to with github sha
docker tag $IMAGE_NAME gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:sha-${GITHUB_SHA}
docker tag $IMAGE_NAME us-docker.pkg.dev/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER/$IMAGE_NAME:sha-${GITHUB_SHA}

echo "Pushing image to GCP container registry..."
docker push gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER --all-tags
docker push us-docker.pkg.dev/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER/$IMAGE_NAME --all-tags

echo "Pushing image to GCP container registry with following tags:"
echo "::set-output name=image::gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:$IMAGE_TAG"
Expand Down
Loading