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