diff --git a/Dockerfile b/Dockerfile index 098d4c005..06a98d820 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,16 @@ FROM node:18.16.0 as base ENV YARN_CACHE_FOLDER=/tmp/yarn_cache +# We'll need a mock NPM_TOKEN to execute any yarn commands +ENV NPM_TOKEN= + # Update the system packages RUN apt-get update RUN apt-get install -y \ # Get the envsubst command (see below) - gettext-base + gettext-base \ + # Get the json utilities + jq # .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- # / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ @@ -28,11 +33,6 @@ RUN apt-get install -y \ # `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' FROM base as builder -# The name of the package we're building here -# -# e.g. @layerzerolabs/ua-utils-evm-hardhat -ARG PACKAGE - WORKDIR /app # We'll only use this turbo to prune the workspace, we don't care what version we use here @@ -47,7 +47,14 @@ COPY . . # # See more here https://turbo.build/repo/docs/reference/command-line-reference/prune # And here https://turbo.build/repo/docs/handbook/deploying-with-docker -RUN turbo prune $PACKAGE --docker +# +# There's an open issue on turbo github to support pruning +# without scope, in the meantime we'll use yarn workspaces info +# in combination with jq to get a full list of the workspace packages +# and prefix them with --scope +# +# See https://github.com/vercel/turbo/issues/4074 +RUN turbo prune $(yarn workspaces --silent info | jq -r 'keys | map("--scope " + .) | join(" ")') --docker # .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- # / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ @@ -99,17 +106,14 @@ RUN \ # / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ # `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' # -# Image that builds the package +# Image that prepares the project for development # # .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- # / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ # `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' -FROM dependencies as build +FROM dependencies as development -# The name of the package we're building here -# -# e.g. @layerzerolabs/ua-utils-evm-hardhat -ARG PACKAGE +ENV NPM_TOKEN= WORKDIR /app @@ -117,7 +121,4 @@ WORKDIR /app COPY tsconfig.json ./ # Now we grab the full source code from the builder step -COPY --from=builder /app/out/full/ . - -# And finally we build the package -RUN yarn build --filter=$PACKAGE... \ No newline at end of file +COPY --from=builder /app/out/full/ . \ No newline at end of file diff --git a/docker-compose.templates.yaml b/docker-compose.templates.yaml index b662d5a91..d3d381b74 100644 --- a/docker-compose.templates.yaml +++ b/docker-compose.templates.yaml @@ -18,5 +18,35 @@ services: build: context: . args: - PACKAGE: + # In order not to embed the NPM_TOKEN to the image, we'll pass it as an build argument + # + # This works in conjunction with the adjacent Dockerfile that: + # + # - interpolates .npmrc with this argument + # - installs the depenendencies + # - deletes the interpolated file + # + # This all needs to be done within one layer so that there is no way of reverse engineering + # the Dockerfile and getting the NPM_TOKEN out NPM_TOKEN: $NPM_TOKEN + # We'll provide a single testing MNEMONIC for the project so that the test EVM nodes + # account are in sync with the hardhat accounts + environment: + - MNEMONIC='test test test test test test test test test test test test' + + # EVM node for testing purposes + evm-node: + extends: + service: project + working_dir: /app/packages/test-evm-node + command: ["npx", "turbo", "start"] + healthcheck: + interval: 2s + retries: 10 + test: ["CMD", "curl", "-f", "http://0.0.0.0:8545/"] + + # Service that can build this package + tests: + extends: + service: project + working_dir: /app/packages/ua-utils-evm-hardhat-test diff --git a/packages/ua-utils-evm-hardhat-test/docker-compose.yaml b/docker-compose.yaml similarity index 60% rename from packages/ua-utils-evm-hardhat-test/docker-compose.yaml rename to docker-compose.yaml index cb522ca4f..59ed54e8d 100644 --- a/packages/ua-utils-evm-hardhat-test/docker-compose.yaml +++ b/docker-compose.yaml @@ -18,46 +18,27 @@ services: network-vengaboys: extends: file: docker-compose.templates.yaml - service: node + service: evm-node network-britney: extends: file: docker-compose.templates.yaml - service: node + service: evm-node # ~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~ # - # Bootstrap script that deploys all the networks + # The actual tests # # .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo. - bootstrap: + tests: extends: file: docker-compose.templates.yaml - service: package + service: project depends_on: network-vengaboys: condition: service_healthy network-britney: condition: service_healthy - # Can't say I love the fact that the deploy scripts are inlined here - # but at least it's all in this file that bootstraps the whole environment - command: - - /bin/bash - - -c - - | - npx hardhat --network vengaboys deploy --reset - npx hardhat --network britney deploy --reset - - # ~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~ - # - # The actual tests - # - # .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo. - tests: - extends: - file: docker-compose.templates.yaml - service: package - depends_on: - bootstrap: - condition: service_completed_successfully - command: ["npx", "hardhat", "test"] + volumes: + - ./packages:/app/packages + command: ["npx", "turbo", "test"] diff --git a/package.json b/package.json index 394f8ac3a..0690fd72e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dev": "npx turbo run dev", "lint": "npx turbo run lint", "prepare": "husky install", - "test": "npx turbo run test" + "test": "docker compose run --rm $DOCKER_COMPOSE_RUN_TESTS_ARGS tests" }, "lint-staged": { "**/*": "npx prettier --write --ignore-unknown" diff --git a/packages/ua-utils-evm-hardhat-test/docker-compose.templates.yaml b/packages/ua-utils-evm-hardhat-test/docker-compose.templates.yaml deleted file mode 100644 index eafb845dd..000000000 --- a/packages/ua-utils-evm-hardhat-test/docker-compose.templates.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- -# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ -# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' -# -# Reusable services for docker compose -# -# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- -# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ -# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' -version: "3.9" - -services: - # Service that can build this package - package: - build: - args: - PACKAGE: "@layerzerolabs/ua-utils-evm-hardhat-test" - extends: - file: ../../docker-compose.templates.yaml - service: project - working_dir: /app/packages/ua-utils-evm-hardhat-test - volumes: - - ./:/app/packages/ua-utils-evm-hardhat-test - - # Hardhat node started on port 8545 - node: - extends: - service: package - expose: - - 8545 - command: ["npx", "hardhat", "node", "--hostname", "0.0.0.0", "--no-deploy"] - healthcheck: - interval: 2s - retries: 10 - test: ["CMD", "curl", "-f", "http://0.0.0.0:8545/"] diff --git a/packages/ua-utils-evm-hardhat-test/hardhat.config.ts b/packages/ua-utils-evm-hardhat-test/hardhat.config.ts index b4dd9ad33..2cb8c52e3 100644 --- a/packages/ua-utils-evm-hardhat-test/hardhat.config.ts +++ b/packages/ua-utils-evm-hardhat-test/hardhat.config.ts @@ -1,10 +1,12 @@ import 'hardhat-deploy' import 'hardhat-deploy-ethers' +import assert from 'assert' import { withLayerZeroArtifacts } from '@layerzerolabs/utils-evm-hardhat' import { EndpointId } from '@layerzerolabs/lz-definitions' import { HardhatUserConfig } from 'hardhat/types' -const MNEMONIC = 'test test test test test test test test test test test test' +const MNEMONIC = process.env.MNEMONIC +assert(MNEMONIC, `Missing MNEMONIC environment variable`) /** * This is a dummy hardhat config that enables us to test @@ -15,11 +17,6 @@ const config: HardhatUserConfig = { version: '0.8.19', }, networks: { - hardhat: { - accounts: { - mnemonic: MNEMONIC, - }, - }, vengaboys: { eid: EndpointId.ETHEREUM_MAINNET, url: 'http://network-vengaboys:8545', diff --git a/packages/ua-utils-evm-hardhat-test/package.json b/packages/ua-utils-evm-hardhat-test/package.json index 897db9c9c..7ef69914a 100644 --- a/packages/ua-utils-evm-hardhat-test/package.json +++ b/packages/ua-utils-evm-hardhat-test/package.json @@ -11,7 +11,8 @@ "license": "MIT", "scripts": { "lint": "npx eslint '**/*.{js,ts,json}'", - "test": "docker compose run --rm $DOCKER_COMPOSE_RUN_TESTS_ARGS tests" + "pretest": "npx hardhat --network vengaboys deploy --reset && npx hardhat --network britney deploy --reset", + "test": "npx hardhat test" }, "devDependencies": { "@ethersproject/abstract-signer": "^5.7.0", diff --git a/turbo.json b/turbo.json index 69101a56b..782f32509 100644 --- a/turbo.json +++ b/turbo.json @@ -21,7 +21,13 @@ "lint": { "cache": false }, + "start": { + "outputs": [], + "dependsOn": ["build"], + "persistent": true + }, "test": { + "cache": false, "outputs": [], "dependsOn": ["^build"] }