Skip to content

Commit 434c655

Browse files
jakeloofarhanW3
andauthored
Simplifies docker and compose build (#586)
* Simplifies docker and compose build * Fix redis image * updates to fix abosulte <> relative path * reverting tsconfig udpates --------- Co-authored-by: farhanW3 <farhan@thirdweb.com>
1 parent f40c83d commit 434c655

File tree

18 files changed

+135
-1041
lines changed

18 files changed

+135
-1041
lines changed

.dockerignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ npm-debug.log
33
Dockerfile
44
.dockerignore
55
.env
6+
.env*
67
yarn-error.log
78
.husky
89
docker-compose*.yml
9-
Dockerfile
10+
Dockerfile*
1011
.DS_Store
1112
swagger.yml
1213
test
1314
.dist
1415
.github
1516
.gitignore
1617
.git
17-
.coverage
18+
.coverage
19+
dist
20+
docs
21+
.vscode

.github/workflows/promote.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

Dockerfile

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,67 @@
11
FROM node:18.20-slim AS base
22

3-
# Upgrade packages
4-
RUN apt-get -y update && apt-get -y upgrade
5-
6-
# Install tini & build dependencies
7-
RUN apt-get install -y g++ make python3-pip openssl
8-
9-
# Set the working directory
103
WORKDIR /app
114

5+
# Upgrade packages
6+
RUN apt-get -y update && \
7+
apt-get -y upgrade && \
8+
apt-get -y install libssl-dev
129

13-
# Copy package.json and yarn.lock files
14-
COPY package*.json yarn*.lock ./
15-
16-
# Copy the entire project directory
17-
COPY . .
10+
##############################
11+
##############################
12+
##############################
13+
##############################
1814

19-
# Install dependencies for both development and production
20-
RUN yarn install --frozen-lockfile --network-timeout 1000000
15+
# Generate cert for local https
16+
FROM base AS certs
2117

2218
WORKDIR /app/src/https
2319

20+
RUN apt-get -y install openssl
21+
2422
RUN openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 \
2523
-subj "/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=localhost" \
2624
-passout pass:thirdweb-engine && \
2725
chmod 600 key.pem cert.pem
2826

29-
WORKDIR /app
30-
31-
# Clean up build dependencies
32-
# RUN apt del build-dependencies
33-
3427
##############################
3528
##############################
36-
37-
FROM base AS local
38-
39-
EXPOSE 3005
40-
ENV NODE_ENV="local"
41-
RUN npm install -g nodemon
42-
43-
CMD [ "sh", "-c","yarn prisma:setup:dev && yarn dev:run" ]
44-
4529
##############################
4630
##############################
4731

48-
# Production Node Modules stage
49-
FROM base AS prod-dependencies
32+
FROM base AS build
5033

51-
WORKDIR /app
34+
# Install Python3-Pip
35+
RUN apt-get -y install python3-pip
5236

53-
# Upgrade packages
54-
RUN apt-get -y update && apt-get -y upgrade
37+
# Copy the entire project directory
38+
COPY . .
5539

40+
# Install dependencies for both development and production (May need devDependencies to build)
5641
# Build the project
57-
RUN apt-get install -y g++ make python3-pip && \
42+
# Prune dev dependencies from the packages
43+
RUN yarn install --frozen-lockfile --production=false --network-timeout 1000000 && \
5844
yarn build && \
59-
yarn copy-files && \
60-
rm -rf node_modules && \
61-
yarn install --production=true --frozen-lockfile --network-timeout 1000000
62-
45+
yarn install --frozen-lockfile --production=true --network-timeout 1000000
6346

6447
##############################
6548
##############################
49+
##############################
50+
##############################
51+
52+
FROM base AS prod
6653

67-
# Production stage
68-
FROM node:18.20-slim AS prod
54+
EXPOSE 3005
6955

70-
# Setting ENV variables for image information
7156
ARG ENGINE_VERSION
7257
ENV ENGINE_VERSION=${ENGINE_VERSION}
73-
74-
# Upgrade packages
75-
RUN apt-get -y update && apt-get -y upgrade
76-
77-
# Install openssl
78-
RUN apt-get install -y openssl
79-
80-
# Set the working directory
81-
WORKDIR /app
8258
ENV NODE_ENV="production" \
8359
PATH=/app/node_modules/.bin:$PATH
84-
85-
EXPOSE 3005
86-
87-
# Copy package.json and yarn.lock files
88-
COPY package*.json yarn*.lock ./
89-
90-
# Replace the schema path in the package.json file
91-
RUN sed -i 's_"schema": "./src/prisma/schema.prisma"_"schema": "./dist/prisma/schema.prisma"_g' package.json
9260

93-
# Copy only production dependencies from the prod-dependencies stage
94-
COPY --from=prod-dependencies /app/node_modules ./node_modules
95-
COPY --from=prod-dependencies /app/dist ./dist
96-
COPY --from=base /app/src/https ./dist/https
61+
COPY --from=certs /app/src/https ./dist/https
62+
COPY --from=build /app/package.json .
63+
COPY --from=build /app/node_modules ./node_modules
64+
COPY --from=build /app/src/prisma/* ./src/prisma/
65+
COPY --from=build /app/dist ./dist
9766

98-
CMD [ "yarn", "start"]
67+
ENTRYPOINT [ "yarn", "start"]

docker-compose-infra.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

docker-compose-prod.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

docker-compose.yml

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
###################################
2+
# USED FOR LOCAL DEVELOPMENT ONLY #
3+
###################################
4+
15
services:
2-
db:
3-
image: postgres:latest
6+
postgres:
7+
container_name: postgres
8+
image: postgres:16.3
9+
restart: always
410
env_file:
511
- .env
12+
environment:
13+
- POSTGRES_HOST_AUTH_METHOD=trust
614
volumes:
7-
- db_data:/var/lib/postgresql/data
15+
- postgres_data:/var/lib/postgresql/data
816
ports:
9-
- "5432:5432"
17+
- 5432:5432
1018
deploy:
1119
resources:
1220
limits:
@@ -18,34 +26,51 @@ services:
1826

1927
redis:
2028
container_name: redis
21-
image: redis:latest
29+
image: redis:7.2
2230
restart: always
2331
ports:
2432
- 6379:6379
2533
volumes:
2634
- redis_data:/data
2735

36+
bullboard:
37+
container_name: bullboard
38+
image: deadly0/bull-board:3.2.6
39+
restart: always
40+
ports:
41+
- 3333:3000
42+
environment:
43+
REDIS_HOST: redis
44+
REDIS_PORT: 6379
45+
REDIS_USE_TLS: "false"
46+
BULL_PREFIX: bull
47+
depends_on:
48+
- redis
49+
2850
engine:
51+
profiles:
52+
- engine
2953
build:
3054
dockerfile: Dockerfile
3155
context: .
32-
target: local
56+
target: prod
3357
env_file:
3458
- .env
3559
ports:
3660
- 3005:3005
3761
depends_on:
38-
- db
62+
- postgres
3963
- redis
4064
deploy:
4165
resources:
4266
limits:
4367
cpus: "1"
4468
memory: 1024M
69+
# entrypoint: "yarn start:dev"
4570
# volumes:
4671
# - ./:/app
4772
# - node_modules:/app/node_modules
4873

4974
volumes:
50-
db_data:
75+
postgres_data:
5176
redis_data:

package.json

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,20 @@
77
"author": "thirdweb engineering <eng@thirdweb.com>",
88
"type": "module",
99
"scripts": {
10-
"docker": "docker compose --env-file ./.env up --remove-orphans",
11-
"docker:build": "docker compose build --no-cache",
1210
"dev": "yarn dev:infra && yarn dev:db && yarn dev:run",
13-
"dev:infra": "docker compose -f ./docker-compose-infra.yml up -d",
11+
"dev:infra": "docker compose -f ./docker-compose.yml up -d",
1412
"dev:db": "yarn prisma:setup:dev",
15-
"dev:run": "nodemon --watch 'src/**/*.ts' --exec 'npx tsx ./src/index.ts' --files src/index.ts",
13+
"dev:run": "npx nodemon --watch 'src/**/*.ts' --exec 'npx tsx ./src/index.ts' --files src/index.ts",
1614
"build": "rm -rf dist && tsc -p ./tsconfig.json --outDir dist",
15+
"build:docker": "docker build . -f Dockerfile -t prod",
1716
"generate:sdk": "npx tsx ./src/scripts/generate-sdk && cd ./sdk && yarn build",
1817
"prisma:setup:dev": "npx tsx ./src/scripts/setup-db.ts",
1918
"prisma:setup:prod": "npx tsx ./dist/scripts/setup-db.js",
2019
"start": "yarn prisma:setup:prod && yarn start:run",
2120
"start:run": "node --experimental-specifier-resolution=node ./dist/index.js",
22-
"start:docker": "docker compose build && docker compose --env-file ./.env up --remove-orphans",
23-
"docker-build-run": "docker compose build --no-cache && docker compose --env-file ./.env up --remove-orphans",
24-
"copy-files": "copyfiles -u 2 ./src/prisma/* ./dist/prisma/ && copyfiles -u 3 ./src/prisma/migrations/**/*.sql ./dist/prisma/migrations/",
25-
"lint": "eslint 'src/**/*.ts'",
21+
"start:docker": "docker compose --profile engine --env-file ./.env up --remove-orphans",
22+
"start:docker-force-build": "docker compose --profile engine --env-file ./.env up --remove-orphans --build",
2623
"lint:fix": "eslint --fix 'src/**/*.ts'",
27-
"test:load": "npx tsx ./test/load/index.ts",
28-
"test:load:benchmark": "npx tsx ./test/load/scripts/account.ts",
2924
"test:unit": "vitest",
3025
"test:coverage": "vitest run --coverage"
3126
},
@@ -37,7 +32,7 @@
3732
"@fastify/type-provider-typebox": "^3.2.0",
3833
"@fastify/websocket": "^8.2.0",
3934
"@google-cloud/kms": "^4.4.0",
40-
"@prisma/client": "^5.14.0-dev.65",
35+
"@prisma/client": "^5.14.0",
4136
"@sinclair/typebox": "^0.31.28",
4237
"@t3-oss/env-core": "^0.6.0",
4338
"@thirdweb-dev/auth": "^4.1.87",
@@ -50,7 +45,6 @@
5045
"bullmq": "^5.7.8",
5146
"cookie": "^0.5.0",
5247
"cookie-parser": "^1.4.6",
53-
"copyfiles": "^2.4.1",
5448
"cron-parser": "^4.9.0",
5549
"crypto": "^1.0.1",
5650
"crypto-js": "^4.2.0",
@@ -70,7 +64,7 @@
7064
"pg": "^8.11.3",
7165
"pino": "^8.15.1",
7266
"pino-pretty": "^10.0.0",
73-
"prisma": "5.14.0-dev.61",
67+
"prisma": "^5.14.0",
7468
"superjson": "^2.2.1",
7569
"thirdweb": "^5.39.0",
7670
"uuid": "^9.0.1",
@@ -91,13 +85,10 @@
9185
"@typescript-eslint/eslint-plugin": "^5.55.0",
9286
"@typescript-eslint/parser": "^5.55.0",
9387
"@vitest/coverage-v8": "^2.0.3",
94-
"commander": "^11.0.0",
9588
"eslint": "^9.3.0",
9689
"eslint-config-prettier": "^8.7.0",
97-
"nodemon": "^3.1.2",
9890
"openapi-typescript-codegen": "^0.25.0",
9991
"prettier": "^2.8.7",
100-
"ts-node": "^10.9.1",
10192
"typescript": "^5.1.3",
10293
"vitest": "^2.0.3"
10394
},

0 commit comments

Comments
 (0)