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

Publish action update #478

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ on:
description: Docker container registry
default: true

image-tag:
type: string
description: Image tag
default: latest

container-registry-folder:
type: choice
description: Container registry folder
options:
- velo-external-db
- velo-manged-external-db
- velo-external-db-test
- velo-manged-external-db-test

jobs:
Build-and-push:
runs-on: ubuntu-latest
Expand All @@ -29,8 +43,8 @@ jobs:
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
CONTAINER_REGISTRY_FOLDER: ${{ secrets.GCP_CONTAINER_REGISTRY_FOLDER }}
IMAGE_TAG: latest
IMAGE_TAG: ${{ github.event.inputs.image-tag }}
CONTAINER_REGISTRY_FOLDER: ${{ github.event.inputs.container-registry-folder }}

steps:
- name: Git checkout
Expand All @@ -56,10 +70,20 @@ jobs:
if: github.event.inputs.aws == 'true'
id: aws-push-image
run: |
docker tag $IMAGE_NAME:$IMAGE_TAG $PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG
# Setting image tag to image tag input
docker tag $IMAGE_NAME $PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG
# Setting image to with github branch name
docker tag $IMAGE_NAME $PUBLIC_ECR_URL/$IMAGE_NAME:branch-${GITHUB_REF##*/}
# Setting image to with github sha
docker tag $IMAGE_NAME $PUBLIC_ECR_URL/$IMAGE_NAME:sha-${GITHUB_SHA}

echo "Pushing image to ECR..."
docker push $PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG
docker push $PUBLIC_ECR_URL/$IMAGE_NAME --all-tags

echo "Pushing image to ECR with following tags:"
echo "::set-output name=image::$PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG"
echo "::set-output name=image::$PUBLIC_ECR_URL/$IMAGE_NAME:branch-${GITHUB_REF##*/}"
echo "::set-output name=image::$PUBLIC_ECR_URL/$IMAGE_NAME:sha-${GITHUB_SHA}"

- name: Login to Docker Hub
if: github.event.inputs.dockerHub == 'true'
Expand All @@ -72,10 +96,20 @@ jobs:
if: github.event.inputs.dockerHub == 'true'
id: dockerhub-push-image
run: |
# Setting image tag to image tag input
docker tag $IMAGE_NAME $DOCKERHUB_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG
# Setting image to with github branch name
docker tag $IMAGE_NAME $DOCKERHUB_REPOSITORY/$IMAGE_NAME:branch-${GITHUB_REF##*/}
# Setting image to with github sha
docker tag $IMAGE_NAME $DOCKERHUB_REPOSITORY/$IMAGE_NAME:sha-${GITHUB_SHA}

echo "Pushing image to Docker Hub..."
docker push $DOCKERHUB_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG
docker push $DOCKERHUB_REPOSITORY/$IMAGE_NAME --all-tags

echo "Pushing image to Docker Hub with following tags:"
echo "::set-output name=image::$DOCKERHUB_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG"
echo "::set-output name=image::$DOCKERHUB_REPOSITORY/$IMAGE_NAME:branch-${GITHUB_REF##*/}"
echo "::set-output name=image::$DOCKERHUB_REPOSITORY/$IMAGE_NAME:sha-${GITHUB_SHA}"

# Authenticate to Google Cloud
- id: auth
Expand All @@ -97,5 +131,18 @@ jobs:
if: github.event.inputs.gcp == 'true'
run: |
gcloud auth configure-docker -q
docker tag $IMAGE_NAME:$IMAGE_TAG gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER
docker push gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:$IMAGE_TAG

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

echo "Pushing image to GCP container registry..."
docker push gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER --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"
echo "::set-output name=image::gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:branch-${GITHUB_REF##*/}"
echo "::set-output name=image::gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:sha-${GITHUB_SHA}"
Loading