Skip to content

Commit 4709157

Browse files
committed
mitch/tmnt-165-create-deploy-eth-devnetyml
1 parent 2640bfe commit 4709157

File tree

11 files changed

+450
-62
lines changed

11 files changed

+450
-62
lines changed

.github/local_workflow.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Runs a github workflow locally.
4+
#
5+
# Needs `act`. See https://nektosact.com/installation/index.html
6+
#
7+
# Bind-mounts the local directory into the container, which executes as the current user.
8+
# Attempts to use a GCP service account, which you can download from
9+
# https://console.cloud.google.com/iam-admin/serviceaccounts
10+
11+
# Your workflow may not need a GCP service account, nor a kubeconfig, etc.
12+
# Feel free to send a PR to tweak the script ;)
13+
14+
# example usage:
15+
# export GOOGLE_APPLICATION_CREDENTIALS=/your/path/to/testnet-helm-sa.json
16+
# alias lwfl=/your/path/to/aztec-clones/alpha/.github/local_workflow.sh
17+
# lwfl deploy_eth_devnet --input cluster=kind --input resource_profile=dev --input namespace=mitch-eth-devnet --input create_static_ips=false
18+
# lwfl deploy_eth_devnet --input cluster=aztec-gke-private --input resource_profile=prod --input namespace=mitch-eth-devnet --input create_static_ips=false
19+
20+
workflow_name=$1
21+
22+
REPO_ROOT=$(git rev-parse --show-toplevel)
23+
24+
if [ -z "$workflow_name" ]; then
25+
echo "Usage: $0 <workflow_name> [args ...]"
26+
exit 1
27+
fi
28+
29+
# get the rest of the args (skip the first one which is the workflow name)
30+
shift
31+
args=("$@")
32+
33+
SA_KEY_JSON=$(cat "$GOOGLE_APPLICATION_CREDENTIALS")
34+
35+
act workflow_dispatch -j $workflow_name \
36+
-s GITHUB_TOKEN="$(gh auth token)" \
37+
-s GCP_SA_KEY="$SA_KEY_JSON" \
38+
-s KUBECONFIG_B64="$(cat $HOME/.kube/config | base64 -w0)" \
39+
--container-options "--user $(id -u):$(id -g)" \
40+
--bind \
41+
--directory $REPO_ROOT "${args[@]}"
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
name: Deploy Eth Devnet
2+
3+
# This workflow is used to deploy the eth devnet to a cluster.
4+
# It can be used to deploy to kind or a GKE cluster.
5+
#
6+
# Set yourself up to run locally with:
7+
# export GOOGLE_APPLICATION_CREDENTIALS=/your/path/to/testnet-helm-sa.json
8+
# alias lwfl=/your/path/to/aztec-clones/alpha/.github/local_workflow.sh
9+
#
10+
# Then deploy to kind:
11+
# lwfl deploy_eth_devnet --input cluster=kind --input resource_profile=dev --input namespace=mitch-eth-devnet --input create_static_ips=false
12+
#
13+
# Or to a GKE cluster:
14+
# lwfl deploy_eth_devnet --input cluster=aztec-gke-private --input resource_profile=prod --input namespace=mitch-eth-devnet --input create_static_ips=false
15+
16+
on:
17+
workflow_call:
18+
inputs:
19+
cluster:
20+
description: The cluster to deploy to, e.g. aztec-gke-private or kind
21+
required: true
22+
type: string
23+
namespace:
24+
description: The namespace to deploy to
25+
required: true
26+
type: string
27+
ref:
28+
description: The branch name to deploy from
29+
required: false
30+
type: string
31+
default: "next"
32+
chain_id:
33+
description: Ethereum chain ID for genesis generation
34+
required: false
35+
type: number
36+
default: 1337
37+
block_time:
38+
description: Block time in seconds for genesis generation
39+
required: false
40+
type: number
41+
default: 12
42+
gas_limit:
43+
description: Gas limit for blocks in genesis generation
44+
required: false
45+
type: string
46+
default: "32000000"
47+
resource_profile:
48+
description: Resource profile to use (dev or prod)
49+
required: false
50+
type: string
51+
default: "prod"
52+
create_static_ips:
53+
description: Whether to create static IPs as part of the eth devnet for the execution and beacon nodes
54+
required: false
55+
type: string
56+
default: "false"
57+
run_terraform_destroy:
58+
description: Whether to run the terraform destroy
59+
required: false
60+
type: string
61+
default: "false"
62+
secrets:
63+
GCP_SA_KEY:
64+
description: The JSON key for the GCP service account
65+
required: true
66+
KUBECONFIG_B64:
67+
description: The base64 encoded kubeconfig
68+
required: true
69+
70+
workflow_dispatch:
71+
inputs:
72+
cluster:
73+
description: The cluster to deploy to, e.g. aztec-gke-private or kind
74+
required: false
75+
type: string
76+
default: "kind"
77+
namespace:
78+
description: The namespace to deploy to
79+
required: false
80+
type: string
81+
default: "eth-devnet"
82+
ref:
83+
description: The branch name to deploy from.
84+
required: false
85+
type: string
86+
default: "next"
87+
chain_id:
88+
description: Ethereum chain ID for genesis generation
89+
required: false
90+
type: number
91+
default: 1337
92+
block_time:
93+
description: Block time in seconds for genesis generation
94+
required: false
95+
type: number
96+
default: 12
97+
gas_limit:
98+
description: Gas limit for blocks in genesis generation
99+
required: false
100+
type: string
101+
default: "32000000"
102+
resource_profile:
103+
description: Resource profile to use (dev or prod)
104+
required: false
105+
type: string
106+
default: "prod"
107+
create_static_ips:
108+
description: Whether to create static IPs as part of the eth devnet for the execution and beacon nodes
109+
required: false
110+
type: string
111+
default: "false"
112+
run_terraform_destroy:
113+
description: Whether to run the terraform destroy
114+
required: false
115+
type: string
116+
default: "false"
117+
118+
jobs:
119+
deploy_eth_devnet:
120+
runs-on: ubuntu-latest
121+
env:
122+
TF_STATE_BUCKET: aztec-terraform
123+
REGION: us-west1-a
124+
# Common Terraform variables as environment variables
125+
TF_VAR_NAMESPACE: ${{ inputs.namespace || 'eth-devnet' }}
126+
TF_VAR_CHAIN_ID: ${{ inputs.chain_id || 1337 }}
127+
TF_VAR_BLOCK_TIME: ${{ inputs.block_time || 12 }}
128+
TF_VAR_GAS_LIMIT: ${{ inputs.gas_limit || '32000000' }}
129+
TF_VAR_MNEMONIC_SECRET_NAME: eth-devnet-genesis-mnemonic
130+
TF_VAR_PREFUNDED_MNEMONIC_INDICES: "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1000,1001,1002,1003"
131+
TF_VAR_RESOURCE_PROFILE: ${{ inputs.resource_profile || 'prod' }}
132+
133+
steps:
134+
- name: debug inputs
135+
run: |
136+
echo "cluster: ${{ inputs.cluster }}"
137+
echo "namespace: ${{ inputs.namespace }}"
138+
echo "ref: ${{ inputs.ref }}"
139+
echo "chain_id: ${{ inputs.chain_id }}"
140+
echo "block_time: ${{ inputs.block_time }}"
141+
echo "gas_limit: ${{ inputs.gas_limit }}"
142+
echo "resource_profile: ${{ inputs.resource_profile }}"
143+
echo "create_static_ips: ${{ inputs.create_static_ips }}"
144+
echo "run_terraform_destroy: ${{ inputs.run_terraform_destroy }}"
145+
146+
- name: Check if directory exists
147+
id: check_dir
148+
run: |
149+
if [ -d ".git" ]; then
150+
echo "exists=true" >> $GITHUB_OUTPUT
151+
else
152+
echo "exists=false" >> $GITHUB_OUTPUT
153+
fi
154+
155+
# if running with `act`, skip the checkout since the code is mounted in
156+
- name: Checkout code
157+
if: ${{ steps.check_dir.outputs.exists != 'true' }}
158+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
159+
with:
160+
ref: ${{ inputs.ref || github.ref }}
161+
162+
- name: Authenticate to Google Cloud
163+
uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f
164+
with:
165+
credentials_json: ${{ secrets.GCP_SA_KEY }}
166+
167+
- name: Set up Cloud SDK
168+
uses: google-github-actions/setup-gcloud@6189d56e4096ee891640bb02ac264be376592d6a
169+
170+
- name: Install GKE Auth Plugin
171+
run: |
172+
gcloud components install gke-gcloud-auth-plugin --quiet
173+
174+
- name: Configure kubectl with GKE cluster
175+
if: ${{ inputs.cluster != 'kind' }}
176+
run: |
177+
gcloud container clusters get-credentials ${{ inputs.cluster }} --region ${{ env.REGION }}
178+
179+
- name: Configure kubectl with kind cluster
180+
if: ${{ inputs.cluster == 'kind' }}
181+
run: |
182+
# fail if kubeconfig is not provided
183+
if [ -z "${{ secrets.KUBECONFIG_B64 }}" ]; then
184+
echo "KUBECONFIG_B64 is not set"
185+
exit 1
186+
fi
187+
mkdir -p $HOME/.kube
188+
echo "${{ secrets.KUBECONFIG_B64 }}" | base64 -d > $HOME/.kube/config
189+
kubectl config use-context kind-kind
190+
191+
- name: Set up Terraform variables
192+
id: setup_vars
193+
run: |
194+
# Set CREATE_STATIC_IPS based on cluster type
195+
# Note: Terraform boolean values must be "true" or "false" (lowercase, unquoted)
196+
if [ "${{ inputs.cluster }}" == "kind" ]; then
197+
CREATE_STATIC_IPS=false
198+
else
199+
# Convert string "true"/"false" to boolean for Terraform
200+
if [ "${{ inputs.create_static_ips }}" == "true" ]; then
201+
CREATE_STATIC_IPS=true
202+
else
203+
CREATE_STATIC_IPS=false
204+
fi
205+
fi
206+
207+
# Get kubectl context
208+
CLUSTER_CONTEXT=$(kubectl config current-context)
209+
210+
# Export all as TF_VAR for Terraform
211+
echo "TF_VAR_CREATE_STATIC_IPS=${CREATE_STATIC_IPS}" >> $GITHUB_ENV
212+
echo "TF_VAR_K8S_CLUSTER_CONTEXT=${CLUSTER_CONTEXT}" >> $GITHUB_ENV
213+
214+
- name: Terraform Init
215+
working-directory: ./spartan/terraform/deploy-eth-devnet
216+
run: |
217+
# Clean up any previous backend overrides
218+
rm -f backend_override.tf
219+
220+
if [ "${{ inputs.cluster }}" == "kind" ]; then
221+
# For kind, use local backend with explicit path
222+
cat > backend_override.tf << EOF
223+
terraform {
224+
backend "local" {
225+
path = "state/${{ inputs.cluster }}/${{ inputs.namespace }}/terraform.tfstate"
226+
}
227+
}
228+
EOF
229+
else
230+
# For GKE, use GCS backend with explicit path
231+
cat > backend_override.tf << EOF
232+
terraform {
233+
backend "gcs" {
234+
bucket = "${{ env.TF_STATE_BUCKET }}"
235+
prefix = "deploy-eth-devnet/${{ env.REGION }}/${{ inputs.cluster }}/${{ inputs.namespace }}/terraform.tfstate"
236+
}
237+
}
238+
EOF
239+
fi
240+
241+
terraform init -reconfigure
242+
243+
- name: Terraform Destroy
244+
working-directory: ./spartan/terraform/deploy-eth-devnet
245+
if: ${{ inputs.run_terraform_destroy == 'true' }}
246+
# Destroy fails if the resources are already destroyed, so we continue on error
247+
continue-on-error: true
248+
run: |
249+
# All variables are now set as TF_VAR_ environment variables
250+
terraform destroy -auto-approve
251+
252+
- name: Terraform Plan
253+
working-directory: ./spartan/terraform/deploy-eth-devnet
254+
run: |
255+
# All variables are now set as TF_VAR_ environment variables
256+
terraform plan -out=tfplan
257+
258+
- name: Terraform Apply
259+
working-directory: ./spartan/terraform/deploy-eth-devnet
260+
run: |
261+
terraform apply tfplan

.github/workflows/publish-bb-mac.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ jobs:
4343
optional: false
4444
- label: amd64-darwin-starknet
4545
runner: macos-13
46-
cmake_flags: "-DCMAKE_CXX_FLAGS=\"-DSTARKNET_GARAGA_FLAVORS=1\""
46+
cmake_flags: '-DCMAKE_CXX_FLAGS="-DSTARKNET_GARAGA_FLAVORS=1"'
4747
optional: true
4848
- label: arm64-darwin-starknet
4949
runner: macos-14
50-
cmake_flags: "-DCMAKE_CXX_FLAGS=\"-DSTARKNET_GARAGA_FLAVORS=1\""
50+
cmake_flags: '-DCMAKE_CXX_FLAGS="-DSTARKNET_GARAGA_FLAVORS=1"'
5151
optional: true
5252
steps:
5353
- name: Checkout
@@ -69,22 +69,22 @@ jobs:
6969
7070
- name: Compile Barretenberg
7171
working-directory: barretenberg/cpp
72-
continue-on-error: ${{ matrix.optional }}
72+
continue-on-error: ${{ matrix.optional }}
7373
run: |
7474
cmake --preset homebrew ${{ matrix.cmake_flags }}
7575
cmake --build --preset homebrew --target bb
7676
7777
- name: Package barretenberg artifact (${{ matrix.label }})
7878
working-directory: barretenberg/cpp/build/bin
79-
continue-on-error: ${{ matrix.optional }}
79+
continue-on-error: ${{ matrix.optional }}
8080
run: |
8181
mkdir dist
8282
cp ./bb ./dist/bb
8383
7z a -ttar -so -an ./dist/* | 7z a -si ./barretenberg-${{ matrix.label }}.tar.gz
8484
8585
- name: Upload artifact (${{ matrix.label }})
8686
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
87-
continue-on-error: ${{ matrix.optional }}
87+
continue-on-error: ${{ matrix.optional }}
8888
with:
8989
name: barretenberg-${{ matrix.label }}.tar.gz
9090
path: ./barretenberg/cpp/build/bin/barretenberg-${{ matrix.label }}.tar.gz

spartan/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.tgz
22
scripts/logs
33
scripts/LICENSE
4+
tfplan
5+
*_override.tf

spartan/scripts/cleanup_helm.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Script to manually clean up stuck Helm releases
4+
# Usage: ./cleanup_helm.sh [release-name] [namespace]
5+
6+
RELEASE_NAME=${1:-"eth-devnet"}
7+
NAMESPACE=${2:-"eth-devnet"}
8+
9+
echo "=== Cleaning up stuck Helm release: $RELEASE_NAME in namespace: $NAMESPACE ==="
10+
11+
# Check current state
12+
echo "Current Helm releases:"
13+
helm list -n $NAMESPACE -a
14+
15+
echo "Current Helm secrets:"
16+
kubectl get secrets -n $NAMESPACE -l owner=helm
17+
18+
# Look for pending operations
19+
echo "Checking for pending operations..."
20+
kubectl get secrets -n $NAMESPACE -l owner=helm -o json | jq -r '.items[] | select(.metadata.labels.status == "pending-install" or .metadata.labels.status == "pending-upgrade" or .metadata.labels.status == "pending-rollback") | "\(.metadata.name) - \(.metadata.labels.status)"'
21+
22+
# Force cleanup
23+
echo "Force deleting pending Helm secrets..."
24+
kubectl delete secrets -n $NAMESPACE -l owner=helm,status=pending-install --ignore-not-found=true
25+
kubectl delete secrets -n $NAMESPACE -l owner=helm,status=pending-upgrade --ignore-not-found=true
26+
kubectl delete secrets -n $NAMESPACE -l owner=helm,status=pending-rollback --ignore-not-found=true
27+
28+
# Try to uninstall
29+
echo "Attempting to uninstall release..."
30+
helm uninstall $RELEASE_NAME -n $NAMESPACE --wait --timeout=60s || echo "Uninstall failed or no release found"
31+
32+
# Nuclear option: delete all Helm secrets for this release
33+
echo "Force deleting all Helm secrets for release $RELEASE_NAME..."
34+
kubectl delete secrets -n $NAMESPACE -l name=$RELEASE_NAME,owner=helm --ignore-not-found=true
35+
36+
# Clean up all resources in namespace
37+
echo "Cleaning up all resources in namespace..."
38+
kubectl delete all --all -n $NAMESPACE --ignore-not-found=true
39+
40+
echo "=== Cleanup complete! ==="
41+
echo "You can now retry your deployment."

0 commit comments

Comments
 (0)