Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): publishing dockerhub manifests #3450

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions build-system/scripts/deploy_dockerhub
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ REPOSITORY=$1
# TODO: Why even provide this? We can just figure it out by probing.
ARCH_LIST=${2:-}

# The tag to use for release images. Can be turned into an argument if needed, for now we only release 'latest'.
DIST_TAG="latest"

function docker_or_dryrun {
if [ "$DRY_DEPLOY" -eq 1 ] ; then
if [ "$DRY_DEPLOY" -eq 1 ]; then
echo DRY RUN: docker $@
else
retry docker $@
Expand All @@ -18,7 +21,9 @@ echo "Repo: $REPOSITORY"
echo "Arch List: $ARCH_LIST"

VERSION_TAG=$(extract_tag_version $REPOSITORY true)
MANIFEST_DEPLOY_URI=aztecprotocol/$REPOSITORY:$VERSION_TAG

MANIFEST_DEPLOY_URI=$DOCKERHUB_ACCOUNT/$REPOSITORY:$VERSION_TAG
MANIFEST_DIST_URI=$DOCKERHUB_ACCOUNT/$REPOSITORY:$DIST_TAG

# Login to dockerhub and ecr
dockerhub_login
Expand All @@ -30,16 +35,19 @@ for ARCH in $ARCH_LIST; do
retry docker pull $IMAGE_COMMIT_URI

# Retag and push image.
IMAGE_DEPLOY_URI=aztecprotocol/$REPOSITORY:$VERSION_TAG-$ARCH
IMAGE_DEPLOY_URI=$DOCKERHUB_ACCOUNT/$REPOSITORY:$VERSION_TAG-$ARCH
docker tag $IMAGE_COMMIT_URI $IMAGE_DEPLOY_URI
docker_or_dryrun push $IMAGE_DEPLOY_URI

echo "Adding image $IMAGE_DEPLOY_URI to manifest list $MANIFEST_DEPLOY_URI..."
docker_or_dryrun manifest create $MANIFEST_DEPLOY_URI --amend $IMAGE_DEPLOY_URI
done

docker_or_dryrun push $MANIFEST_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
done

# Retag versioned as latest.
docker_or_dryrun tag $MANIFEST_DEPLOY_URI aztecprotocol/$REPOSITORY:latest
docker_or_dryrun push aztecprotocol/$REPOSITORY:latest
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
4 changes: 1 addition & 3 deletions build-system/scripts/setup_env
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ echo "PULL_REQUEST=$PULL_REQUEST"
if [[ "$COMMIT_MESSAGE" == *"[ci dry-deploy]"* ]]; then
COMMIT_TAG=v999.999.999
DRY_DEPLOY=1
else
DRY_DEPLOY=0
fi

if [ -n "${COMMIT_TAG:-}" ]; then
Expand Down Expand Up @@ -83,7 +81,7 @@ echo export DEPLOY_ENV=$DEPLOY_ENV >> $BASH_ENV
echo export DEPLOY_TAG=$DEPLOY_TAG >> $BASH_ENV
echo export BRANCH=$BRANCH >> $BASH_ENV
echo export PULL_REQUEST=$PULL_REQUEST >> $BASH_ENV
echo export DRY_DEPLOY=${DRY_DEPLOY:-} >> $BASH_ENV
echo export DRY_DEPLOY=${DRY_DEPLOY:-0} >> $BASH_ENV
# We want very strict failures on any failing command, undefined variable, or commands that pipe to other commands.
echo set -euo pipefail >> $BASH_ENV
# Enable logging if [ci debug] is in commit message.
Expand Down
17 changes: 17 additions & 0 deletions build-system/scripts/test_shit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -eu

# TEST_STUFF=${TEST_STUFF:-}
unset TEST_STUFF

function test_fn {
if [ "$TEST_STUFF" -eq 1 ]; then
echo 'TEST_STUFF is 1'
else
echo 'TEST_STUFF is not 1'
fi
}

test_fn

echo 'end'
28 changes: 28 additions & 0 deletions l1-contracts/scripts/ci_deploy_contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

FORCE_DEPLOY=${2:-"false"}

export ETHEREUM_HOST=$DEPLOY_TAG-mainnet-fork.aztec.network:8545/$FORK_API_KEY

# If we have previously successful commit, we can early out if nothing relevant has changed since.
if [[ $FORCE_DEPLOY == 'false' ]] && check_rebuild cache-"$CONTENT_HASH" $REPOSITORY; then
echo "No deploy necessary."
exit 0
fi

mkdir -p serve
# Contract addresses will be mounted in the serve directory
docker run \
-v $(pwd)/serve:/usr/src/contracts/serve \
-e ETHEREUM_HOST=$ETHEREUM_HOST -e PRIVATE_KEY=$CONTRACT_PUBLISHER_PRIVATE_KEY \
278380418400.dkr.ecr.eu-west-2.amazonaws.com/l1-contracts:$COMMIT_HASH \
./scripts/deploy_contracts.sh

# Write the contract addresses as terraform variables
for KEY in ROLLUP_CONTRACT_ADDRESS REGISTRY_CONTRACT_ADDRESS INBOX_CONTRACT_ADDRESS OUTBOX_CONTRACT_ADDRESS; do
VALUE=$(jq -r .$KEY ./serve/contract_addresses.json)
export TF_VAR_$KEY=$VALUE
done

# Write TF state variables
deploy_terraform l1-contracts ./terraform
54 changes: 54 additions & 0 deletions l1-contracts/scripts/deploy_contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -eu

# Sets up defaults then runs the E2E Setup script to perform contract deployments
#
# Expected enviornment variables
# -ROLLUP_CONTRACT_ADDRESS
# -CONTRACT_DEPLOYMENT_EMITTER_ADDRESS
# -INBOX_CONTRACT_ADDRESS
# -OUTBOX_CONTRACT_ADDRESS
# -REGISTRY_CONTRACT_ADDRESS

# Create serve directory in which we save contract_addresses.json.
mkdir -p serve/
echo "Created output directory"

extract_deployed_to() {
grep 'Deployed to:' | awk '{print $3}'
}

deploy_contract() {
CONTRACT="$1"
CONSTRUCTOR_ARGS=(${2-})
if [ ${#CONSTRUCTOR_ARGS[@]} -gt 0 ]; then
forge create --rpc-url $ETHEREUM_HOST --private-key $PRIVATE_KEY $CONTRACT --constructor-args $CONSTRUCTOR_ARGS
else
forge create --rpc-url $ETHEREUM_HOST --private-key $PRIVATE_KEY $CONTRACT
fi
}

export REGISTRY_CONTRACT_ADDRESS=$(deploy_contract ./src/core/messagebridge/Registry.sol:Registry | extract_deployed_to)
export INBOX_CONTRACT_ADDRESS=$(deploy_contract ./src/core/messagebridge/Inbox.sol:Inbox "$REGISTRY_CONTRACT_ADDRESS" | extract_deployed_to)
export OUTBOX_CONTRACT_ADDRESS=$(deploy_contract ./src/core/messagebridge/Outbox.sol:Outbox "$REGISTRY_CONTRACT_ADDRESS" | extract_deployed_to)
export ROLLUP_CONTRACT_ADDRESS=$(deploy_contract ./src/core/Rollup.sol:Rollup "$REGISTRY_CONTRACT_ADDRESS" | extract_deployed_to)
export CONTRACT_DEPLOYMENT_EMITTER_ADDRESS=$(deploy_contract ./src/core/periphery/ContractDeploymentEmitter.sol:ContractDeploymentEmitter | extract_deployed_to)

# Store contract addresses in a JSON file
jq -n \
--arg registryAddress "$REGISTRY_CONTRACT_ADDRESS" \
--arg inboxAddress "$INBOX_CONTRACT_ADDRESS" \
--arg outboxAddress "$OUTBOX_CONTRACT_ADDRESS" \
--arg rollupAddress "$ROLLUP_CONTRACT_ADDRESS" \
--arg emitterAddress "$CONTRACT_DEPLOYMENT_EMITTER_ADDRESS" \
'{
REGISTRY_CONTRACT_ADDRESS: $registryAddress,
INBOX_CONTRACT_ADDRESS: $inboxAddress,
OUTBOX_CONTRACT_ADDRESS: $outboxAddress,
ROLLUP_CONTRACT_ADDRESS: $rollupAddress,
CONTRACT_DEPLOYMENT_EMITTER_ADDRESS: $emitterAddress
}' >serve/contract_addresses.json

cat serve/contract_addresses.json

echo "Contract addresses have been written to serve/contract_addresses.json"