Skip to content

Commit 2ac1c3b

Browse files
authored
Dockerfile & Docker Compose Updates (#267)
* refactored dockerfile for prod builds * updated Dockerfile to reduce prod image size. Updated docker compose * wallet balance params fixed, retry end-point updated
1 parent 693ddfd commit 2ac1c3b

File tree

6 files changed

+107
-49
lines changed

6 files changed

+107
-49
lines changed

.dockerignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ docker-compose*.yml
99
Dockerfile
1010
.DS_Store
1111
swagger.yml
12-
test
12+
test
13+
.dist
14+
.github
15+
.gitignore
16+
.git
17+
.coverage

Dockerfile

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,77 +10,119 @@ WORKDIR /app
1010
ENTRYPOINT ["/sbin/tini", "--"]
1111

1212
# Install build dependencies
13-
RUN apk --no-cache --virtual build-dependencies add g++ make py3-pip
13+
RUN apk --no-cache --virtual build-dependencies add g++ make py3-pip openssl
1414

1515
# Copy package.json and yarn.lock files
1616
COPY package*.json yarn*.lock ./
1717

1818
# Copy the entire project directory
1919
COPY . .
2020

21+
RUN npm install -g nodemon
22+
2123
# Install dependencies for both development and production
2224
RUN yarn install --frozen-lockfile --network-timeout 1000000
2325

24-
# Build the project
25-
RUN yarn build
26-
RUN yarn copy-files
26+
WORKDIR /app/https
27+
28+
RUN openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 \
29+
-subj "/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=localhost" \
30+
-passout pass:thirdweb-engine
31+
32+
RUN chmod 600 key.pem cert.pem
33+
34+
WORKDIR /app
2735

2836
# Clean up build dependencies
2937
RUN apk del build-dependencies
3038

31-
# Expose the necessary ports
32-
EXPOSE 3005
39+
##############################
40+
##############################
3341

3442
FROM base AS local_server
3543

44+
EXPOSE 3005
45+
3646
ENV NODE_ENV="local"
37-
CMD [ "yarn", "dev:server" ]
47+
CMD [ "sh", "-c","yarn prisma:setup:dev && yarn dev:server" ]
48+
49+
##############################
50+
##############################
3851

3952
FROM base AS local_worker
4053

4154
ENV NODE_ENV="local"
42-
CMD [ "yarn", "dev:worker" ]
55+
CMD [ "sh", "-c", "yarn prisma:setup:dev && yarn dev:worker" ]
4356

44-
# Production stage
45-
FROM node:18.15.0-alpine AS prod
46-
47-
# Install tini
48-
RUN apk add --no-cache tini
57+
##############################
58+
##############################
4959

50-
# Set the working directory
51-
WORKDIR /app
52-
53-
ENV NODE_ENV="production"
60+
# Production Node Modules stage
61+
FROM node:18.15.0-alpine AS prod-dependencies
5462

5563
# Install build dependencies
56-
RUN apk --no-cache --virtual build-dependencies add g++ make py3-pip
64+
RUN apk add --no-cache g++ make py3-pip openssl
65+
66+
WORKDIR /app
5767

5868
# Copy package.json and yarn.lock files
5969
COPY package*.json yarn*.lock ./
6070

61-
# Replace the schema path in the package.json file
62-
RUN sed -i 's_"schema": "./src/prisma/schema.prisma"_"schema": "./dist/src/prisma/schema.prisma"_g' package.json
71+
# Copy the entire project directory
72+
COPY . .
6373

64-
# Copy the built dist folder from the base stage to the production stage
65-
COPY --from=base /app/dist ./dist
74+
COPY --from=base /app/node_modules ./node_modules
75+
76+
# Build the project
77+
RUN yarn build
78+
RUN yarn copy-files
79+
80+
RUN rm -rf node_modules
81+
82+
# Install production dependencies only
83+
RUN yarn install --production=true --frozen-lockfile --network-timeout 1000000
6684

6785
# Generate SSL certificates
68-
RUN apk --update add openssl
6986
WORKDIR /app/dist/https
87+
7088
RUN openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 \
7189
-subj "/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=localhost" \
7290
-passout pass:thirdweb-engine
91+
7392
RUN chmod 600 key.pem cert.pem
74-
RUN apk del openssl
7593

76-
# Change Working Directory back to /app
94+
# Clean up build dependencies
95+
RUN apk del g++ make py3-pip openssl
96+
97+
##############################
98+
##############################
99+
100+
# Production stage
101+
FROM node:18.15.0-alpine AS prod
102+
103+
# Install tini
104+
RUN apk add --no-cache tini
105+
106+
# Set the working directory
77107
WORKDIR /app
78108

79-
# Install production dependencies only
80-
RUN yarn install --production=true --frozen-lockfile --network-timeout 1000000
109+
ENV NODE_ENV="production"
81110

82-
# Clean up build dependencies
83-
RUN apk del build-dependencies
111+
EXPOSE 3005
112+
113+
# Copy package.json and yarn.lock files
114+
COPY package*.json yarn*.lock ./
115+
116+
# Replace the schema path in the package.json file
117+
RUN sed -i 's_"schema": "./src/prisma/schema.prisma"_"schema": "./dist/src/prisma/schema.prisma"_g' package.json
118+
119+
# Copy only production dependencies from the prod-dependencies stage
120+
COPY --from=prod-dependencies /app/node_modules ./node_modules
121+
COPY --from=prod-dependencies /app/dist ./dist
122+
COPY --from=prod-dependencies /app/dist/https ./dist/https
123+
124+
# Add the node_modules/.bin directory to the PATH
125+
ENV PATH /app/node_modules/.bin:$PATH
84126

85127
# Use tini as entrypoint to handle killing processes
86128
ENTRYPOINT ["/sbin/tini", "--"]

docker-compose-infra.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ version: "3.8"
33
services:
44
db:
55
image: postgres:latest
6-
env_file:
7-
- .env
86
volumes:
97
- psql_db:/var/lib/postgresql/data
108
ports:

docker-compose.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,42 @@ services:
2525
dockerfile: Dockerfile
2626
context: .
2727
target: local_server
28+
env_file:
29+
- .env
2830
ports:
2931
- 3005:3005
30-
volumes:
31-
- ./:/app
32-
- node_modules:/app/node_modules
32+
depends_on:
33+
- db
34+
deploy:
35+
resources:
36+
limits:
37+
cpus: "1"
38+
memory: 1024M
39+
# volumes:
40+
# - ./:/app
41+
# - node_modules:/app/node_modules
3342

3443
engine-worker:
3544
build:
3645
dockerfile: Dockerfile
3746
context: .
3847
target: local_worker
48+
env_file:
49+
- .env
3950
ports:
4051
- 3006:3006
41-
volumes:
42-
- ./:/app
43-
- node_modules:/app/node_modules
52+
depends_on:
53+
- db
54+
deploy:
55+
resources:
56+
limits:
57+
cpus: "1"
58+
memory: 1024M
59+
# volumes:
60+
# - ./:/app
61+
# - node_modules:/app/node_modules
4462

4563
volumes:
46-
node_modules:
64+
# node_modules:
4765
db_data:
4866
pgadmin:

server/api/backend-wallet/getBalance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function getBalance(fastify: FastifyInstance) {
3737
Reply: Static<typeof responseSchema>;
3838
}>({
3939
method: "GET",
40-
url: "/backend-wallet/:chain/:wallet_address/get-balance",
40+
url: "/backend-wallet/:chain/:walletAddress/get-balance",
4141
schema: {
4242
summary: "Get balance",
4343
description: "Get the native balance for a backend wallet.",

server/api/transaction/retry.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import { retryTx } from "../../../src/db/transactions/retryTx";
55
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
66

77
// INPUT
8-
const requestSchema = Type.Object({
8+
9+
const requestBodySchema = Type.Object({
910
queueId: Type.String({
1011
description: "Transaction Queue ID",
1112
examples: ["9eb88b00-f04f-409b-9df7-7dcc9003bc35"],
1213
}),
13-
});
14-
15-
const requestBodySchema = Type.Object({
1614
maxFeePerGas: Type.String(),
1715
maxPriorityFeePerGas: Type.String(),
1816
});
@@ -35,27 +33,24 @@ responseBodySchema.example = {
3533

3634
export async function retryTransaction(fastify: FastifyInstance) {
3735
fastify.route<{
38-
Params: Static<typeof requestSchema>;
3936
Body: Static<typeof requestBodySchema>;
4037
Reply: Static<typeof responseBodySchema>;
4138
}>({
4239
method: "POST",
43-
url: "/transaction/retry/:queueId",
40+
url: "/transaction/retry",
4441
schema: {
4542
summary: "Retry transaction",
4643
description: "Retry a transaction with updated gas settings.",
4744
tags: ["Transaction"],
4845
operationId: "retry",
49-
params: requestSchema,
5046
body: requestBodySchema,
5147
response: {
5248
...standardResponseSchema,
5349
[StatusCodes.OK]: responseBodySchema,
5450
},
5551
},
5652
handler: async (request, reply) => {
57-
const { queueId } = request.params;
58-
const { maxFeePerGas, maxPriorityFeePerGas } = request.body;
53+
const { queueId, maxFeePerGas, maxPriorityFeePerGas } = request.body;
5954

6055
await retryTx({
6156
queueId: queueId,

0 commit comments

Comments
 (0)