Skip to content

Commit

Permalink
👷 dockerize it
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Cory authored and Will Cory committed Sep 11, 2023
1 parent 9b77904 commit 8012949
Show file tree
Hide file tree
Showing 17 changed files with 7,720 additions and 4,345 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
**/node_modules
lib/**/dist
apps/**/dist
packages/**/dist
.env
.vscode
forge-artifacts
cache
**/.env
target
24 changes: 2 additions & 22 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,17 @@ jobs:
e2e-vite:
name: Playwright E2E @evmts/example-vite
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.37.1-jammy
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive

- name: "Setup"
uses: ./.github/actions/setup

- name: Run anvil
run: anvil --port=8546 --fork-url ${{ secrets.RPC_URL_MAINNET }} --fork-block-number 14457512 &
env:
ANVIL_FORK_URL: ${{ secrets.ANVIL_FORK_URL }}
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
ANVIL_RPC_URL_1: ${{ secrets.RPC_URL_MAINNET }}
EXAMPLE_PROJECT: "@evmts/example-vite"
SERVER_PORT: 5173
VITE_RPC_URL_1: "http://localhost:8546"
PRIVATE_KEY: "test test test test test test test test test test test junk"

- name: Run @evmts/vite-example tests
run: xvfb-run --server-args='-screen 0 1024x768x24' pnpm nx e2e:ci @evmts/e2e
run: docker-compose up --build --abort-on-container-exit --exit-code-from e2e e2e
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
ANVIL_RPC_URL_1: ${{ secrets.RPC_URL_MAINNET }}
EXAMPLE_PROJECT: "@evmts/example-vite"
SERVER_PORT: 5173
VITE_RPC_URL_1: "http://localhost:8546"
PRIVATE_KEY: "test test test test test test test test test test test junk"
ANVIL_FORK_URL_1: ${{ secrets.RPC_URL_MAINNET }}

- name: 'Upload test-results artifacts'
uses: actions/upload-artifact@v3
Expand Down
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM node:18.12.1-bullseye as monorepo

ENV PATH "$PATH:/root/.foundry/bin"
ENV NX_DAEMON=false

# Add the Foundry CLI to the PATH and do a quick test to make sure it's installed to path
RUN curl -L https://foundry.paradigm.xyz | bash && \
foundryup && \
forge --version && \
anvil --version && \
cast --version && \
npm install -g [email protected]

WORKDIR /monorepo

# Copy manifest files into the image in
# preparation for `yarn install`.
COPY pnpm-workspace.yaml pnpm-lock.yaml .nvmrc ./

# install all dependencies
RUN pnpm fetch

# copy rest of repo and buildd
COPY . .

# build all apps and packages
RUN pnpm install --frozen-lockfile && pnpm nx run-many --target=build:dist

CMD ["pnpm", "all"]

# @evmts/example-next
# FROM nginx:stable-alpine as example-next
# COPY --from=monorepo /monorepo/examples/next/dist /usr/share/nginx/html
# COPY apps/ts-sol-playground/nginx.conf /etc/nginx/conf.d/default.conf
# EXPOSE 80
# CMD ["nginx", "-g", "daemon off;"]

# @evmts/example-vite
FROM nginx:stable-alpine as example-vite
COPY --from=monorepo /monorepo/examples/vite/dist /usr/share/nginx/html
COPY examples/vite/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

60 changes: 60 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: '3.8'

services:
anvil:
image: monorepo:latest
build:
context: .
target: monorepo
command:
[
"anvil",
"--port",
"8546",
"--fork-url",
"${ANVIL_FORK_URL_1}"
]
environment:
- ANVIL_IP_ADDR=0.0.0.0
- ANVIL_FORK_URL_1=${ANVIL_FORK_URL_1}
ports:
- 8546:8546
healthcheck:
test: cast block-number --rpc-url http://0.0.0.0:8546

example-vite:
image: example-vite:latest
build:
context: .
target: example-vite
args:
VITE_RPC_URL_1: "http://anvil:8546"
VITE_RPC_URL_420: "https://goerli.optimism.io"
environment:
- PORT=5173
- HOST="0.0.0.0"
ports:
- 5173:80
healthcheck:
test: wget localhost:80 -q -O - > /dev/null 2>&1

e2e:
image: e2e:latest
build:
context: e2e
environment:
- PLAYWRIGHT_BASE_URL=http://example-vite:5173
- PLAYWRIGHT_SLOW_MO=0
- PLAYWRIGHT_METAMASK_VERSION=10.25.0
- CI=true
- PLAYWRIGHT_HEADLESS_MODE=0
- PLAYWRIGHT_PRIVATE_KEY="test test test test test test test test test test test junk"
- PLAYWRIGHT_CHAIN_ID=1
- PLAYWRIGHT_RPC_URL=http://anvil:8546
depends_on:
anvil:
condition: service_healthy
example-vite:
condition: service_healthy
volumes:
- ./e2e/test_results:/e2e/test_results
13 changes: 13 additions & 0 deletions e2e/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules
lib/**/node_modules
lib/**/dist
apps/**/node_modules
apps/**/dist
packages/**/node_modules
packages/**/dist
.env
.vscode
forge-artifacts
cache
**/.env
target
18 changes: 18 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mcr.microsoft.com/playwright:v1.37.1-jammy

ENV PATH "$PATH:/root/.foundry/bin"

RUN apt-get update && apt-get install -y \
&& npm install -g [email protected]

WORKDIR /e2e

COPY pnpm-lock.yaml package.json ./

RUN pnpm install --frozen-lockfile

COPY . .

ENV NODE_ENV=production

CMD ["pnpm", "e2e:ci"]
5 changes: 2 additions & 3 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
"package:up": "pnpm up --latest",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"typescript": "^5.2.2"
},
"devDependencies": {
"@playwright/test": "^1.37.1",
"@synthetixio/synpress": "3.7.2-beta.7",
"dotenv": "^16.3.1",
"rome": "^12.1.3",
"typescript": "^5.2.2",
"viem": "^1.10.8"
}
}
19 changes: 3 additions & 16 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PlaywrightTestConfig, devices } from '@playwright/test'
import dotenv from 'dotenv';
import path from 'path';

dotenv.config();

Expand All @@ -11,29 +10,17 @@ const config: PlaywrightTestConfig = {
['line'],
['junit', { outputFile: 'test-results/results.xml' }],
['json', { outputFile: 'test-results/results.json' }],
['html'],
['html', { outputFile: 'test-results/results.html' }],
],
use: {
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
headless: false,
video: 'retain-on-failure',
headless: Boolean(process.env.PLAYWRIGHT_HEADLESS_MODE),
launchOptions: {
slowMo: parseInt(process.env.PLAYWRIGHT_SLOW_MO || '0'),
}
},
webServer: {
command: `pnpm nx test-server ${process.env.EXAMPLE_PROJECT ?? "@evmts/example-vite"}`,
url: `http://localhost:${process.env.SERVER_PORT ?? '5173'}`,
reuseExistingServer: false,
env: {
VITE_RPC_URL_1: 'http://localhost:8546',
VITE_RPC_URL_10: 'http://localhost:9545',
VITE_RPC_URL_420: 'http://localhost:9546',
PRIVATE_KEY: 'test test test test test test test test test test test junk',
SERVER_PORT: process.env.SERVER_PORT ?? '5173',
}
},
projects: [
{
name: 'chromium',
Expand Down
Loading

0 comments on commit 8012949

Please sign in to comment.