Skip to content

Commit

Permalink
ci: add reset workflow (only development env) (#1594)
Browse files Browse the repository at this point in the history
  • Loading branch information
penumbra23 authored Feb 25, 2025
1 parent fa4cb25 commit bdbc996
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/actions/tc-cli/action.yaml
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
61 changes: 61 additions & 0 deletions .github/workflows/dispatch-reset-cluster.yaml
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

0 comments on commit bdbc996

Please sign in to comment.