Skip to content

Commit

Permalink
chore: Rearrange containerized setup
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista committed Dec 4, 2023
1 parent 5172160 commit a934120
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 88 deletions.
35 changes: 18 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
Expand All @@ -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
Expand All @@ -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

# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
Expand Down Expand Up @@ -99,25 +106,19 @@ 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

# For some reason we're missing tsconfig.json when using turbo prune
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...
COPY --from=builder /app/out/full/ .
32 changes: 31 additions & 1 deletion docker-compose.templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 0 additions & 35 deletions packages/ua-utils-evm-hardhat-test/docker-compose.templates.yaml

This file was deleted.

9 changes: 3 additions & 6 deletions packages/ua-utils-evm-hardhat-test/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion packages/ua-utils-evm-hardhat-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
"lint": {
"cache": false
},
"start": {
"outputs": [],
"dependsOn": ["build"],
"persistent": true
},
"test": {
"cache": false,
"outputs": [],
"dependsOn": ["^build"]
}
Expand Down

0 comments on commit a934120

Please sign in to comment.