Skip to content

Commit

Permalink
refactored release-env to introduce database reset step (#270)
Browse files Browse the repository at this point in the history
* refactored release-env to introduce database reset step

* fix lint

* refactored release pipeline

* fix: improved comment

* fix: fixed lint issue

* fix lint issue

* resolve lint issues

* fix: removed comment

* add reset-db param to releanse env job

* fix: added trigger_pipeline param
  • Loading branch information
junydania authored Jul 24, 2024
1 parent 74ec767 commit ba4907e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/commands/vfcli/vfcli-delete-or-release-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ parameters:
type: string
description: Path to the env_name file
default: "/home/circleci/voiceflow/env_name.txt"
reset-db:
type: boolean
description: Whether to reset the database
default: false
steps:
- restore_cache:
key: env_name_cache-{{ .Environment.CIRCLE_PROJECT_REPONAME }}-{{ .Environment.CIRCLE_WORKFLOW_ID }}
Expand All @@ -36,6 +40,24 @@ steps:
if [[ "$env_name" != "null" ]] && [[ -n "$env_name" ]]; then
echo "Releasing the environment..... $env_name"
vfcli pool release-env --env-name "$env_name"
if [[ << parameters.reset-db >> == true ]]; then
echo "Resetting the database for $env_name"
vfcli pool release-env --env-name "$env_name"
echo "Triggering pipeline with env-name parameter"
response=$(curl -s -o /dev/null -w "%{http_code}" \
--request POST \
--url "https://circleci.com/api/v2/project/gh/voiceflow/env-release-system/pipeline" \
--header "Circle-Token: ${CIRCLECI_API_TOKEN}" \
--header "content-type: application/json" \
--data "{\"parameters\":{\"e2e_env_name\":\"$env_name\",\"trigger_pipeline\":true}}")
if [[ $response == "201" ]]; then
echo "Env Release Pipeline triggered successfully. Exiting with success."
exit 0
else
echo "Failed to trigger pipeline. HTTP status code: $response"
exit 1
fi
fi
vfcli env resume "$env_name" --interactive false
vfcli track attach --branch master --components all --name "$env_name" --interactive false --no-circleci
vfcli pool free-env --env-name "$env_name"
Expand Down
1 change: 0 additions & 1 deletion src/commands/vfcli/vfcli-resetdb-free-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ steps:
vfcli env resume "$env_name" --interactive false
vfcli track attach --branch master --components all --name "$env_name" --interactive false --no-circleci
vfcli env database reset --name "$env_name"
vfcli component restart --name "$env_name" --wait
vfcli pool free-env --env-name "$env_name"
5 changes: 5 additions & 0 deletions src/jobs/e2e/release-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ parameters:
type: string
description: When to run this command
default: always
reset-db:
type: boolean
description: Whether to reset the database
default: false
steps:
- install-vfcli:
init-cluster: << parameters.cluster >>
- vfcli-delete-or-release-env:
env-name: << parameters.env-name >>
reset-db: << parameters.reset-db >>
when: << parameters.when >>

0 comments on commit ba4907e

Please sign in to comment.