Skip to content

Commit 7e19b39

Browse files
authored
feat: deploy networks via github actions (#10381)
I used locally with [act](https://github.com/nektos/act) to deploy a smoke network in the new aztec-gke cluster.
1 parent 5a02480 commit 7e19b39

File tree

4 files changed

+84
-33
lines changed

4 files changed

+84
-33
lines changed

.github/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.secrets

.github/workflows/network-deploy.yml

+63-31
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
name: Aztec Network EKS Deployment
2-
3-
# Manual trigerring of this workflow is intentionally disabled
4-
# Helm deployments do not support lock files
5-
# Without a lockfile, manual trigerring can lead to corrupted or partial deployments
1+
name: Aztec Network Deployment
62

73
on:
8-
push:
9-
branches:
10-
- staging
11-
- production
12-
pull_request:
13-
branches:
14-
- staging
15-
- production
4+
workflow_dispatch:
5+
inputs:
6+
namespace:
7+
description: The namespace to deploy to, e.g. smoke
8+
required: true
9+
values_file:
10+
description: The values file to use, e.g. 1-validators.yaml
11+
required: true
12+
aztec_docker_image:
13+
description: The Aztec Docker image to use, e.g. aztecprotocol/aztec:da809c58290f9590836f45ec59376cbf04d3c4ce-x86_64
14+
required: true
1615

1716
jobs:
1817
network_deployment:
@@ -24,34 +23,67 @@ jobs:
2423

2524
# Set up a variable based on the branch name
2625
env:
27-
NAMESPACE: ${{ github.ref == 'refs/heads/production' && 'production' || 'staging' }}
26+
AZTEC_DOCKER_IMAGE: ${{ inputs.aztec_docker_image }}
27+
NAMESPACE: ${{ inputs.namespace }}
28+
VALUES_FILE: ${{ inputs.values_file }}
2829
CHART_PATH: ./spartan/aztec-network
30+
CLUSTER_NAME: aztec-gke
31+
REGION: us-west1-a
32+
TF_STATE_BUCKET: aztec-terraform
33+
GKE_CLUSTER_CONTEXT: gke_testnet-440309_us-west1-a_aztec-gke
2934

3035
steps:
31-
# Step 1: Check out the repository's code
3236
- name: Checkout code
3337
uses: actions/checkout@v3
3438

35-
# Step 2: Configure AWS credentials using GitHub Secrets
36-
- name: Configure AWS credentials
37-
uses: aws-actions/configure-aws-credentials@v2
39+
- name: Authenticate to Google Cloud
40+
uses: google-github-actions/auth@v2
3841
with:
39-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
40-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41-
aws-region: us-east-1
42+
credentials_json: ${{ secrets.GCP_SA_KEY }}
43+
44+
- name: Set up Cloud SDK
45+
uses: google-github-actions/setup-gcloud@v2
4246

43-
# Step 3: Set up Kubernetes context for AWS EKS
44-
- name: Configure kubectl with EKS cluster
47+
- name: Install GKE Auth Plugin
4548
run: |
46-
aws eks update-kubeconfig --region us-east-1 --name spartan
49+
gcloud components install gke-gcloud-auth-plugin --quiet
4750
48-
# Step 4: Install Helm
49-
- name: Install Helm
51+
- name: Configure kubectl with GKE cluster
5052
run: |
51-
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
53+
gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --region ${{ env.REGION }}
5254
53-
# Step 5: Apply Helm Chart
54-
- name: Deploy Helm chart
55+
- name: Ensure Terraform state bucket exists
5556
run: |
56-
helm dependency update ${{ env.CHART_PATH }}
57-
helm upgrade --install ${{ env.NAMESPACE }} ${{ env.CHART_PATH }} --namespace ${{ env.NAMESPACE }} --set network.public=true --atomic --create-namespace --timeout 20m
57+
if ! gsutil ls gs://${{ env.TF_STATE_BUCKET }} >/dev/null 2>&1; then
58+
echo "Creating GCS bucket for Terraform state..."
59+
gsutil mb -l us-east4 gs://${{ env.TF_STATE_BUCKET }}
60+
gsutil versioning set on gs://${{ env.TF_STATE_BUCKET }}
61+
else
62+
echo "Terraform state bucket already exists"
63+
fi
64+
65+
- name: Setup Terraform
66+
uses: hashicorp/setup-terraform@v2
67+
with:
68+
terraform_version: "1.5.0" # Specify your desired version
69+
70+
- name: Terraform Init
71+
working-directory: ./spartan/terraform/deploy-release
72+
run: |
73+
terraform init \
74+
-backend-config="bucket=${{ env.TF_STATE_BUCKET }}" \
75+
-backend-config="prefix=network-deploy/${{ env.REGION }}/${{ env.CLUSTER_NAME }}/${{ env.NAMESPACE }}/terraform.tfstate" \
76+
77+
- name: Terraform Plan
78+
working-directory: ./spartan/terraform/deploy-release
79+
run: |
80+
terraform plan \
81+
-var="release_name=${{ env.NAMESPACE }}" \
82+
-var="values_file=${{ env.VALUES_FILE }}" \
83+
-var="gke_cluster_context=${{ env.GKE_CLUSTER_CONTEXT }}" \
84+
-var="aztec_docker_image=${{ env.AZTEC_DOCKER_IMAGE }}" \
85+
-out=tfplan
86+
87+
- name: Terraform Apply
88+
working-directory: ./spartan/terraform/deploy-release
89+
run: terraform apply -auto-approve tfplan

spartan/terraform/deploy-release/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
2-
backend "s3" {
2+
backend "gcs" {
33
bucket = "aztec-terraform"
4-
region = "eu-west-2"
4+
prefix = "terraform/state"
55
}
66
required_providers {
77
helm = {

spartan/terraform/gke-cluster/main.tf

+18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ resource "google_project_iam_member" "gke_sa_roles" {
3838
member = "serviceAccount:${google_service_account.gke_sa.email}"
3939
}
4040

41+
# Create a new service account for Helm
42+
resource "google_service_account" "helm_sa" {
43+
account_id = "helm-sa"
44+
display_name = "Helm Service Account"
45+
description = "Service account for Helm operations"
46+
}
47+
48+
# Add IAM roles to the Helm service account
49+
resource "google_project_iam_member" "helm_sa_roles" {
50+
for_each = toset([
51+
"roles/container.admin",
52+
"roles/storage.admin"
53+
])
54+
project = var.project
55+
role = each.key
56+
member = "serviceAccount:${google_service_account.helm_sa.email}"
57+
}
58+
4159
# Create a GKE cluster
4260
resource "google_container_cluster" "primary" {
4361
name = "spartan-gke"

0 commit comments

Comments
 (0)