-
Notifications
You must be signed in to change notification settings - Fork 284
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
feat: metrics via terraform #10594
Merged
just-mitch
merged 4 commits into
master
from
10439-bug-services-are-not-using-correct-loki-endpoint-when-using-prod-metrics
Dec 10, 2024
+286
−157
Merged
feat: metrics via terraform #10594
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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. 1-validators.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 |
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
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
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
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 @@ | ||
|
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,53 @@ | ||
terraform { | ||
backend "gcs" { | ||
bucket = "aztec-terraform" | ||
prefix = "terraform/state" | ||
} | ||
required_providers { | ||
helm = { | ||
source = "hashicorp/helm" | ||
version = "~> 2.16.1" | ||
} | ||
kubernetes = { | ||
source = "hashicorp/kubernetes" | ||
version = "~> 2.24.0" | ||
} | ||
} | ||
} | ||
|
||
provider "kubernetes" { | ||
alias = "gke-cluster" | ||
config_path = "~/.kube/config" | ||
config_context = var.GKE_CLUSTER_CONTEXT | ||
} | ||
|
||
provider "helm" { | ||
alias = "gke-cluster" | ||
kubernetes { | ||
config_path = "~/.kube/config" | ||
config_context = var.GKE_CLUSTER_CONTEXT | ||
} | ||
} | ||
|
||
# Aztec Helm release for gke-cluster | ||
resource "helm_release" "aztec-gke-cluster" { | ||
provider = helm.gke-cluster | ||
name = var.RELEASE_NAME | ||
repository = "../../" | ||
chart = "metrics" | ||
namespace = var.RELEASE_NAME | ||
create_namespace = true | ||
upgrade_install = true | ||
dependency_update = true | ||
force_update = true | ||
|
||
# base values file | ||
values = [file("../../metrics/values/${var.VALUES_FILE}")] | ||
|
||
|
||
# Setting timeout and wait conditions | ||
timeout = 1200 # 20 minutes in seconds | ||
wait = true | ||
wait_for_jobs = true | ||
|
||
} |
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 @@ | ||
|
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,15 @@ | ||
variable "GKE_CLUSTER_CONTEXT" { | ||
description = "GKE cluster context" | ||
type = string | ||
default = "gke_testnet-440309_us-east4-a_spartan-gke" | ||
} | ||
|
||
variable "RELEASE_NAME" { | ||
description = "Name of helm deployment and k8s namespace" | ||
type = string | ||
} | ||
|
||
variable "VALUES_FILE" { | ||
description = "Name of the values file to use for deployment" | ||
type = string | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a nit but presumably this example should be one of the metrics values files?