diff --git a/.circleci/config.yml b/.circleci/config.yml index 6a9bfbae5b9..802998ad110 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -948,7 +948,21 @@ jobs: name: "Deploy mainnet fork" command: | should_deploy || exit 0 - deploy_ecr mainnet-fork + deploy mainnet-fork + + deploy-contracts: + machine: + image: ubuntu-2204:2023.07.2 + resource_class: medium + steps: + - *checkout + - *setup_env + - run: + name: "Deploy L1 contracts to mainnet fork" + working_directory: l1-contracts + command: | + should_deploy || exit 0 + ./scripts/ci_deploy_contracts.sh deploy-npm: machine: @@ -977,6 +991,29 @@ jobs: deploy_dockerhub noir x86_64,arm64 deploy_dockerhub aztec-sandbox x86_64,arm64 deploy_dockerhub cli x86_64,arm64 + deploy_dockerhub faucet x86_64,arm64 + deploy_dockerhub mainnet-fork x86_64,arm64 + dpeloy_dockerhub l1-contracts x86_64,arm64 + + deploy-devnet: + machine: + image: ubuntu-2204:2023.07.2 + resource_class: medium + steps: + - *checkout + - *setup_env + - run: + name: "Deploy devnet to AWS" + command: | + should_deploy 0 || exit 0 + export TF_VAR_FAUCET_PRIVATE_KEY=$FAUCET_PRIVATE_KEY + export TF_VAR_BOOTNODE_1_PEER_ID=$BOOTNODE_1_PEER_ID + export TF_VAR_BOOTNODE_2_PEER_ID=$BOOTNODE_2_PEER_ID + export TF_VAR_BOOTNODE_1_PRIVATE_KEY=$BOOTNODE_1_PRIVATE_KEY + export TF_VAR_BOOTNODE_2_PRIVATE_KEY=$BOOTNODE_2_PRIVATE_KEY + deploy p2p-bootstrap + deploy aztec-node + deploy aztec-faucet # Repeatable config for defining the workflow below. defaults: &defaults @@ -1203,4 +1240,16 @@ workflows: # Production deployment - deploy-dockerhub: *defaults_deploy - deploy-npm: *defaults_deploy - - deploy-mainnet-fork: *defaults_deploy + - deploy-mainnet-fork: + requires: + - deploy-dockerhub + <<: *defaults_deploy + - deploy-contracts: + requires: + - deploy-mainnet-fork + <<: *defaults_deploy + - deploy-devnet: + requires: + - deploy-contracts + <<: *defaults_deploy + diff --git a/build-system/scripts/deploy b/build-system/scripts/deploy index 06410f5f031..08ef24ac2e8 100755 --- a/build-system/scripts/deploy +++ b/build-system/scripts/deploy @@ -19,7 +19,7 @@ if check_rebuild cache-$CONTENT_HASH-$DEPLOY_TAG-deployed $REPOSITORY; then exit 0 fi -deploy_terraform $REPOSITORY ./terraform/$DEPLOY_ENV "$TO_TAINT" +deploy_terraform $REPOSITORY ./terraform/ "$TO_TAINT" # Restart services. for SERVICE in $SERVICES; do diff --git a/build-system/scripts/deploy_dockerhub b/build-system/scripts/deploy_dockerhub index 4009f453d48..ac99bbe4f1a 100755 --- a/build-system/scripts/deploy_dockerhub +++ b/build-system/scripts/deploy_dockerhub @@ -20,7 +20,17 @@ function docker_or_dryrun { echo "Repo: $REPOSITORY" echo "Arch List: $ARCH_LIST" -VERSION_TAG=$(extract_tag_version $REPOSITORY true) +VERSION_TAG=$(extract_tag_version $REPOSITORY false) + +# if no version tag, check if we're on `master` branch +if [[ -z "$VERSION_TAG" ]]; then + if [[ "$BRANCH" != "master" ]]; then + echo "No version tag found. Exiting" >&2 + exit 1 + fi + # if we're on master, use the DEPLOY_TAG as the version tag + VERSION_TAG=$DEPLOY_TAG +fi MANIFEST_DEPLOY_URI=$DOCKERHUB_ACCOUNT/$REPOSITORY:$VERSION_TAG MANIFEST_DIST_URI=$DOCKERHUB_ACCOUNT/$REPOSITORY:$DIST_TAG @@ -42,12 +52,17 @@ for ARCH in $ARCH_LIST; do echo "Adding image $IMAGE_DEPLOY_URI to manifest list $MANIFEST_DEPLOY_URI..." docker_or_dryrun manifest create $MANIFEST_DEPLOY_URI --amend $IMAGE_DEPLOY_URI - echo "Adding image $IMAGE_DEPLOY_URI to manifest list $MANIFEST_DIST_URI" - docker_or_dryrun manifest create $MANIFEST_DIST_URI --amend $IMAGE_DEPLOY_URI + # Add latest manifest if we're making a release. + if [[ "$VERSION_TAG" != $DEPLOY_TAG ]]; then + echo "Adding image $IMAGE_DEPLOY_URI to manifest list $MANIFEST_DIST_URI" + docker_or_dryrun manifest create $MANIFEST_DIST_URI --amend $IMAGE_DEPLOY_URI + fi done -echo "Tagging $MANIFEST_DEPLOY_URI as $VERSION_TAG..." docker_or_dryrun manifest push --purge $MANIFEST_DEPLOY_URI -# Publish version as latest. -echo "Tagging $MANIFEST_DEPLOY_URI as $DIST_TAG..." -docker_or_dryrun manifest push --purge $MANIFEST_DIST_URI + +# Retag version as latest if we're making a release. +if [[ "$VERSION_TAG" != "$DEPLOY_TAG" ]]; then + echo "Tagging $MANIFEST_DEPLOY_URI as $DIST_TAG..." + docker_or_dryrun manifest push --purge $MANIFEST_DIST_URI +fi diff --git a/build-system/scripts/deploy_terraform b/build-system/scripts/deploy_terraform index 6d7f6ef81bb..3759cc52a0a 100755 --- a/build-system/scripts/deploy_terraform +++ b/build-system/scripts/deploy_terraform @@ -25,6 +25,10 @@ echo "Deploying terraform found at $PWD..." # Always want to export the DEPLOY_TAG variable to terraform. It's used to easily scope releases. export TF_VAR_DEPLOY_TAG=$DEPLOY_TAG export TF_VAR_COMMIT_HASH=$COMMIT_HASH +export TF_VAR_DOCKERHUB_ACCOUNT=$DOCKERHUB_ACCOUNT +export TF_VAR_FORK_MNEMONIC=$FORK_MNEMONIC +export TF_VAR_INFURA_API_KEY=$INFURA_API_KEY +export TF_VAR_API_KEY=$FORK_API_KEY # If given a repository name, use it to construct and set/override the backend key. # Otherwise use the key as specified in the terraform. diff --git a/build-system/scripts/ensure_terraform b/build-system/scripts/ensure_terraform index f2e33c5445d..d7444aa4e4c 100755 --- a/build-system/scripts/ensure_terraform +++ b/build-system/scripts/ensure_terraform @@ -6,7 +6,7 @@ set -eu [ ! -f /usr/local/bin/terraform ] || exit 0 cd $HOME -TERRAFORM_VERSION=0.13.3 +TERRAFORM_VERSION=1.5.2 curl -sSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip sudo apt install -y unzip unzip terraform.zip diff --git a/build-system/scripts/should_deploy b/build-system/scripts/should_deploy index aac1504ab33..b5f198af06e 100755 --- a/build-system/scripts/should_deploy +++ b/build-system/scripts/should_deploy @@ -1,7 +1,15 @@ #!/bin/bash -# Retuns success if we are expected to do a deploy. -# At present this is only if we have a commit tag. -# Once we are doing master deployments to devnet, we'll want to check if BRANCH is master. +# Returns success if we are expected to do a deployment. +# This is if we have a commit tag (release) or if we're on `master` branch (devnet deployment). + set -eu -[ -n "$COMMIT_TAG" ] \ No newline at end of file +# This is when we only want to deploy on master, not release with new COMMIT_TAG. +# Specifically for deploying devnet. +RELEASE=${1:-1} + +if [ -n "$COMMIT_TAG" ] && [ "$RELEASE" != "0" ] || [ "$BRANCH" = "master" ]; then + exit 0 +else + exit 1 +fi diff --git a/iac/mainnet-fork/scripts/wait_for_fork b/iac/mainnet-fork/scripts/wait_for_fork index 4d990e30f88..326582c25af 100755 --- a/iac/mainnet-fork/scripts/wait_for_fork +++ b/iac/mainnet-fork/scripts/wait_for_fork @@ -6,7 +6,7 @@ set -e # This script waits on a healthy status from the fork - a valid response to the chainid request # We retry every 20 seconds, and wait for a total of 5 minutes (15 times) -export ETHEREUM_HOST="https://aztec-mainnet-fork.aztec.network:8545/$FORK_API_KEY" +export ETHEREUM_HOST="https://aztec-mainnet-fork.aztec.network:8545/$API_KEY" curl -H "Content-Type: application/json" -X POST --data '{"method":"eth_chainId","params":[],"id":33,"jsonrpc":"2.0"}' \ --connect-timeout 30 \ diff --git a/iac/mainnet-fork/terraform/main.tf b/iac/mainnet-fork/terraform/main.tf index 8cec1f4a18b..18bc1eb3ab2 100644 --- a/iac/mainnet-fork/terraform/main.tf +++ b/iac/mainnet-fork/terraform/main.tf @@ -1,7 +1,6 @@ terraform { backend "s3" { bucket = "aztec-terraform" - key = "aztec-network/mainnet-fork" region = "eu-west-2" } required_providers { @@ -50,7 +49,7 @@ provider "aws" { } resource "aws_service_discovery_service" "aztec_mainnet_fork" { - name = "aztec-network-mainnet-fork" + name = "${var.DEPLOY_TAG}-mainnet-fork" health_check_custom_config { failure_threshold = 1 @@ -75,10 +74,10 @@ resource "aws_service_discovery_service" "aztec_mainnet_fork" { # EFS filesystem for mainnet fork resource "aws_efs_file_system" "aztec_mainnet_fork_data_store" { - creation_token = "aztec-network-mainnet-fork-data" + creation_token = "${var.DEPLOY_TAG}-mainnet-fork-data" tags = { - Name = "aztec-network-mainnet-fork-data" + Name = "${var.DEPLOY_TAG}-mainnet-fork-data" } lifecycle_policy { @@ -100,7 +99,7 @@ resource "aws_efs_mount_target" "aztec_fork_private_az2" { # Define deployment task and service resource "aws_ecs_task_definition" "aztec_mainnet_fork" { - family = "aztec-network-mainnet-fork" + family = "${var.DEPLOY_TAG}-mainnet-fork" requires_compatibilities = ["FARGATE"] network_mode = "awsvpc" cpu = "2048" @@ -117,13 +116,13 @@ resource "aws_ecs_task_definition" "aztec_mainnet_fork" { container_definitions = <serve/contract_addresses.json + +cat serve/contract_addresses.json + +echo "Contract addresses have been written to serve/contract_addresses.json" diff --git a/l1-contracts/terraform/main.tf b/l1-contracts/terraform/main.tf new file mode 100644 index 00000000000..89cb2c801e5 --- /dev/null +++ b/l1-contracts/terraform/main.tf @@ -0,0 +1,57 @@ +terraform { + backend "s3" { + bucket = "aztec-terraform" + region = "eu-west-2" + } + required_providers { + aws = { + source = "hashicorp/aws" + version = "3.74.2" + } + } +} + +variable "ROLLUP_CONTRACT_ADDRESS" { + type = string + default = "" +} + +output "rollup_contract_address" { + value = var.ROLLUP_CONTRACT_ADDRESS +} + +variable "REGISTRY_CONTRACT_ADDRESS" { + type = string + default = "" +} + +output "registry_contract_address" { + value = var.REGISTRY_CONTRACT_ADDRESS +} + +variable "INBOX_CONTRACT_ADDRESS" { + type = string + default = "" +} + +output "inbox_contract_address" { + value = var.INBOX_CONTRACT_ADDRESS +} + +variable "OUTBOX_CONTRACT_ADDRESS" { + type = string + default = "" +} + +output "outbox_contract_address" { + value = var.OUTBOX_CONTRACT_ADDRESS +} + +variable "CONTRACT_DEPLOYMENT_EMITTER_ADDRESS" { + type = string + default = "" +} + +output "contract_deployment_emitter_address" { + value = var.CONTRACT_DEPLOYMENT_EMITTER_ADDRESS +} diff --git a/yarn-project/aztec-faucet/terraform/main.tf b/yarn-project/aztec-faucet/terraform/main.tf index 8a1f901fd09..bfbb82a982b 100644 --- a/yarn-project/aztec-faucet/terraform/main.tf +++ b/yarn-project/aztec-faucet/terraform/main.tf @@ -41,7 +41,7 @@ resource "aws_cloudwatch_log_group" "aztec-faucet" { } resource "aws_service_discovery_service" "aztec-faucet" { - name = "${var.DEPLOY_TAG}-aztec-faucet" + name = "${var.DEPLOY_TAG}-faucet" health_check_custom_config { failure_threshold = 1 @@ -72,7 +72,7 @@ resource "aws_service_discovery_service" "aztec-faucet" { # Define task definition and service. resource "aws_ecs_task_definition" "aztec-faucet" { - family = "${var.DEPLOY_TAG}-aztec-faucet" + family = "${var.DEPLOY_TAG}-faucet" requires_compatibilities = ["FARGATE"] network_mode = "awsvpc" cpu = "2048" @@ -83,8 +83,8 @@ resource "aws_ecs_task_definition" "aztec-faucet" { container_definitions = <" && exit 1 + +serviceId="--service-id=$1" + +echo "Draining servicediscovery instances from $1 ..." +ids="$(aws servicediscovery list-instances $serviceId --query 'Instances[].Id' --output text | tr '\t' ' ')" + +found= +for id in $ids; do + if [ -n "$id" ]; then + echo "Deregistering $1 / $id ..." + aws servicediscovery deregister-instance $serviceId --instance-id "$id" + found=1 + fi +done + +# Yes, I'm being lazy here... +[ -n "$found" ] && sleep 5 || true \ No newline at end of file diff --git a/yarn-project/aztec-node/terraform/variables.tf b/yarn-project/aztec-node/terraform/variables.tf index d80ae23529d..f8c10fefd2c 100644 --- a/yarn-project/aztec-node/terraform/variables.tf +++ b/yarn-project/aztec-node/terraform/variables.tf @@ -31,15 +31,13 @@ variable "SEQ_2_PUBLISHER_PRIVATE_KEY" { } variable "CHAIN_ID" { - type = string + type = string + default = 31337 } -variable "BOOTNODE_1_LISTEN_PORT" { - type = string -} - -variable "BOOTNODE_2_LISTEN_PORT" { - type = string +variable "BOOTNODE_LISTEN_PORT" { + type = number + default = 40500 } variable "BOOTNODE_1_PEER_ID" { @@ -50,12 +48,9 @@ variable "BOOTNODE_2_PEER_ID" { type = string } -variable "NODE_1_TCP_PORT" { - type = string -} - -variable "NODE_2_TCP_PORT" { - type = string +variable "NODE_TCP_PORT" { + type = number + default = 40400 } variable "NODE_1_PRIVATE_KEY" { @@ -66,22 +61,26 @@ variable "NODE_2_PRIVATE_KEY" { type = string } -variable "ECR_URL" { +variable "DOCKERHUB_ACCOUNT" { type = string } variable "SEQ_MAX_TX_PER_BLOCK" { - type = string + type = string + default = 64 } variable "SEQ_MIN_TX_PER_BLOCK" { - type = string + type = string + default = 1 } variable "P2P_MIN_PEERS" { - type = string + type = string + default = 50 } variable "P2P_MAX_PEERS" { - type = string + type = string + default = 100 } diff --git a/yarn-project/ethereum/src/testnet.ts b/yarn-project/ethereum/src/testnet.ts index b260356df75..4c3694f9361 100644 --- a/yarn-project/ethereum/src/testnet.ts +++ b/yarn-project/ethereum/src/testnet.ts @@ -2,6 +2,8 @@ import { Chain } from 'viem'; import { EthereumChain } from './ethereum_chain.js'; +const { DEPLOY_TAG = 'aztec-dev' } = process.env; + export const createTestnetChain = (apiKey: string) => { const chain: Chain = { id: 677868, @@ -14,10 +16,10 @@ export const createTestnetChain = (apiKey: string) => { }, rpcUrls: { default: { - http: [`https://aztec-connect-testnet-eth-host.aztec.network:8545/${apiKey}`], + http: [`https://${DEPLOY_TAG}-mainnet-fork.aztec.network:8545/${apiKey}`], }, public: { - http: [`https://aztec-connect-testnet-eth-host.aztec.network:8545/${apiKey}`], + http: [`https://${DEPLOY_TAG}-mainnet-fork.aztec.network:8545/${apiKey}`], }, }, }; diff --git a/yarn-project/p2p-bootstrap/terraform/main.tf b/yarn-project/p2p-bootstrap/terraform/main.tf index a5b2f88ffb4..311c9b9b241 100644 --- a/yarn-project/p2p-bootstrap/terraform/main.tf +++ b/yarn-project/p2p-bootstrap/terraform/main.tf @@ -1,6 +1,6 @@ # Terraform to setup a prototype network of Aztec Boot Nodes in AWS # It sets up 2 boot nodes with different ports/keys etc. -# Some duplication across the 2 defined services, could possibly +# Some duplication across the 2 defined services, could possibly # be refactored to use modules as and when we build out infrastructure for real terraform { @@ -48,14 +48,20 @@ data "terraform_remote_state" "aztec-network_iac" { } } +locals { + bootnode_keys = [var.BOOTNODE_1_PRIVATE_KEY, var.BOOTNODE_2_PRIVATE_KEY] + bootnode_count = length(local.bootnode_keys) +} + -resource "aws_cloudwatch_log_group" "aztec-bootstrap-1-log-group" { - name = "/fargate/service/${var.DEPLOY_TAG}/aztec-bootstrap-1" +resource "aws_cloudwatch_log_group" "aztec-bootstrap-log-group" { + count = local.bootnode_count + name = "/fargate/service/${var.DEPLOY_TAG}/aztec-bootstrap-${count.index + 1}" retention_in_days = 14 } -resource "aws_service_discovery_service" "aztec-bootstrap-1" { - name = "${var.DEPLOY_TAG}-aztec-bootstrap-1" +resource "aws_service_discovery_service" "aztec-bootstrap" { + name = "${var.DEPLOY_TAG}-aztec-bootstrap-${count.index + 1}" health_check_custom_config { failure_threshold = 1 @@ -80,12 +86,13 @@ resource "aws_service_discovery_service" "aztec-bootstrap-1" { # Terraform just fails if this resource changes and you have registered instances. provisioner "local-exec" { when = destroy - command = "${path.module}/../servicediscovery-drain.sh ${self.id}" + command = "${path.module}/servicediscovery-drain.sh ${self.id}" } } -resource "aws_ecs_task_definition" "aztec-bootstrap-1" { - family = "${var.DEPLOY_TAG}-aztec-bootstrap-1" +resource "aws_ecs_task_definition" "aztec-bootstrap" { + count = local.bootnode_count + family = "${var.DEPLOY_TAG}-aztec-bootstrap-${count.index + 1}" requires_compatibilities = ["FARGATE"] network_mode = "awsvpc" cpu = "2048" @@ -96,14 +103,14 @@ resource "aws_ecs_task_definition" "aztec-bootstrap-1" { container_definitions = <" && exit 1 + +serviceId="--service-id=$1" + +echo "Draining servicediscovery instances from $1 ..." +ids="$(aws servicediscovery list-instances $serviceId --query 'Instances[].Id' --output text | tr '\t' ' ')" + +found= +for id in $ids; do + if [ -n "$id" ]; then + echo "Deregistering $1 / $id ..." + aws servicediscovery deregister-instance $serviceId --instance-id "$id" + found=1 + fi +done + +# Yes, I'm being lazy here... +[ -n "$found" ] && sleep 5 || true \ No newline at end of file diff --git a/yarn-project/p2p-bootstrap/terraform/variables.tf b/yarn-project/p2p-bootstrap/terraform/variables.tf index aafaf04abe0..aead56bdd84 100644 --- a/yarn-project/p2p-bootstrap/terraform/variables.tf +++ b/yarn-project/p2p-bootstrap/terraform/variables.tf @@ -2,30 +2,29 @@ variable "DEPLOY_TAG" { type = string } -variable "BOOTNODE_1_LISTEN_PORT" { - type = string +variable "BOOTNODE_LISTEN_PORT" { + type = string + default = 40500 } variable "BOOTNODE_1_PRIVATE_KEY" { type = string } -variable "BOOTNODE_2_LISTEN_PORT" { - type = string -} - variable "BOOTNODE_2_PRIVATE_KEY" { type = string } -variable "ECR_URL" { - type = string -} - variable "P2P_MIN_PEERS" { - type = string + type = string + default = 50 } variable "P2P_MAX_PEERS" { + type = string + default = 100 +} + +variable "DOCKERHUB_ACCOUNT" { type = string }