forked from AztecProtocol/aztec-packages
-
Notifications
You must be signed in to change notification settings - Fork 1
143 lines (129 loc) · 4.75 KB
/
metrics-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Aztec Metrics Stack Deployment
on:
workflow_call:
inputs:
namespace:
description: The namespace to deploy to, e.g. metrics
required: true
type: string
default: metrics
values_file:
description: The values file to use, e.g. prod.yaml
required: true
type: string
default: "prod.yaml"
respect_tf_lock:
description: Whether to respect the Terraform lock
required: false
type: string
default: "true"
run_terraform_destroy:
description: Whether to run terraform destroy before deploying
required: false
type: string
default: "false"
ref:
description: The branch name to deploy from
required: false
type: string
default: "master"
secrets:
GCP_SA_KEY:
required: true
workflow_dispatch:
inputs:
namespace:
description: The namespace to deploy to, e.g. metrics
required: true
default: metrics
values_file:
description: The values file to use, e.g. prod.yaml
required: true
default: "prod.yaml"
respect_tf_lock:
description: Whether to respect the Terraform lock
required: false
default: "true"
run_terraform_destroy:
description: Whether to run terraform destroy before deploying
required: false
default: "false"
ref:
description: The branch name to deploy from
required: false
default: "master"
jobs:
metrics_deployment:
# This job will run on Ubuntu
runs-on: ubuntu-latest
concurrency:
group: deploy-${{ github.ref }} # Only one job per branch
cancel-in-progress: false # Allow previous deployment to complete to avoid corruption
# Set up a variable based on the branch name
env:
NAMESPACE: ${{ inputs.namespace }}
VALUES_FILE: ${{ inputs.values_file }}
CHART_PATH: ./spartan/metrics
CLUSTER_NAME: aztec-gke
REGION: us-west1-a
TF_STATE_BUCKET: aztec-terraform
GKE_CLUSTER_CONTEXT: gke_testnet-440309_us-west1-a_aztec-gke
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Install GKE Auth Plugin
run: |
gcloud components install gke-gcloud-auth-plugin --quiet
- name: Configure kubectl with GKE cluster
run: |
gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --region ${{ env.REGION }}
- name: Ensure Terraform state bucket exists
run: |
if ! gsutil ls gs://${{ env.TF_STATE_BUCKET }} >/dev/null 2>&1; then
echo "Creating GCS bucket for Terraform state..."
gsutil mb -l us-east4 gs://${{ env.TF_STATE_BUCKET }}
gsutil versioning set on gs://${{ env.TF_STATE_BUCKET }}
else
echo "Terraform state bucket already exists"
fi
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: "1.5.0" # Specify your desired version
- name: Terraform Init
working-directory: ./spartan/terraform/deploy-metrics
run: |
terraform init \
-backend-config="bucket=${{ env.TF_STATE_BUCKET }}" \
-backend-config="prefix=metrics-deploy/${{ env.REGION }}/${{ env.CLUSTER_NAME }}/${{ env.NAMESPACE }}/terraform.tfstate"
- name: Terraform Destroy
working-directory: ./spartan/terraform/deploy-metrics
if: ${{ inputs.run_terraform_destroy == 'true' }}
# Destroy fails if the resources are already destroyed, so we continue on error
continue-on-error: true
run: |
terraform destroy -auto-approve \
-var="RELEASE_NAME=${{ env.NAMESPACE }}" \
-var="VALUES_FILE=${{ env.VALUES_FILE }}" \
-var="GKE_CLUSTER_CONTEXT=${{ env.GKE_CLUSTER_CONTEXT }}" \
-lock=${{ inputs.respect_tf_lock }}
- name: Terraform Plan
working-directory: ./spartan/terraform/deploy-metrics
run: |
terraform plan \
-var="RELEASE_NAME=${{ env.NAMESPACE }}" \
-var="VALUES_FILE=${{ env.VALUES_FILE }}" \
-var="GKE_CLUSTER_CONTEXT=${{ env.GKE_CLUSTER_CONTEXT }}" \
-out=tfplan \
-lock=${{ inputs.respect_tf_lock }}
- name: Terraform Apply
working-directory: ./spartan/terraform/deploy-metrics
run: terraform apply -lock=${{ inputs.respect_tf_lock }} -auto-approve tfplan