Skip to content

Commit cc515da

Browse files
authored
fix(ci): redeploy triggers (AztecProtocol#3677)
- use `deploy_service` to restart AWS services - check if l1-contracts were redeployed to reset node file systems - redeploy l1-contracts
1 parent 7c8814e commit cc515da

File tree

12 files changed

+148
-48
lines changed

12 files changed

+148
-48
lines changed

.circleci/config.yml

+24-8
Original file line numberDiff line numberDiff line change
@@ -945,27 +945,43 @@ jobs:
945945
name: "Deploy mainnet fork"
946946
command: |
947947
should_deploy || exit 0
948-
deploy mainnet-fork
948+
deploy_terraform_services iac/mainnet-fork
949949
- run:
950950
name: "Deploy L1 contracts to mainnet fork"
951951
working_directory: l1-contracts
952952
command: |
953953
should_deploy || exit 0
954954
./scripts/ci_deploy_contracts.sh
955955
- run:
956-
name: "Deploy devnet to AWS"
956+
name: "Deploy P2P bootstrap servers to AWS"
957957
command: |
958958
should_deploy 0 || exit 0
959-
export TF_VAR_FAUCET_PRIVATE_KEY=$FAUCET_PRIVATE_KEY
960-
export TF_VAR_BOOTNODE_1_PEER_ID=$BOOTNODE_1_PEER_ID
961-
export TF_VAR_BOOTNODE_2_PEER_ID=$BOOTNODE_2_PEER_ID
959+
# Export variables for Terraform.
962960
export TF_VAR_BOOTNODE_1_PRIVATE_KEY=$BOOTNODE_1_PRIVATE_KEY
963961
export TF_VAR_BOOTNODE_2_PRIVATE_KEY=$BOOTNODE_2_PRIVATE_KEY
962+
deploy_terraform_services yarn-project/p2p-bootstrap aztec-sandbox
963+
- run:
964+
name: "Deploy Aztec Nodes to AWS"
965+
command: |
966+
should_deploy 0 || exit 0
967+
export TF_VAR_BOOTNODE_1_PEER_ID=$BOOTNODE_1_PEER_ID
968+
export TF_VAR_BOOTNODE_2_PEER_ID=$BOOTNODE_2_PEER_ID
964969
export TF_VAR_SEQ_1_PUBLISHER_PRIVATE_KEY=$SEQ_1_PUBLISHER_PRIVATE_KEY
965970
export TF_VAR_SEQ_2_PUBLISHER_PRIVATE_KEY=$SEQ_2_PUBLISHER_PRIVATE_KEY
966-
deploy_terraform p2p-bootstrap yarn-project/p2p-bootstrap/terraform
967-
deploy_terraform aztec-node yarn-project/aztec-node/terraform
968-
deploy_terraform aztec-faucet yarn-project/aztec-faucet/terraform
971+
export TF_VAR_NODE_1_PRIVATE_KEY=$NODE_1_PRIVATE_KEY
972+
export TF_VAR_NODE_2_PRIVATE_KEY=$NODE_2_PRIVATE_KEY
973+
# Check if l1-contracts have changed
974+
if $CONTRACTS_DEPLOYED -eq 1; then
975+
deploy_terraform_services yarn-project/aztec-node aztec-sandbox aztec-node aws_efs_file_system.node_data_store
976+
else
977+
deploy_terraform_services yarn-project/aztec-node aztec-sandbox
978+
fi
979+
- run:
980+
name: "Deploy Aztec Faucet to AWS"
981+
command: |
982+
should_deploy 0 || exit 0
983+
export TF_VAR_FAUCET_PRIVATE_KEY=$FAUCET_PRIVATE_KEY
984+
deploy_terraform_services yarn-project/aztec-faucet aztec-sandbox
969985
970986
# Repeatable config for defining the workflow below.
971987
defaults: &defaults

build-system/scripts/deploy_service

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,24 @@
22
[ -n "${BUILD_SYSTEM_DEBUG:-}" ] && set -x # conditionally trace
33
set -eu
44

5-
# Redeploy service with latest image.
5+
# Redeploy services with the latest image that match $DEPLOY_TAG followed by $SERVICE_NAME.
66
SERVICE_NAME=$1
7-
if aws ecs list-services --region $ECR_DEPLOY_REGION --cluster setup | grep "/$SERVICE_NAME\"" > /dev/null; then
8-
aws ecs update-service --region $ECR_DEPLOY_REGION --cluster setup --service $SERVICE_NAME --force-new-deployment
9-
fi
7+
PATTERN="$DEPLOY_TAG.*$SERVICE_NAME.*"
8+
9+
# Fetch list of services
10+
SERVICES=$(aws ecs list-services --region $ECR_DEPLOY_REGION --cluster setup | grep -Eo "arn:aws:ecs:[^:]+:[^:]+:service/[^/]+/$PATTERN" || true)
11+
12+
echo "Services to redeploy:"
13+
echo "$SERVICES"
14+
15+
# Loop through and update each matching service.
16+
for SERVICE_ARN in $SERVICES; do
17+
# Extract the actual service name from ARN
18+
ACTUAL_SERVICE_NAME=$(echo "$SERVICE_ARN" | awk -F/ '{print $NF}')
19+
20+
if [ "$DRY_DEPLOY" -eq 1 ]; then
21+
echo "DRY_DEPLOY: aws ecs update-service --region $ECR_DEPLOY_REGION --cluster setup --service $ACTUAL_SERVICE_NAME --force-new-deployment"
22+
else
23+
aws ecs update-service --region $ECR_DEPLOY_REGION --cluster setup --service $ACTUAL_SERVICE_NAME --force-new-deployment
24+
fi
25+
done

build-system/scripts/deploy_terraform

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ for RESOURCE in $TO_TAINT; do
4444
done
4545

4646
if [ "$DRY_DEPLOY" -eq 1 ]; then
47-
terraform plan -input=false -auto-approve
47+
terraform plan -input=false
4848
else
4949
terraform apply -input=false -auto-approve
5050
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
[ -n "${BUILD_SYSTEM_DEBUG:-}" ] && set -x # conditionally trace
3+
set -eu
4+
5+
# This script deploys a terraform project and restarts related services.
6+
7+
# The terraform project directory.
8+
PROJECT_DIR=$1
9+
# Extract project name fromm the directory, e.g. yarn-project/aztec-node -> aztec-node
10+
PROJECT_NAME=$(basename $PROJECT_DIR)
11+
12+
# The repository to check for changes. Defaults to the project name
13+
# but can be different for projects that e.g. use the sandbox image.
14+
CHECK_REBUILD_REPOSITORY=${2:-$PROJECT_NAME}
15+
16+
# The services to restart. Defaults to the project name but can be different.
17+
SERVICE_NAMES=${3:-$PROJECT_NAME}
18+
19+
# The terraform resources to taint. Defaults to none.
20+
TO_TAINT=${4:-}
21+
22+
cd $PROJECT_DIR
23+
24+
# Bail out if nothing changed.
25+
CONTENT_HASH=$(calculate_content_hash $CHECK_REBUILD_REPOSITORY)
26+
echo "Last successfully deployed commit: $CONTENT_HASH"
27+
if check_rebuild cache-$CONTENT_HASH-$DEPLOY_TAG-deployed $CHECK_REBUILD_REPOSITORY; then
28+
echo "No changes detected, skipping deployment."
29+
exit 0
30+
fi
31+
32+
deploy_terraform $PROJECT_NAME ./terraform/ "$TO_TAINT"
33+
34+
# Restart services.
35+
for SERVICE in $SERVICE_NAMES; do
36+
deploy_service $SERVICE
37+
done
38+
39+
# Tag the image as deployed.
40+
if [ "$DRY_DEPLOY" -eq 1 ]; then
41+
echo "DRY_DEPLOY: tag_remote_image $CHECK_REBUILD_REPOSITORY cache-$CONTENT_HASH cache-$CONTENT_HASH-$DEPLOY_TAG-deployed"
42+
else
43+
retry tag_remote_image $CHECK_REBUILD_REPOSITORY cache-$CONTENT_HASH cache-$CONTENT_HASH-$DEPLOY_TAG-deployed
44+
fi

build-system/scripts/setup_env

+6-4
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ echo "PULL_REQUEST=$PULL_REQUEST"
3434
# If the user has requested to perform a "dry deploy", we set the commit tag to fake version, and set DRY_DEPLOY to 1.
3535
if [[ "$COMMIT_MESSAGE" == *"[ci dry-deploy]"* ]]; then
3636
COMMIT_TAG=v999.999.999
37-
DRY_DEPLOY=1
37+
export DRY_DEPLOY=1
3838
fi
3939

4040
if should_deploy; then
4141
if [ -n "${COMMIT_TAG:-}" ]; then
4242
# Extract the deploy env from the commit tag, if it has one, e.g. testnet.
4343
# If we have one, we look something like v2.1.123-testnet.0. This is a "non production" release.
4444
if [[ "$COMMIT_TAG" == *"-"* ]]; then
45-
# Strips the trailing '.XX' from the end of the commit tag
45+
# Strips the trailing '.XX' from the end of the commit tag.
4646
TEMP=${COMMIT_TAG%.*}
47-
# Strips the 'vX.Y.ZZZ-' from the front of the commit tag, leaving the e.g. 'testnet'
47+
# Strips the 'vX.Y.ZZZ-' from the front of the commit tag, leaving the e.g. 'testnet'.
4848
DEPLOY_ENV=${TEMP##*-}
49-
else
49+
elif [ ! "$DRY_DEPLOY" -eq 1 ]; then
5050
DEPLOY_ENV=prod
51+
else
52+
DEPLOY_ENV=dev
5153
fi
5254
else
5355
# If we're on master, this is our devnet.

build-system/scripts/should_deploy

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Right now, that's only if we're master.
44
set -eu
55

6-
if [ "$BRANCH" == "master" ]; then
6+
if [ "$BRANCH" == "master" ] || [ "$DRY_DEPLOY" -eq 1 ]; then
77
exit 0
88
else
99
exit 1

build_manifest.yml

+12
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ aztec-faucet:
149149
dependencies:
150150
- yarn-project-prod
151151

152+
aztec-node:
153+
buildDir: yarn-project
154+
projectDir: yarn-project/aztec-node
155+
dependencies:
156+
- yarn-project-prod
157+
158+
p2p-bootstrap:
159+
buildDir: yarn-project
160+
projectDir: yarn-project/p2p-bootstrap
161+
dependencies:
162+
- yarn-project-prod
163+
152164
cli:
153165
buildDir: yarn-project
154166
projectDir: yarn-project/cli

l1-contracts/REDEPLOY

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Append value to force redeploy
2-
1
2+
3

l1-contracts/scripts/ci_deploy_contracts.sh

+14-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ echo "Last successfully published commit: $CONTENT_HASH"
1111
# Check if image hash has alredy been deployed.
1212
if check_rebuild "cache-$CONTENT_HASH-$DEPLOY_TAG-deployed" $REPOSITORY; then
1313
echo "No changes detected, no contract deploy necessary."
14+
# Set global variable for redeployment of contracts
15+
echo export CONTRACTS_DEPLOYED=0 >>$BASH_ENV
1416
exit 0
1517
fi
1618

@@ -31,8 +33,16 @@ for KEY in ROLLUP_CONTRACT_ADDRESS REGISTRY_CONTRACT_ADDRESS INBOX_CONTRACT_ADDR
3133
export TF_VAR_$KEY=$VALUE
3234
done
3335

34-
# Write TF state variables
35-
deploy_terraform l1-contracts ./terraform
36+
if [ -n "${DRY_DEPLOY:-}" ]; then
37+
echo "DRY_DEPLOY: deploy_terraform l1-contracts ./terraform"
38+
echo "DRY_DEPLOY: tag_remote_image $REPOSITORY cache-$CONTENT_HASH cache-$CONTENT_HASH-$DEPLOY_TAG-deployed"
39+
else
40+
# Write TF state variables
41+
deploy_terraform l1-contracts ./terraform
3642

37-
# Tag the image as deployed.
38-
retry tag_remote_image $REPOSITORY cache-$CONTENT_HASH cache-$CONTENT_HASH-$DEPLOY_TAG-deployed
43+
# Tag the image as deployed.
44+
retry tag_remote_image $REPOSITORY cache-$CONTENT_HASH cache-$CONTENT_HASH-$DEPLOY_TAG-deployed
45+
fi
46+
47+
# Set global variable for redeployment of contracts
48+
echo export CONTRACTS_DEPLOYED=1 >>$BASH_ENV

yarn-project/aztec-faucet/terraform/main.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ resource "aws_ecs_task_definition" "aztec-faucet" {
8686
container_definitions = <<DEFINITIONS
8787
[
8888
{
89-
"name": "${var.DEPLOY_TAG}-faucet",
89+
"name": "${var.DEPLOY_TAG}-aztec-faucet",
9090
"image": "${var.DOCKERHUB_ACCOUNT}/aztec-faucet:${var.DEPLOY_TAG}",
9191
"essential": true,
9292
"memoryReservation": 3776,
@@ -151,7 +151,7 @@ DEFINITIONS
151151
}
152152

153153
resource "aws_ecs_service" "aztec-faucet" {
154-
name = "${var.DEPLOY_TAG}-faucet"
154+
name = "${var.DEPLOY_TAG}-aztec-faucet"
155155
cluster = data.terraform_remote_state.setup_iac.outputs.ecs_cluster_id
156156
launch_type = "FARGATE"
157157
desired_count = 1
@@ -169,13 +169,13 @@ resource "aws_ecs_service" "aztec-faucet" {
169169

170170
load_balancer {
171171
target_group_arn = aws_alb_target_group.aztec-faucet.arn
172-
container_name = "${var.DEPLOY_TAG}-faucet"
172+
container_name = "${var.DEPLOY_TAG}-aztec-faucet"
173173
container_port = 80
174174
}
175175

176176
service_registries {
177177
registry_arn = aws_service_discovery_service.aztec-faucet.arn
178-
container_name = "${var.DEPLOY_TAG}-faucet"
178+
container_name = "${var.DEPLOY_TAG}-aztec-faucet"
179179
container_port = 80
180180
}
181181

yarn-project/aztec-node/terraform/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ resource "aws_efs_file_system" "node_data_store" {
110110
provisioned_throughput_in_mibps = 20
111111

112112
tags = {
113-
Name = "${var.DEPLOY_TAG}-node-data"
113+
Name = "${var.DEPLOY_TAG}-node-${count.index + 1}-data"
114114
}
115115

116116
lifecycle_policy {

yarn-project/p2p-bootstrap/terraform/main.tf

+20-20
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ locals {
5454
}
5555

5656

57-
resource "aws_cloudwatch_log_group" "aztec-bootstrap-log-group" {
57+
resource "aws_cloudwatch_log_group" "p2p-bootstrap-log-group" {
5858
count = local.bootnode_count
59-
name = "/fargate/service/${var.DEPLOY_TAG}/aztec-bootstrap-${count.index + 1}"
59+
name = "/fargate/service/${var.DEPLOY_TAG}/p2p-bootstrap-${count.index + 1}"
6060
retention_in_days = 14
6161
}
6262

63-
resource "aws_service_discovery_service" "aztec-bootstrap" {
63+
resource "aws_service_discovery_service" "p2p-bootstrap" {
6464
count = local.bootnode_count
65-
name = "${var.DEPLOY_TAG}-aztec-bootstrap-${count.index + 1}"
65+
name = "${var.DEPLOY_TAG}-p2p-bootstrap-${count.index + 1}"
6666

6767
health_check_custom_config {
6868
failure_threshold = 1
@@ -91,9 +91,9 @@ resource "aws_service_discovery_service" "aztec-bootstrap" {
9191
}
9292
}
9393

94-
resource "aws_ecs_task_definition" "aztec-bootstrap" {
94+
resource "aws_ecs_task_definition" "p2p-bootstrap" {
9595
count = local.bootnode_count
96-
family = "${var.DEPLOY_TAG}-aztec-bootstrap-${count.index + 1}"
96+
family = "${var.DEPLOY_TAG}-p2p-bootstrap-${count.index + 1}"
9797
requires_compatibilities = ["FARGATE"]
9898
network_mode = "awsvpc"
9999
cpu = "2048"
@@ -104,7 +104,7 @@ resource "aws_ecs_task_definition" "aztec-bootstrap" {
104104
container_definitions = <<DEFINITIONS
105105
[
106106
{
107-
"name": "${var.DEPLOY_TAG}-aztec-bootstrap-${count.index + 1}",
107+
"name": "${var.DEPLOY_TAG}-p2p-bootstrap-${count.index + 1}",
108108
"image": "${var.DOCKERHUB_ACCOUNT}/aztec-sandbox:${var.DEPLOY_TAG}",
109109
"essential": true,
110110
"command": ["start"],
@@ -154,7 +154,7 @@ resource "aws_ecs_task_definition" "aztec-bootstrap" {
154154
"logConfiguration": {
155155
"logDriver": "awslogs",
156156
"options": {
157-
"awslogs-group": "/fargate/service/${var.DEPLOY_TAG}/aztec-bootstrap-${count.index + 1}",
157+
"awslogs-group": "/fargate/service/${var.DEPLOY_TAG}/p2p-bootstrap-${count.index + 1}",
158158
"awslogs-region": "eu-west-2",
159159
"awslogs-stream-prefix": "ecs"
160160
}
@@ -164,9 +164,9 @@ resource "aws_ecs_task_definition" "aztec-bootstrap" {
164164
DEFINITIONS
165165
}
166166

167-
resource "aws_ecs_service" "aztec-bootstrap" {
167+
resource "aws_ecs_service" "p2p-bootstrap" {
168168
count = local.bootnode_count
169-
name = "${var.DEPLOY_TAG}-aztec-bootstrap-${count.index + 1}"
169+
name = "${var.DEPLOY_TAG}-p2p-bootstrap-${count.index + 1}"
170170
cluster = data.terraform_remote_state.setup_iac.outputs.ecs_cluster_id
171171
launch_type = "FARGATE"
172172
desired_count = 1
@@ -183,23 +183,23 @@ resource "aws_ecs_service" "aztec-bootstrap" {
183183
}
184184

185185
service_registries {
186-
registry_arn = aws_service_discovery_service.aztec-bootstrap[count.index].arn
187-
container_name = "${var.DEPLOY_TAG}-aztec-bootstrap-${count.index + 1}"
186+
registry_arn = aws_service_discovery_service.p2p-bootstrap[count.index].arn
187+
container_name = "${var.DEPLOY_TAG}-p2p-bootstrap-${count.index + 1}"
188188
container_port = 80
189189
}
190190

191191
load_balancer {
192-
target_group_arn = aws_lb_target_group.aztec-bootstrap-target-group[count.index].id
193-
container_name = "${var.DEPLOY_TAG}-aztec-bootstrap-${count.index + 1}"
192+
target_group_arn = aws_lb_target_group.p2p-bootstrap-target-group[count.index].id
193+
container_name = "${var.DEPLOY_TAG}-p2p-bootstrap-${count.index + 1}"
194194
container_port = var.BOOTNODE_LISTEN_PORT + count.index
195195
}
196196

197-
task_definition = aws_ecs_task_definition.aztec-bootstrap[count.index].family
197+
task_definition = aws_ecs_task_definition.p2p-bootstrap[count.index].family
198198
}
199199

200-
resource "aws_lb_target_group" "aztec-bootstrap-target-group" {
200+
resource "aws_lb_target_group" "p2p-bootstrap-target-group" {
201201
count = local.bootnode_count
202-
name = "aztec-bootstrap-${count.index + 1}-target-group"
202+
name = "p2p-bootstrap-${count.index + 1}-target-group"
203203
port = var.BOOTNODE_LISTEN_PORT + count.index
204204
protocol = "TCP"
205205
target_type = "ip"
@@ -224,18 +224,18 @@ resource "aws_security_group_rule" "allow-bootstrap-tcp" {
224224
security_group_id = data.terraform_remote_state.aztec-network_iac.outputs.p2p_security_group_id
225225
}
226226

227-
resource "aws_lb_listener" "aztec-bootstrap-tcp-listener" {
227+
resource "aws_lb_listener" "p2p-bootstrap-tcp-listener" {
228228
count = local.bootnode_count
229229
load_balancer_arn = data.terraform_remote_state.aztec-network_iac.outputs.nlb_arn
230230
port = var.BOOTNODE_LISTEN_PORT + count.index
231231
protocol = "TCP"
232232

233233
tags = {
234-
name = "aztec-bootstrap-${count.index}-target-group"
234+
name = "p2p-bootstrap-${count.index}-target-group"
235235
}
236236

237237
default_action {
238238
type = "forward"
239-
target_group_arn = aws_lb_target_group.aztec-bootstrap-target-group[count.index].arn
239+
target_group_arn = aws_lb_target_group.p2p-bootstrap-target-group[count.index].arn
240240
}
241241
}

0 commit comments

Comments
 (0)