diff --git a/.circleci/config.yml b/.circleci/config.yml index f0d325cdfc70..e3d80cfb75b6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -596,7 +596,7 @@ jobs: - *setup_env - run: name: "Build and test" - command: build aztec-sandbox + command: force_deploy_build aztec-sandbox circuits-js: machine: diff --git a/build-system/scripts/build b/build-system/scripts/build index 2f59649e2738..d5fc2d44d56a 100755 --- a/build-system/scripts/build +++ b/build-system/scripts/build @@ -115,16 +115,48 @@ for STAGE in $STAGES; do STAGE_CACHE_FROM="--cache-from $STAGE_IMAGE_LAST_URI" fi fi - + echo "Building stage: $STAGE" STAGE_IMAGE_COMMIT_URI=$ECR_URL/$REPOSITORY:cache-$CONTENT_HASH-$STAGE # Build our dockerfile, add timing information - docker build --target $STAGE $STAGE_CACHE_FROM -t $STAGE_IMAGE_COMMIT_URI -f $DOCKERFILE --build-arg ARG_CONTENT_HASH=$CONTENT_HASH . \ + + # Check if there is a commit tag + if [[ -n "$COMMIT_TAG" ]]; then + + # Check if it's a repo-specific tag + if [[ "$COMMIT_TAG" == *"/"* ]]; then + REPO_NAME="${COMMIT_TAG%%/*}" + COMMIT_TAG_VERSION="${COMMIT_TAG#*/}" + echo "Tag was made for: $REPO_NAME" + echo "Version: $COMMIT_TAG_VERSION" + + # Check if REPO_NAME is equal to REPOSITORY + if [ "$REPO_NAME" != "$REPOSITORY" ]; then + echo "REPO_NAME ($REPO_NAME) does not match REPOSITORY ($REPOSITORY). Ignoring..." + COMMIT_TAG_VERSION="" + fi + else + COMMIT_TAG_VERSION=$COMMIT_TAG + fi + + # We are building a tagged commit. Check it's a valid semver. + VERSION=$(npx semver $COMMIT_TAG_VERSION) + if [ -z "$VERSION" ]; then + COMMIT_TAG_VERSION="" + fi + + # Pass commit tag as build argument if it exists + docker build --target $STAGE $STAGE_CACHE_FROM -t $STAGE_IMAGE_COMMIT_URI -f $DOCKERFILE --build-arg ARG_CONTENT_HASH=$CONTENT_HASH DOCKER_TAG=${COMMIT_TAG_VERSION#v} . \ | while read line ; do echo "$(date "+%H:%M:%S")| $line"; done - + else + docker build --target $STAGE $STAGE_CACHE_FROM -t $STAGE_IMAGE_COMMIT_URI -f $DOCKERFILE --build-arg ARG_CONTENT_HASH=$CONTENT_HASH . \ + | while read line ; do echo "$(date "+%H:%M:%S")| $line"; done + + fi + # We don't want to have redo this stages work when building the final image. Use it as a layer cache. CACHE_FROM="--cache-from $STAGE_IMAGE_COMMIT_URI $CACHE_FROM" - + echo "Pushing stage: $STAGE" docker push $STAGE_IMAGE_COMMIT_URI > /dev/null 2>&1 echo @@ -144,7 +176,7 @@ IMAGE_COMMIT_URI=$ECR_URL/$REPOSITORY:cache-$CONTENT_HASH echo "Building image: $IMAGE_COMMIT_URI" # Build our dockerfile, add timing information docker build -t $IMAGE_COMMIT_URI -f $DOCKERFILE $CACHE_FROM --build-arg COMMIT_TAG=$COMMIT_TAG --build-arg ARG_CONTENT_HASH=$CONTENT_HASH . \ - | while read line ; do echo "$(date "+%H:%M:%S")| $line"; done +| while read line ; do echo "$(date "+%H:%M:%S")| $line"; done echo "Pushing image: $IMAGE_COMMIT_URI" docker push $IMAGE_COMMIT_URI > /dev/null 2>&1 untag_remote_image $REPOSITORY tainted diff --git a/build-system/scripts/force_deploy_build b/build-system/scripts/force_deploy_build new file mode 100755 index 000000000000..d7729bc7e361 --- /dev/null +++ b/build-system/scripts/force_deploy_build @@ -0,0 +1,48 @@ +#!/bin/bash +# +# This script forces a build if we're in a deployment run, otherwise runs `build` as usual +# +# usage: ./deploy_force_build +# example: ./deploy_force_build aztec-sandbox +set -e + +REPOSITORY=$1 +FORCE_BUILD=${2:-"false"} + +# if FORCE_BUILD is already set, just continue with it +if [[ $FORCE_BUILD == 'true' ]]; then + build $REPOSITORY true + exit 0 +fi + +# Check if there's a commit TAG +if [[ -n "$COMMIT_TAG" ]]; then + # Check if it's a repo-specific tag + if [[ "$COMMIT_TAG" == *"/"* ]]; then + REPO_NAME="${COMMIT_TAG%%/*}" + COMMIT_TAG_VERSION="${COMMIT_TAG#*/}" + echo "Tag was made for: $REPO_NAME" + echo "Version: $COMMIT_TAG_VERSION" + + # Check if REPO_NAME is equal to REPOSITORY + if [ "$REPO_NAME" != "$REPOSITORY" ]; then + echo "REPO_NAME ($REPO_NAME) does not match REPOSITORY ($REPOSITORY). Ignoring..." + COMMIT_TAG_VERSION="" + fi + else + COMMIT_TAG_VERSION=$COMMIT_TAG + fi + + # We are building a tagged commit. Check it's a valid semver. + VERSION=$(npx semver $COMMIT_TAG_VERSION) + if [ -z "$VERSION" ]; then + # Not a version tag, build normally + build $REPOSITORY + else + # Force build + build $REPOSITORY true + fi +else + # Not a tagged commit, build normally + build $REPOSITORY +fi diff --git a/yarn-project/aztec-cli/README.md b/yarn-project/aztec-cli/README.md index 69313b809115..da770d47de92 100644 --- a/yarn-project/aztec-cli/README.md +++ b/yarn-project/aztec-cli/README.md @@ -435,6 +435,20 @@ Syntax: aztec-cli example-contracts ``` +### get-node-info + +Gets information of an Aztec node at the specified URL. + +Syntax: + +```shel +aztec-cli get-node-info +``` + +Options: + +- `-u, --rpc-url `: URL of the Aztec RPC. Default: `http://localhost:8080`. + ## Conclusion That covers the available commands and their usage in the `aztec-cli`. You can now use these commands to interact with Aztec and perform various actions such as deploying contracts, creating accounts, executing functions, and retrieving blockchain data. diff --git a/yarn-project/aztec-cli/package.json b/yarn-project/aztec-cli/package.json index defce57b8cba..f929d946e3d7 100644 --- a/yarn-project/aztec-cli/package.json +++ b/yarn-project/aztec-cli/package.json @@ -43,6 +43,7 @@ "@aztec/noir-contracts": "workspace:^", "@aztec/types": "workspace:^", "commander": "^9.0.0", + "lodash.startcase": "^4.4.0", "semver": "^7.5.4", "tslib": "^2.4.0", "viem": "^1.2.5" @@ -51,6 +52,7 @@ "@jest/globals": "^29.5.0", "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.5.0", + "@types/lodash.startcase": "^4.4.7", "@types/node": "^18.7.23", "jest": "^29.5.0", "jest-mock-extended": "^3.0.5", diff --git a/yarn-project/aztec-cli/src/client.ts b/yarn-project/aztec-cli/src/client.ts index 7cb5d770aa0c..f1ec98bbb240 100644 --- a/yarn-project/aztec-cli/src/client.ts +++ b/yarn-project/aztec-cli/src/client.ts @@ -60,7 +60,7 @@ export async function checkServerVersion(rpc: AztecRPC, expectedVersionRange: st throw new VersionMismatchError(`Couldn't determine ${serverName} version. You may run into issues.`); } const version = client.split('@')[1]; - logger?.debug(`Comparing server version ${version} against CLI expected ${expectedVersionRange}`); + logger?.warn(`Comparing server version ${version} against CLI expected ${expectedVersionRange}`); if (!version || !valid(version)) { throw new VersionMismatchError(`Missing or invalid version identifier for ${serverName} (${version ?? 'empty'}).`); } else if (!satisfies(version, expectedVersionRange)) { diff --git a/yarn-project/aztec-cli/src/index.ts b/yarn-project/aztec-cli/src/index.ts index a0b73b04f358..34aa0c159505 100644 --- a/yarn-project/aztec-cli/src/index.ts +++ b/yarn-project/aztec-cli/src/index.ts @@ -19,6 +19,7 @@ import { CompleteAddress, ContractData, L2BlockL2Logs, PrivateKey, TxHash } from import { Command } from 'commander'; import { readFileSync } from 'fs'; +import startCase from 'lodash.startcase'; import { dirname, resolve } from 'path'; import { mnemonicToAccount } from 'viem/accounts'; @@ -436,7 +437,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { log('\nView result: ', result, '\n'); }); - // Helper for users to decode hex strings into structs if needed + // Helper for users to decode hex strings into structs if needed. program .command('parse-parameter-struct') .description("Helper for parsing an encoded string into a contract's parameter struct.") @@ -479,6 +480,17 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { names.forEach(name => log(name)); }); + program + .command('get-node-info') + .description('Gets the information of an aztec node at a URL.') + .requiredOption('-u, --rpc-url ', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080') + .action(async options => { + const client = await createCompatibleClient(options.rpcUrl, debugLogger); + const info = await client.getNodeInfo(); + log(`\nNode Info:\n`); + Object.entries(info).map(([key, value]) => log(`${startCase(key)}: ${value}`)); + }); + compileContract(program, 'compile', log); return program; diff --git a/yarn-project/aztec-rpc/src/config/index.ts b/yarn-project/aztec-rpc/src/config/index.ts index c44f505decdc..11a63369e050 100644 --- a/yarn-project/aztec-rpc/src/config/index.ts +++ b/yarn-project/aztec-rpc/src/config/index.ts @@ -29,5 +29,6 @@ export function getConfigEnvVars(): RpcServerConfig { export function getPackageInfo() { const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json'); const { version, name } = JSON.parse(readFileSync(packageJsonPath).toString()); + return { version, name }; } diff --git a/yarn-project/aztec-sandbox/Dockerfile b/yarn-project/aztec-sandbox/Dockerfile index aeacc207c78a..56cb755d5ba4 100644 --- a/yarn-project/aztec-sandbox/Dockerfile +++ b/yarn-project/aztec-sandbox/Dockerfile @@ -1,19 +1,34 @@ FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder +ARG DOCKER_TAG + +# Remove SRS files (currently not producing proofs) RUN rm -rf /usr/src/circuits/cpp/barretenberg/cpp/srs_db/ignition/monomial COPY . . +# Update aztec-rpc version if DOCKER_TAG has been used +WORKDIR /usr/src/yarn-project/aztec-rpc +RUN if [[ -n "${DOCKER_TAG}" ]]; then \ + jq --arg v ${DOCKER_TAG} '.version = $v' package.json > _temp && mv _temp package.json; \ + fi + WORKDIR /usr/src/yarn-project/aztec-sandbox -RUN yarn build -# && yarn formatting && yarn test +RUN ls +RUN if [[ -n "${DOCKER_TAG}" ]]; then \ + jq --arg v ${DOCKER_TAG} '.version = $v' package.json > _temp && mv _temp package.json; \ + fi + +RUN yarn build && yarn formatting && yarn test # Prune dev dependencies. See comment in base image. RUN yarn cache clean RUN yarn workspaces focus --production > /dev/null FROM node:18-alpine + COPY --from=builder /usr/src/ /usr/src/ WORKDIR /usr/src/yarn-project/aztec-sandbox + ENTRYPOINT ["yarn"] CMD [ "start" ] EXPOSE 8080 \ No newline at end of file diff --git a/yarn-project/aztec-sandbox/src/index.ts b/yarn-project/aztec-sandbox/src/index.ts index 093353350f28..17b4da20df70 100644 --- a/yarn-project/aztec-sandbox/src/index.ts +++ b/yarn-project/aztec-sandbox/src/index.ts @@ -67,7 +67,7 @@ async function main() { const hdAccount = mnemonicToAccount(MNEMONIC); const privKey = hdAccount.getHdKey().privateKey; const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../package.json'); - const version: string = JSON.parse(readFileSync(packageJsonPath).toString()).version; + const version = JSON.parse(readFileSync(packageJsonPath).toString()).version; logger.info(`Setting up Aztec Sandbox v${version}, please stand by...`); logger.info('Deploying rollup contracts to L1...'); diff --git a/yarn-project/yarn-project-base/Dockerfile b/yarn-project/yarn-project-base/Dockerfile index 953139661c48..6ff9e79fc73f 100644 --- a/yarn-project/yarn-project-base/Dockerfile +++ b/yarn-project/yarn-project-base/Dockerfile @@ -44,7 +44,7 @@ COPY types/package.json types/package.json COPY world-state/package.json world-state/package.json COPY yarn-project-base/package.json yarn-project-base/package.json -# Copy root files +# Copy root files. COPY package.json package.*.json tsconfig.json yarn.lock .yarnrc.yml ./ COPY .yarn .yarn diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index c60584ae0c50..fb4d249d7ac6 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -324,10 +324,12 @@ __metadata: "@jest/globals": ^29.5.0 "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.5.0 + "@types/lodash.startcase": ^4.4.7 "@types/node": ^18.7.23 commander: ^9.0.0 jest: ^29.5.0 jest-mock-extended: ^3.0.5 + lodash.startcase: ^4.4.0 semver: ^7.5.4 string-argv: ^0.3.2 ts-jest: ^29.1.0 @@ -3272,6 +3274,15 @@ __metadata: languageName: node linkType: hard +"@types/lodash.startcase@npm:^4.4.7": + version: 4.4.7 + resolution: "@types/lodash.startcase@npm:4.4.7" + dependencies: + "@types/lodash": "*" + checksum: ee5b903e7cb99a4c747325c38167dea70c10f9929823033f7f2e02aad5e227c84f80c6f7d9d6923a7c0f30a429c5ea4a1b6505bd50a96655b6ab7ac43e8ebe27 + languageName: node + linkType: hard + "@types/lodash.times@npm:^4.3.7": version: 4.3.7 resolution: "@types/lodash.times@npm:4.3.7" @@ -8960,6 +8971,13 @@ __metadata: languageName: node linkType: hard +"lodash.startcase@npm:^4.4.0": + version: 4.4.0 + resolution: "lodash.startcase@npm:4.4.0" + checksum: c03a4a784aca653845fe09d0ef67c902b6e49288dc45f542a4ab345a9c406a6dc194c774423fa313ee7b06283950301c1221dd2a1d8ecb2dac8dfbb9ed5606b5 + languageName: node + linkType: hard + "lodash.times@npm:^4.3.2": version: 4.3.2 resolution: "lodash.times@npm:4.3.2"