1+ # syntax=docker/dockerfile:1.4
2+
3+ # Build stage
4+ FROM node:22.1.0-alpine@sha256:487dc5d5122d578e13f2231aa4ac0f63068becd921099c4c677c850df93bede8 AS builder
5+
6+ # Set build-time variables for reproducibility
7+ ARG NODE_ENV=development
8+ ARG BUILD_VERSION=dev
9+ ARG BUILD_DATE=unknown
10+ ARG VCS_REF=unknown
11+ ARG PORT=3081
12+
13+ # Set environment variables
14+ ENV NODE_ENV=${NODE_ENV} \
15+ NODE_VERSION=22.1.0
16+
17+ # Set build-time labels
18+ LABEL org.opencontainers.image.created=${BUILD_DATE} \
19+ org.opencontainers.image.version=${BUILD_VERSION} \
20+ org.opencontainers.image.revision=${VCS_REF}
21+
22+ # Set consistent timezone and locale
23+ ENV TZ=UTC \
24+ LANG=C.UTF-8
25+
26+ # Create app directory
27+ WORKDIR /usr/src/app
28+
29+ # Install build dependencies
30+ RUN --mount=type=cache,target=/var/cache/apk \
31+ apk add --no-cache \
32+ python3 \
33+ make \
34+ g++ \
35+ gcc \
36+ linux-headers
37+
38+ # Copy dependency files
39+ COPY package.json yarn.lock ./
40+
41+ # Install dependencies with cache mount
42+ RUN --mount=type=cache,target=/usr/src/app/.yarn-cache \
43+ yarn install --frozen-lockfile --production=false --cache-folder /usr/src/app/.yarn-cache && \
44+ yarn cache clean && \
45+ rm -rf /usr/src/app/.yarn-cache/*
46+
47+ # Copy source code
48+ COPY . .
49+
50+ # Build TypeScript code with deterministic output
51+ RUN yarn build
52+
53+ FROM node:22.1.0-alpine@sha256:487dc5d5122d578e13f2231aa4ac0f63068becd921099c4c677c850df93bede8 AS production
54+
55+ # Declare build arguments in production stage
56+ ARG PORT=3081
57+ ARG NODE_ENV=development
58+
59+ # Set build-time labels
60+ LABEL org.opencontainers.image.created=${BUILD_DATE} \
61+ org.opencontainers.image.version=${BUILD_VERSION} \
62+ org.opencontainers.image.revision=${VCS_REF}
63+
64+ # Set runtime environment
65+ ENV NODE_ENV=${NODE_ENV} \
66+ PORT=${PORT} \
67+ TZ=UTC \
68+ LANG=C.UTF-8
69+
70+ WORKDIR /usr/src/app
71+
72+ # Create non-root user, certificate directory and logs directory
73+ RUN addgroup -S bitgo && \
74+ adduser -S bitgo -G bitgo && \
75+ mkdir -p /app/certs && \
76+ mkdir -p /usr/src/app/logs && \
77+ chown -R bitgo:bitgo /app/certs && \
78+ chown -R bitgo:bitgo /usr/src/app && \
79+ chmod 750 /app/certs && \
80+ chmod 750 /usr/src/app/logs
81+
82+ # Copy only necessary files from builder
83+ COPY --from=builder --chown=bitgo:bitgo /usr/src/app/dist ./dist
84+ COPY --from=builder --chown=bitgo:bitgo /usr/src/app/node_modules ./node_modules
85+ COPY --from=builder --chown=bitgo:bitgo /usr/src/app/bin ./bin
86+ COPY --from=builder --chown=bitgo:bitgo /usr/src/app/package.json .
87+
88+ USER bitgo
89+
90+ # Expose port from build arg
91+ EXPOSE ${PORT}
92+
93+ # Start the application using the binary
94+ CMD ["./bin/enclaved-bitgo-express" ]
0 commit comments