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+ # 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={NODE_ENV} \
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 port from build arg
86+ EXPOSE ${PORT}
87+
88+ # Start the application using the binary
89+ CMD ["./bin/enclaved-bitgo-express" ]
0 commit comments