forked from farcasterxyz/hub-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
58 lines (39 loc) · 2.05 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This docker file uses a multi-stage build pattern as described here:
# https://github.com/goldbergyoni/nodebestpractices/blob/master/sections/docker/multi_stage_builds.md
###############################################################################
############## Stage 1: Build the code using a full node image ################
###############################################################################
FROM node:18 AS build
USER node
WORKDIR /home/node/app
# Copy dependency information and install all dependencies
COPY --chown=node:node tsconfig.json package.json yarn.lock ./
RUN yarn install --frozen-lockfile --network-timeout 1800000
# Copy source code (and all other relevant files)
COPY --chown=node:node src ./src
COPY --chown=node:node .config ./.config
# Build code
RUN yarn build
###############################################################################
########## Stage 2: Copy over the built code to a leaner alpine image #########
###############################################################################
FROM node:18-alpine
RUN apk update && apk add --no-cache g++ make python3 linux-headers
# Set non-root user and expose port 8080
USER node
EXPOSE 8080
# Many npm packages use this to trigger production optimized behaviors
ENV NODE_ENV production
WORKDIR /home/node/app
# Copy dependency information and install dependencies
COPY --chown=node:node tsconfig.json package.json yarn.lock ./
RUN yarn install --frozen-lockfile --production --network-timeout 1800000
# Copy results from previous stage
COPY --chown=node:node --from=build /home/node/app/build ./build
COPY --chown=node:node --from=build /home/node/app/.config ./.config
# TODO: determine if this can be removed while using tsx (or find alternative)
# since we should be able to run with just the compiled javascript in build/
COPY --chown=node:node --from=build /home/node/app/src ./src
# TODO: load identity from some secure store instead of generating a new one
RUN yarn identity create
CMD ["yarn", "tsx", "src/cli.ts", "start", "--rpc-port", "8080", "--gossip-port", "9090" ]