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

For all the cronjob workflows #62

Merged
merged 7 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 11 additions & 7 deletions .github/workflows/cron_deploy-from-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ env:
GCR_DEFAULT_REPO: ${{ vars.GCR_DEFAULT_REPO }}
GAR_DEFAULT_REPO: ${{ vars.GAR_DEFAULT_REPO }}
REGION: ${{ inputs.region }}
AVAILABLE_ZONES_FOR_DEPLOYMENT: ${{ vars.AVAILABLE_ZONES_FOR_DEPLOYMENT }}


jobs:
Expand All @@ -97,13 +98,16 @@ jobs:
echo "At least one of GCR_ENABLED or GAR_ENABLED must be set to true."
echo "At least one of GCR_ENABLED or GAR_ENABLED must be set to true." >> $GITHUB_STEP_SUMMARY
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

- name: Check if region is valid
run: |-
if [[ " ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]} " =~ ${{ env.REGION }} ]]; then
echo "This region - ${{ env.REGION }} - is allowed"
else
echo "Region - ${{ env.REGION }} - is not yet supported. Supported regions are: ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]}"
echo "::error::Region - ${{ env.REGION }} - is not yet supported. Supported regions are: ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]}"
exit 1
fi

- name: Checkout to selected branch
uses: actions/checkout@v4
Expand Down
57 changes: 56 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,8 @@ env:
GAR_ENABLED: ${{ vars.GAR_ENABLED || 'true' }}
GCR_DEFAULT_REPO: ${{ vars.GCR_DEFAULT_REPO }}
GAR_DEFAULT_REPO: ${{ vars.GAR_DEFAULT_REPO }}
REGION: ${{ inputs.region }}
AVAILABLE_ZONES_FOR_DEPLOYMENT: ${{ vars.AVAILABLE_ZONES_FOR_DEPLOYMENT }}

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

- name: Check if region is valid
run: |-
if [[ " ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]} " =~ ${{ env.REGION }} ]]; then
echo "This region - ${{ env.REGION }} - is allowed"
else
echo "Region - ${{ env.REGION }} - is not yet supported. Supported regions are: ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]}"
echo "::error::Region - ${{ env.REGION }} - is not yet supported. Supported regions are: ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]}"
exit 1
fi

- id: "image_name"
name: "Extract repo name and update IMAGE_NAME"
Expand Down Expand Up @@ -94,7 +111,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 +127,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/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
Expand Down Expand Up @@ -170,9 +205,29 @@ 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
ls $HOME
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 }}

- 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}/$ENVIRONMENT
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}
Expand Down
87 changes: 85 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,8 @@ env:
GAR_ENABLED: ${{ vars.GAR_ENABLED || 'true' }}
GCR_DEFAULT_REPO: ${{ vars.GCR_DEFAULT_REPO }}
GAR_DEFAULT_REPO: ${{ vars.GAR_DEFAULT_REPO }}
REGION: ${{ inputs.region }}
AVAILABLE_ZONES_FOR_DEPLOYMENT: ${{ vars.AVAILABLE_ZONES_FOR_DEPLOYMENT }}

jobs:
bump-release:
Expand Down Expand Up @@ -166,6 +173,16 @@ jobs:
run: |
echo "At least one of GCR_ENABLED or GAR_ENABLED must be set to true.'
exit 1

- name: Check if region is valid
run: |-
if [[ " ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]} " =~ ${{ env.REGION }} ]]; then
echo "This region - ${{ env.REGION }} - is allowed"
else
echo "Region - ${{ env.REGION }} - is not yet supported. Supported regions are: ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]}"
echo "::error::Region - ${{ env.REGION }} - is not yet supported. Supported regions are: ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]}"
exit 1
fi

- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -216,7 +233,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 +248,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 +347,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 +395,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 }}
58 changes: 56 additions & 2 deletions .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,8 @@ env:
GAR_ENABLED: ${{ vars.GAR_ENABLED || 'true' }}
GCR_DEFAULT_REPO: ${{ vars.GCR_DEFAULT_REPO }}
GAR_DEFAULT_REPO: ${{ vars.GAR_DEFAULT_REPO }}
REGION: ${{ inputs.region }}
AVAILABLE_ZONES_FOR_DEPLOYMENT: ${{ vars.AVAILABLE_ZONES_FOR_DEPLOYMENT }}

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

- name: Check if region is valid
run: |-
if [[ " ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]} " =~ ${{ env.REGION }} ]]; then
echo "This region - ${{ env.REGION }} - is allowed"
else
echo "Region - ${{ env.REGION }} - is not yet supported. Supported regions are: ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]}"
echo "::error::Region - ${{ env.REGION }} - is not yet supported. Supported regions are: ${AVAILABLE_ZONES_FOR_DEPLOYMENT[*]}"
exit 1
fi

- id: "image_name"
name: "Extract repo name and update IMAGE_NAME"
Expand Down Expand Up @@ -111,7 +128,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 +144,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 @@ -153,7 +188,8 @@ jobs:
env:
TAGS: ${{ steps.tag_to_deploy.outputs.tag }}

- name: Update the Image tags for Selected Environment
- name: Update the Image tags for Selected Environment for Europe region
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 +205,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 for non europe region
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
Loading