diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 5b01d8994..eca2e0f9d 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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 @@ -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 @@ -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' @@ -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 @@ -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}"