-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add reset workflow (only development env) (#1594)
- Loading branch information
1 parent
fa4cb25
commit bdbc996
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: "Dispatch tc-cli workflow" | ||
description: "Trigger a tc-cli command" | ||
|
||
inputs: | ||
version: | ||
description: "Docker image version tag" | ||
required: true | ||
default: "dev" | ||
token: | ||
description: "Github API Token" | ||
required: true | ||
environment: | ||
description: "Target env for the tc-cli dispatch" | ||
required: true | ||
args: | ||
description: "Tc-cli arguments" | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Trigger dispatch | ||
shell: bash | ||
run: | | ||
set -e; | ||
CODE=$(curl -X POST --silent --output curl_out \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{ inputs.token }}" \ | ||
https://api.github.com/repos/Analog-Labs/timechain/actions/workflows/dispatch-tc-cli.yaml/dispatches \ | ||
-d '{ | ||
"ref": "development", | ||
"inputs": { | ||
"version": "'${{ inputs.version }}'", | ||
"environment": "'${{ inputs.environment }}'", | ||
"args": "'${{ inputs.args }}'" | ||
} | ||
}' --write-out "%{http_code}" "$@"); | ||
if [[ ${CODE} -lt 200 || ${CODE} -gt 299 ]] ; then | ||
cat curl_out; | ||
exit 1; | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Reset Timechain | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
description: "Target environment to reset" | ||
required: true | ||
type: string | ||
options: | ||
- development | ||
|
||
jobs: | ||
reset-timechain: | ||
runs-on: ubuntu-latest | ||
environment: ${{ github.event.inputs.environment }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: GKE Setup | ||
uses: ./.github/actions/gke-common | ||
with: | ||
cluster: ${{ github.event.inputs.environment }} | ||
key-file: ${{ secrets.TIMECHAIN_RESET_KEY }} | ||
project-id: ${{ secrets.GCP_PROJECT_ID }} | ||
region: us-east1 | ||
|
||
- name: Install helm | ||
uses: azure/[email protected] | ||
|
||
- name: Purge cluster | ||
run: | | ||
NAMESPACE="timechain" | ||
LATEST_REVISION=$(helm history ${{ secrets.RELESE_NAME }} -n $NAMESPACE | awk 'END{print $1}') | ||
# Delete all volumes | ||
# NOTE: can't wait for this command since PVCs | ||
# can't be deleted while pods are running | ||
kubectl delete pvc --all -n $NAMESPACE --wait=false | ||
# Rollback to the same version, ensuring recreation of all PVCs | ||
if [[ -n "$LATEST_REVISION" ]]; then | ||
helm rollback ${{ secrets.RELESE_NAME }} $LATEST_REVISION -n $NAMESPACE | ||
else | ||
echo "No Helm release found to roll back." | ||
exit 1 | ||
fi | ||
# NOTE: this step might be redundant, but just to make sure | ||
# We give it 1 minute to finish cleaning up | ||
kubectl delete pods --all -n $NAMESPACE --timeout=60s | ||
kubectl get pods -n $NAMESPACE | ||
- name: Re-deploy GMP components | ||
uses: ./.github/actions/tc-cli | ||
with: | ||
environment: ${{ github.event.inputs.environment }} | ||
version: "latest" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
args: deploy |