|
| 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 |
0 commit comments