Skip to content

Commit

Permalink
For all the cronjob workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
robgutsopedra committed Mar 17, 2024
1 parent ee9e52d commit fc18c1c
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 4 deletions.
52 changes: 51 additions & 1 deletion .github/workflows/cron_manual-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ on:
type: string
default: "#plt-239"
description: "Slack channel ID where you want your notifications"
region:
required: false
type: string
description: "Region name to deploy - europe or us-central1, defaults to europe"
default: "europe"


env:
Expand All @@ -46,6 +51,7 @@ env:
GAR_ENABLED: ${{ vars.GAR_ENABLED || 'true' }}
GCR_DEFAULT_REPO: ${{ vars.GCR_DEFAULT_REPO }}
GAR_DEFAULT_REPO: ${{ vars.GAR_DEFAULT_REPO }}
REGION: ${{ inputs.region }}

jobs:
deploy:
Expand All @@ -58,6 +64,13 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Region Validation
if: ${{ env.REGION != 'europe' && env.REGION != 'us-central1' }}
run: |
echo "Region must be either 'europe' or 'us-central1'."
echo "Region must be either 'europe' or 'us-central1'." >> $GITHUB_STEP_SUMMARY
exit 1
- id: "image_name"
name: "Extract repo name and update IMAGE_NAME"
Expand Down Expand Up @@ -94,7 +107,8 @@ jobs:
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
- name: Get env file and scheduler for updating k8s-manifest repo in case of europe region
if: ${{ env.REGION == 'europe' }}
run: |-
if [[ "${ENVIRONMENT}" = "production" ]]; then
cat "deployment_envs/prod.env" > $HOME/envfile.env
Expand All @@ -109,6 +123,23 @@ jobs:
if [[ -f "deployment_envs/common.env" ]]; then
echo "Please delete deployment_envs/common.env" >> $GITHUB_STEP_SUMMARY
fi
- name: Get env file and scheduler for updating k8s-manifest repo in case of us region
if: ${{ env.REGION != 'europe' }}
run: |-
if [[ "${ENVIRONMENT}" = "production" ]]; then
cat "deployment_envs/region/${{ env.REGION }}/prod.env" > $HOME/envfile.env
cat "deployment_schedules/region/${{ env.REGION }}/prod" > $HOME/scheduler
elif [[ "${ENVIRONMENT}" = "staging" ]]; then
cat "deployment_envs/region/${{ env.REGION }}/stage.env" > $HOME/envfile.env
cat "deployment_schedules/region/${{ env.REGION }}/stage" > $HOME/scheduler
else
cat "deployment_envs/region/${{ env.REGION }}/dev.env" > $HOME/envfile.env
cat "deployment_schedules/region/${{ env.REGION }}/dev" > $HOME/cheduler
fi
if [[ -f "deployment_envs/region/${{ env.REGION }}/common.env" ]]; then
echo "Please delete deployment_envs/region/${{ env.REGION }}/common.env" >> $GITHUB_STEP_SUMMARY
fi
- id: fetch_latest_release
uses: ultimateai/fetch-latest-release@2.1.1
Expand Down Expand Up @@ -170,6 +201,7 @@ jobs:
echo "changelog_json=$JSON_CONTENT" >> $GITHUB_OUTPUT
- name: Update the Image tags and env files for Selected Environment
if: ${{ env.REGION == 'europe' }}
run: |-
cd $APP_SQUAD/${{ github.event.repository.name }}/overlay/$ENVIRONMENT
FILE_ENV=$(ls | grep ".env");cat $HOME/envfile.env > $FILE_ENV
Expand All @@ -185,6 +217,24 @@ jobs:
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 }}

- name: Update the Image tags and env files for Selected Environment
if: ${{ env.REGION != 'europe' }}
run: |-
cd $APP_SQUAD/${{ github.event.repository.name }}/region/${REGION}/${K8S_ENV_NAME}
FILE_ENV=$(ls | grep ".env");cat $HOME/envfile.env > $FILE_ENV
scheduler=$(cat $HOME/scheduler)
yq ".spec.schedule = \"$scheduler\"" -i cronjob.yaml
kustomize edit set image app=${IMAGE_NAME}:${TAGS}
cat kustomization.yaml
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
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.24.0
name: Slack notification
Expand Down
83 changes: 81 additions & 2 deletions .github/workflows/cron_merged-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ on:
required: false
type: string
description: "Npm version used in the pipeline, defaults to LTS version"
region:
required: false
type: string
description: "Region name to deploy - europe or us-central1, defaults to europe"
default: "europe"


env:
Expand All @@ -92,6 +97,7 @@ env:
GAR_ENABLED: ${{ vars.GAR_ENABLED || 'true' }}
GCR_DEFAULT_REPO: ${{ vars.GCR_DEFAULT_REPO }}
GAR_DEFAULT_REPO: ${{ vars.GAR_DEFAULT_REPO }}
REGION: ${{ inputs.region }}

jobs:
bump-release:
Expand Down Expand Up @@ -166,6 +172,13 @@ jobs:
run: |
echo "At least one of GCR_ENABLED or GAR_ENABLED must be set to true.'
exit 1
- name: Region Validation
if: ${{ env.REGION != 'europe' && env.REGION != 'us-central1' }}
run: |
echo "Region must be either 'europe' or 'us-central1'."
echo "Region must be either 'europe' or 'us-central1'." >> $GITHUB_STEP_SUMMARY
exit 1
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -216,7 +229,8 @@ jobs:
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
- name: Get environment.env file and scheduler for updating k8s-manifest repo in europe region scenario
if: ${{ env.REGION == 'europe' }}
run: |-
if [[ "${AUTOMATIC_DEPLOYMENT_TO}" == *"staging"* ]]; then
cat "deployment_envs/stage.env" > $HOME/staging-envfile.env
Expand All @@ -230,6 +244,21 @@ jobs:
echo "Please delete deployment_envs/common.env" >> $GITHUB_STEP_SUMMARY
fi
- name: Get environment.env file and scheduler for updating k8s-manifest repo in us region scenario
if: ${{ env.REGION != 'europe' }}
run: |-
if [[ "${AUTOMATIC_DEPLOYMENT_TO}" == *"staging"* ]]; then
cat "deployment_envs/region/${{ env.REGION }}/stage.env" > $HOME/staging-envfile.env
cat "deployment_schedules/region/${{ env.REGION }}/stage" > $HOME/staging-scheduler
fi
if [[ "${AUTOMATIC_DEPLOYMENT_TO}" == *"development"* ]]; then
cat "deployment_envs/region/${{ env.REGION }}/dev.env" > $HOME/development-envfile.env
cat "deployment_schedules/region/${{ env.REGION }}/dev" > $HOME/development-scheduler
fi
if [[ -f "deployment_envs/region/${{ env.REGION }}/common.env" ]]; then
echo "Please delete deployment_envs/region/${{ env.REGION }}/common.env" >> $GITHUB_STEP_SUMMARY
fi
- id: fetch_latest_release
uses: ultimateai/fetch-latest-release@2.1.1
with:
Expand Down Expand Up @@ -314,7 +343,8 @@ jobs:
repository: ${{ env.K8S_MANIFESTS_REPO }}
token: ${{ secrets.ULTIMATE_GITHUB_PAT }}

- name: Update the Image tags for Preproduction Environment
- name: Update the Image tags for Preproduction Environment for europe region
if: ${{ env.REGION == 'europe' }}
run: |-
if [[ $K8S_ENV_NAME == *","* ]]; then
echo "Deploying in multiple environments: $K8S_ENV_NAME"
Expand Down Expand Up @@ -361,3 +391,52 @@ jobs:
REMOTE_REPO: https://${{ secrets.ULTIMATE_GITHUB_PAT }}@github.com/${{ env.K8S_MANIFESTS_REPO }}.git
K8S_ENV_NAME: ${{ env.AUTOMATIC_DEPLOYMENT_TO }}
IMAGE_NAME: ${{ steps.image_name.outputs.image_name }}

- name: Update the Image tags for Preproduction Environment for US region
if: ${{ env.REGION != 'europe' }}
run: |-
if [[ $K8S_ENV_NAME == *","* ]]; then
echo "Deploying in multiple environments: $K8S_ENV_NAME"
IFS=',' read -r -a envs <<< "$K8S_ENV_NAME"
for env in "${envs[@]}"
do
if [[ $env == "development" || $env == "staging" ]]; then
echo "Deploying ${{ github.event.repository.name }} at $env "
cd $APP_SQUAD/${{ github.event.repository.name }}/region/${REGION}/$env
FILE_ENV=$(ls | grep ".env");cat $HOME/$env-envfile.env > $FILE_ENV
kustomize edit set image app=${IMAGE_NAME}:${TAGS}
scheduler=$(cat $HOME/$env-scheduler)
yq ".spec.schedule = \"$scheduler\"" -i cronjob.yaml
cat kustomization.yaml
git config --local user.email $GITHUB_EMAIL
git config --local user.name $GITHUB_USER
git commit -m "update $env image to ${IMAGE_NAME}:${TAGS}" -a || echo "Nothing to commit, version ${IMAGE_NAME}:${TAGS} is already deployed to $env" >> $GITHUB_STEP_SUMMARY
git push ${REMOTE_REPO} HEAD:main --force
cd ../../../../
else
echo "You want to deploy automatically to $env, which is not development nor staging. This is not allowed."
exit 1
fi
done
else
if [[ "${K8S_ENV_NAME}" == "development" || "${K8S_ENV_NAME}" == "staging" ]]; then
cd $APP_SQUAD/${{ github.event.repository.name }}/region/${REGION}/${K8S_ENV_NAME}
FILE_ENV=$(ls | grep ".env");cat $HOME/${K8S_ENV_NAME}-envfile.env > $FILE_ENV
kustomize edit set image app=${IMAGE_NAME}:${TAGS}
cat kustomization.yaml
scheduler=$(cat $HOME/${K8S_ENV_NAME}-scheduler)
yq ".spec.schedule = \"$scheduler\"" -i cronjob.yaml
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 ${IMAGE_NAME}:${TAGS} is already deployed to ${K8S_ENV_NAME}" >> $GITHUB_STEP_SUMMARY
git push ${REMOTE_REPO} HEAD:main --force
else
echo "You want to deploy automatically to ${K8S_ENV_NAME}, which is not development nor staging. This is not allowed."
exit 1
fi
fi
env:
TAGS: ${{ steps.fetch_latest_release.outputs.tag_name }}
REMOTE_REPO: https://${{ secrets.ULTIMATE_GITHUB_PAT }}@github.com/${{ env.K8S_MANIFESTS_REPO }}.git
K8S_ENV_NAME: ${{ env.AUTOMATIC_DEPLOYMENT_TO }}
IMAGE_NAME: ${{ steps.image_name.outputs.image_name }}
52 changes: 51 additions & 1 deletion .github/workflows/cron_rollback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ on:
type: string
default: "#plt-239"
description: "Slack channel ID where you want your notifications"
region:
required: false
type: string
description: "Region name to deploy - europe or us-central1, defaults to europe"
default: "europe"


env:
Expand All @@ -51,6 +56,7 @@ env:
GAR_ENABLED: ${{ vars.GAR_ENABLED || 'true' }}
GCR_DEFAULT_REPO: ${{ vars.GCR_DEFAULT_REPO }}
GAR_DEFAULT_REPO: ${{ vars.GAR_DEFAULT_REPO }}
REGION: ${{ inputs.region }}

jobs:
deploy_rollback:
Expand All @@ -64,6 +70,13 @@ jobs:
with:
fetch-depth: 0
ref: ${{ inputs.version }}

- name: Region Validation
if: ${{ env.REGION != 'europe' && env.REGION != 'us-central1' }}
run: |
echo "Region must be either 'europe' or 'us-central1'."
echo "Region must be either 'europe' or 'us-central1'." >> $GITHUB_STEP_SUMMARY
exit 1
- id: "image_name"
name: "Extract repo name and update IMAGE_NAME"
Expand Down Expand Up @@ -111,7 +124,8 @@ jobs:
TAG=$VERSION
echo '::set-output name=tag::'$TAG
- name: Get environment.env file for updating k8s-manifest repo
- name: Get environment.env file for updating k8s-manifest repo for europe region
if: ${{ env.REGION == 'europe' }}
run: |-
if [[ "${ENVIRONMENT}" = "production" ]]; then
cat "deployment_envs/prod.env" > $HOME/envfile.env
Expand All @@ -126,6 +140,23 @@ jobs:
if [[ -f "deployment_envs/common.env" ]]; then
echo "Please delete deployment_envs/common.env" >> $GITHUB_STEP_SUMMARY
fi
- name: Get environment.env file for updating k8s-manifest repo for us region
if: ${{ env.REGION != 'europe' }}
run: |-
if [[ "${ENVIRONMENT}" = "production" ]]; then
cat "deployment_envs/region/${{ env.REGION }}/prod.env" > $HOME/envfile.env
cat "deployment_schedules/region/${{ env.REGION }}/prod" > $HOME/scheduler
elif [[ "${ENVIRONMENT}" = "staging" ]]; then
cat "deployment_envs/region/${{ env.REGION }}/stage.env" > $HOME/envfile.env
cat "deployment_schedules/region/${{ env.REGION }}/stage" > $HOME/scheduler
else
cat "deployment_envs/region/${{ env.REGION }}/dev.env" > $HOME/envfile.env
cat "deployment_schedules/region/${{ env.REGION }}/dev" > $HOME/cheduler
fi
if [[ -f "deployment_envs/region/${{ env.REGION }}/common.env" ]]; then
echo "Please delete deployment_envs/region/${{ env.REGION }}/common.env" >> $GITHUB_STEP_SUMMARY
fi
- name: "Checkout k8s manifests"
uses: actions/checkout@v4
Expand Down Expand Up @@ -154,6 +185,7 @@ jobs:
TAGS: ${{ steps.tag_to_deploy.outputs.tag }}

- name: Update the Image tags for Selected Environment
if: ${{ env.REGION == 'europe' }}
run: |-
cd $APP_SQUAD/${{ github.event.repository.name }}/overlay/$ENVIRONMENT
FILE_ENV=$(ls | grep ".env");cat $HOME/envfile.env > $FILE_ENV
Expand All @@ -169,6 +201,24 @@ jobs:
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 }}

- name: Update the Image tags for Selected Environment
if: ${{ env.REGION != 'europe' }}
run: |-
cd $APP_SQUAD/${{ github.event.repository.name }}/region/${REGION}/$ENVIRONMENT
FILE_ENV=$(ls | grep ".env");cat $HOME/envfile.env > $FILE_ENV
kustomize edit set image app=${IMAGE_NAME}:${TAGS}
scheduler=$(cat $HOME/scheduler)
yq ".spec.schedule = \"$scheduler\"" -i cronjob.yaml
cat kustomization.yaml
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
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.24.0
name: Slack notification
Expand Down

0 comments on commit fc18c1c

Please sign in to comment.