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: Set correct version of RPC & Sandbox when deploying tagged commit #1914

Merged
merged 13 commits into from
Sep 5, 2023
Merged
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 37 additions & 5 deletions build-system/scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
48 changes: 48 additions & 0 deletions build-system/scripts/force_deploy_build
Original file line number Diff line number Diff line change
@@ -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 <repository>
# 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
14 changes: 14 additions & 0 deletions yarn-project/aztec-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>`: 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.
2 changes: 2 additions & 0 deletions yarn-project/aztec-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-cli/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
14 changes: 13 additions & 1 deletion yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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 <string>', '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;
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec-rpc/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
19 changes: 17 additions & 2 deletions yarn-project/aztec-sandbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion yarn-project/aztec-sandbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/yarn-project-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down