Skip to content

Commit

Permalink
feat: PLT-583 Add GAR push to all workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktslau committed Dec 11, 2023
1 parent e8ceb71 commit 2b641c2
Show file tree
Hide file tree
Showing 11 changed files with 531 additions and 209 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/cron_deploy-from-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,20 @@ jobs:
GCR_IMAGE_NAME=$GCR_IMAGE_REPO"/"${{ github.event.repository.name }}
GAR_IMAGE_NAME=$GAR_IMAGE_REPO"/"${{ github.event.repository.name }}
if [ "$GAR_ENABLED" == "true" ]
then
IMAGE_NAME=$GAR_IMAGE_NAME
else
IMAGE_NAME=$GCR_IMAGE_NAME
fi
echo "gcr_domain=$GCR_DOMAIN" >> $GITHUB_OUTPUT
echo "gar_domain=$GAR_DOMAIN" >> $GITHUB_OUTPUT
echo "gcr_image_repo=$GCR_IMAGE_REPO" >> $GITHUB_OUTPUT
echo "gar_image_repo=$GAR_IMAGE_REPO" >> $GITHUB_OUTPUT
echo "gcr_image_name=$GCR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "gar_image_name=$GAR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Get .env file and scheduler
run: |-
Expand Down Expand Up @@ -226,20 +234,13 @@ jobs:

##Deploy to dev
- name: "Checkout k8s manifests"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ env.K8S_MANIFESTS_REPO }}
token: ${{ secrets.ULTIMATE_GITHUB_PAT }}

- name: Update the Image tags for Dev Environment
run: |-
if [ "$GAR_ENABLED" == "true" ]
then
IMAGE_NAME=$GAR_IMAGE_NAME
else
IMAGE_NAME=$GCR_IMAGE_NAME
fi
cd $APP_SQUAD/${{ github.event.repository.name }}/overlay/${K8S_ENV_NAME}
cat $HOME/dev-copy.env > dev.env
scheduler=$(cat $HOME/dev-scheduler-copy)
Expand All @@ -254,5 +255,4 @@ jobs:
TAG: ${{ steps.get_image_tag.outputs.image_tag }}
REMOTE_REPO: https://${{ secrets.ULTIMATE_GITHUB_PAT }}@github.com/${{ env.K8S_MANIFESTS_REPO }}.git
K8S_ENV_NAME: development
GCR_IMAGE_NAME: ${{ steps.image_name.outputs.gcr_image_name }}
GAR_IMAGE_NAME: ${{ steps.image_name.outputs.gar_image_name }}
IMAGE_NAME: ${{ steps.image_name.outputs.image_name }}
72 changes: 50 additions & 22 deletions .github/workflows/cron_manual-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
image_repo:
required: true
type: string
description: "Your container registry repository - like eu.gcr.io/ultimateai-169214"
default: europe-docker.pkg.dev/common-main-cfc4/eu.gcr.io
description: "Your container registry repository - like europe-docker.pkg.dev/common-main-cfc4/eu.gcr.io"
app_squad:
required: true
type: string
Expand All @@ -33,9 +34,6 @@ on:
default: "#plt-239"
description: "Slack channel ID where you want your notifications"





env:
IMAGE_REPO: ${{ inputs.image_repo }}
Expand All @@ -45,7 +43,8 @@ env:
GITHUB_USER: ${{ inputs.github_user }}
K8S_MANIFESTS_REPO: ${{ inputs.k8s_manifests_repo }}
SLACK_CHANNEL_ID: ${{ inputs.slack_channel_id }}

GCR_ENABLED: ${{ vars.GCR_ENABLED || 'true' }}
GAR_ENABLED: ${{ vars.GAR_ENABLED || 'true' }}

jobs:
deploy:
Expand All @@ -55,16 +54,45 @@ jobs:
contents: "read"
id-token: "write"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- id: "image_name"
name: "Get repo name and update IMAGE_NAME"
run: |-
IMAGE_NAME=$IMAGE_REPO"/"${{ github.event.repository.name }}
name: "Extract repo name and update IMAGE_NAME"
run: |-
REPO_DOMAIN=$(echo $IMAGE_REPO | cut -d '/' -f 1)
case $REPO_DOMAIN in
*gcr.io)
GCR_DOMAIN=$REPO_DOMAIN
GAR_DOMAIN=europe-docker.pkg.dev
GCR_IMAGE_REPO=$IMAGE_REPO
GAR_IMAGE_REPO=europe-docker.pkg.dev/common-main-cfc4/eu.gcr.io ;;
*pkg.dev)
GCR_DOMAIN=eu.gcr.io
GAR_DOMAIN=$REPO_DOMAIN
GCR_IMAGE_REPO=eu.gcr.io/ultimateai-169214
GAR_IMAGE_REPO=$IMAGE_REPO ;;
esac
GCR_IMAGE_NAME=$GCR_IMAGE_REPO"/"${{ github.event.repository.name }}
GAR_IMAGE_NAME=$GAR_IMAGE_REPO"/"${{ github.event.repository.name }}
if [ "$GAR_ENABLED" == "true" ]
then
IMAGE_NAME=$GAR_IMAGE_NAME
else
IMAGE_NAME=$GCR_IMAGE_NAME
fi
echo "gcr_domain=$GCR_DOMAIN" >> $GITHUB_OUTPUT
echo "gar_domain=$GAR_DOMAIN" >> $GITHUB_OUTPUT
echo "gcr_image_repo=$GCR_IMAGE_REPO" >> $GITHUB_OUTPUT
echo "gar_image_repo=$GAR_IMAGE_REPO" >> $GITHUB_OUTPUT
echo "gcr_image_name=$GCR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "gar_image_name=$GAR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Get env file and scheduler for updating k8s-manifest repo
run: |-
if [[ "${ENVIRONMENT}" = "production" ]]; then
Expand All @@ -91,7 +119,7 @@ jobs:
run: |-
TAG=${{ steps.fetch_latest_release.outputs.tag_name }}
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Changelog content
id: full_changelog_content
run: |
Expand All @@ -100,11 +128,11 @@ jobs:
echo "FEND" >> $GITHUB_ENV
- name: "Checkout k8s manifests"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ env.K8S_MANIFESTS_REPO }}
token: ${{ secrets.ULTIMATE_GITHUB_PAT }}

- name: Check if version is already deployed in stage, if trying to deploy in prod
if: ${{ (env.ENVIRONMENT == 'production') }}
run: |-
Expand All @@ -121,7 +149,7 @@ jobs:
id: get_old_version
run: |-
OLD_VERSION=$(cat $APP_SQUAD/${{ github.event.repository.name }}/overlay/$ENVIRONMENT/kustomization.yaml | yq .images.0.newTag)
echo "old_version=$OLD_VERSION" >> $GITHUB_OUTPUT
echo "old_version=$OLD_VERSION" >> $GITHUB_OUTPUT
env:
TAGS: ${{ steps.tag_to_deploy.outputs.tag }}

Expand All @@ -139,7 +167,7 @@ jobs:
run: |
JSON_CONTENT=$(echo "${{ env.FILTERED_CHANGELOG_CONTENT }}" | sed 's/$/\\n/' | tr -d '\n')
echo "changelog_json=$JSON_CONTENT" >> $GITHUB_OUTPUT
- name: Update the Image tags and env files for Selected Environment
run: |-
cd $APP_SQUAD/${{ github.event.repository.name }}/overlay/$ENVIRONMENT
Expand All @@ -151,16 +179,16 @@ jobs:
git config --local user.email $GITHUB_EMAIL
git config --local user.name $GITHUB_USER
git commit -m "update image to ${IMAGE_NAME}:${TAGS}" -a || echo "Nothing to commit, version ${TAGS} is already deployed to $ENVIRONMENT" >> $GITHUB_STEP_SUMMARY
git push ${REMOTE_REPO} HEAD:main --force
git push ${REMOTE_REPO} HEAD:main --force
env:
TAGS: ${{ steps.tag_to_deploy.outputs.tag }}
REMOTE_REPO: https://${{ secrets.ULTIMATE_GITHUB_PAT }}@github.com/${{ env.K8S_MANIFESTS_REPO }}.git
IMAGE_NAME: ${{ steps.image_name.outputs.image_name }}

- uses: slackapi/slack-github-action@v1.23.0
- uses: slackapi/slack-github-action@v1.24.0
name: Slack notification
id: slack_notif
if: ${{ env.ENVIRONMENT == 'production' }}
if: ${{ env.ENVIRONMENT == 'production' }}
with:
channel-id: ${{ env.SLACK_CHANNEL_ID }}
payload: |-
Expand All @@ -183,9 +211,9 @@ jobs:
IMAGE_NAME: ${{ steps.image_name.outputs.image_name }}
OLD_VERSION: ${{ steps.get_old_version.outputs.old_version }}

- uses: slackapi/slack-github-action@v1.23.0
- uses: slackapi/slack-github-action@v1.24.0
name: Threaded slack notification for version comparison
if: ${{ env.ENVIRONMENT == 'production' }}
if: ${{ env.ENVIRONMENT == 'production' }}
id: slack_threaded_version
with:
channel-id: ${{ env.SLACK_CHANNEL_ID }}
Expand All @@ -206,4 +234,4 @@ jobs:
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_GITHUB_BOT_TOKEN }}
TAGS: ${{ steps.tag_to_deploy.outputs.tag }}
JSON_CHANGELOG_CONTENT: ${{ steps.changelog_json_content.outputs.changelog_json }}
JSON_CHANGELOG_CONTENT: ${{ steps.changelog_json_content.outputs.changelog_json }}
92 changes: 74 additions & 18 deletions .github/workflows/cron_merged-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
image_repo:
required: true
type: string
description: "Your container registry repository - like eu.gcr.io/ultimateai-169214"
default: europe-docker.pkg.dev/common-main-cfc4/eu.gcr.io
description: "Your container registry repository - like europe-docker.pkg.dev/common-main-cfc4/eu.gcr.io"
app_squad:
required: true
type: string
Expand Down Expand Up @@ -72,7 +73,6 @@ on:
description: "Npm version used in the pipeline, defaults to LTS version"



env:
IMAGE_REPO: ${{ inputs.image_repo }}
APP_SQUAD: ${{ inputs.app_squad }}
Expand All @@ -89,6 +89,8 @@ env:
BUILD_COMMAND: ${{ inputs.build_command }}
LINT_COMMAND: ${{ inputs.lint_command }}
NPM_VERSION: ${{ inputs.npm_version }}
GCR_ENABLED: ${{ vars.GCR_ENABLED || 'true' }}
GAR_ENABLED: ${{ vars.GAR_ENABLED || 'true' }}

jobs:
bump-release:
Expand All @@ -99,7 +101,7 @@ jobs:
contents: "read"
id-token: "write"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.ULTIMATE_GITHUB_PAT }}
Expand All @@ -115,7 +117,7 @@ jobs:
initial_release: ${{ env.INITIAL_RELEASE }}

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

Expand All @@ -126,7 +128,7 @@ jobs:
### Authentings with Google Cloud because of artifact registry ###
- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v1"
uses: "google-github-actions/auth@v2"
with:
token_format: "access_token"
workload_identity_provider: "${{ secrets.WIF_PROVIDER_NAME }}"
Expand Down Expand Up @@ -158,13 +160,19 @@ jobs:
contents: "read"
id-token: "write"
steps:
- uses: actions/checkout@v3
- name: Validation
if: ${{ env.GCR_ENABLED != 'true' && env.GAR_ENABLED != 'true' }}
run: |
echo "At least one of GCR_ENABLED or GAR_ENABLED must be set to true.'
exit 1
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

Expand All @@ -173,11 +181,39 @@ jobs:
run: npm i -g npm@${{ env.NPM_VERSION }} --registry=https://registry.npmjs.org

- id: "image_name"
name: "Get repo name and update IMAGE_NAME"
name: "Extract repo name and update IMAGE_NAME"
run: |-
IMAGE_NAME=$IMAGE_REPO"/"${{ github.event.repository.name }}
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
REPO_DOMAIN=$(echo $IMAGE_REPO | cut -d '/' -f 1)
case $REPO_DOMAIN in
*gcr.io)
GCR_DOMAIN=$REPO_DOMAIN
GAR_DOMAIN=europe-docker.pkg.dev
GCR_IMAGE_REPO=$IMAGE_REPO
GAR_IMAGE_REPO=europe-docker.pkg.dev/common-main-cfc4/eu.gcr.io ;;
*pkg.dev)
GCR_DOMAIN=eu.gcr.io
GAR_DOMAIN=$REPO_DOMAIN
GCR_IMAGE_REPO=eu.gcr.io/ultimateai-169214
GAR_IMAGE_REPO=$IMAGE_REPO ;;
esac
GCR_IMAGE_NAME=$GCR_IMAGE_REPO"/"${{ github.event.repository.name }}
GAR_IMAGE_NAME=$GAR_IMAGE_REPO"/"${{ github.event.repository.name }}
if [ "$GAR_ENABLED" == "true" ]
then
IMAGE_NAME=$GAR_IMAGE_NAME
else
IMAGE_NAME=$GCR_IMAGE_NAME
fi
echo "gcr_domain=$GCR_DOMAIN" >> $GITHUB_OUTPUT
echo "gar_domain=$GAR_DOMAIN" >> $GITHUB_OUTPUT
echo "gcr_image_repo=$GCR_IMAGE_REPO" >> $GITHUB_OUTPUT
echo "gar_image_repo=$GAR_IMAGE_REPO" >> $GITHUB_OUTPUT
echo "gcr_image_name=$GCR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "gar_image_name=$GAR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Get environment.env file and scheduler for updating k8s-manifest repo
run: |-
Expand All @@ -202,16 +238,25 @@ jobs:
### Authentings with Google Cloud to Push Image to GCR ###
- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v1"
uses: "google-github-actions/auth@v2"
with:
token_format: "access_token"
workload_identity_provider: "${{ secrets.WIF_PROVIDER_NAME }}"
service_account: ${{ secrets.GSA_GCR_EMAIL }}

- name: "Authenticating docker to push to gcr"
uses: docker/login-action@v2.1.0
if: ${{ env.GCR_ENABLED == 'true' }}
uses: docker/login-action@v3
with:
registry: "eu.gcr.io"
registry: "${{ steps.image_name.outputs.GCR_DOMAIN }}"
username: "oauth2accesstoken"
password: "${{ steps.auth.outputs.access_token }}"

- name: "Authenticating docker to push to gar"
if: ${{ env.GAR_ENABLED == 'true' }}
uses: docker/login-action@v3
with:
registry: "${{ steps.image_name.outputs.GAR_DOMAIN }}"
username: "oauth2accesstoken"
password: "${{ steps.auth.outputs.access_token }}"

Expand All @@ -236,23 +281,34 @@ jobs:

- name: Docker build
run: |-
docker build -t "${IMAGE_NAME}:${TAGS}" .
docker build -t "${GCR_IMAGE_NAME}:${TAGS}" -t "${GAR_IMAGE_NAME}:${TAGS}" .
shell: bash
env:
TAGS: ${{ steps.fetch_latest_release.outputs.tag_name }}
IMAGE_NAME: ${{ steps.image_name.outputs.image_name }}
GCR_IMAGE_NAME: ${{ steps.image_name.outputs.gcr_image_name }}
GAR_IMAGE_NAME: ${{ steps.image_name.outputs.gar_image_name }}

- name: Docker push
- name: Docker push to GCR
if: ${{ env.GCR_ENABLED == 'true' }}
run: |-
docker push "${IMAGE_NAME}:${TAGS}"
shell: bash
env:
TAGS: ${{ steps.fetch_latest_release.outputs.tag_name }}
IMAGE_NAME: ${{ steps.image_name.outputs.image_name }}
IMAGE_NAME: ${{ steps.image_name.outputs.gcr_image_name }}

- name: Docker push to GAR
if: ${{ env.GAR_ENABLED == 'true' }}
run: |-
docker push "${IMAGE_NAME}:${TAGS}"
shell: bash
env:
TAGS: ${{ steps.fetch_latest_release.outputs.tag_name }}
IMAGE_NAME: ${{ steps.image_name.outputs.gar_image_name }}

##Automatic deploy to development on merged PR to main
- name: "Checkout k8s manifests"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ env.K8S_MANIFESTS_REPO }}
token: ${{ secrets.ULTIMATE_GITHUB_PAT }}
Expand Down
Loading

0 comments on commit 2b641c2

Please sign in to comment.