Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

improvement(eng-4792): speed up prod docker build

Tre Dubravac97e1a507484
diff --git a/.github/workflows/release-standalone-docker-img-postgres-offical.yml b/.github/workflows/release-standalone-docker-img-postgres-offical.yml
index 9890196908..93cc55b594 100644
--- a/.github/workflows/release-standalone-docker-img-postgres-offical.yml
+++ b/.github/workflows/release-standalone-docker-img-postgres-offical.yml
@@ -21,7 +21,7 @@ jobs:
id: extract_version
run: echo "::set-output name=version::${GITHUB_REF_NAME}"
- name: ☁️ Checkout source
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📦 Install dependencies to test all dependencies
@@ -39,9 +39,9 @@ jobs:
id: commit
uses: pr-mpt/actions-commit-hash@v2
- name: 🔧 Set up Docker Buildx
- uses: docker/setup-buildx-action@v2
+ uses: docker/setup-buildx-action@v3
- name: 🐋 Login to Docker Hub
- uses: docker/login-action@v2
+ uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -84,7 +84,7 @@ jobs:
id: extract_version
run: echo "::set-output name=version::${GITHUB_REF_NAME}"
- name: ☁️ Checkout source
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📦 Install dependencies to test all dependencies
@@ -102,9 +102,9 @@ jobs:
id: commit
uses: pr-mpt/actions-commit-hash@v2
- name: 🔧 Set up Docker Buildx
- uses: docker/setup-buildx-action@v2
+ uses: docker/setup-buildx-action@v3
- name: 🐋 Login to Docker Hub
- uses: docker/login-action@v2
+ uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
diff --git a/Dockerfile.standalone-infisical b/Dockerfile.standalone-infisical
index 443bd5c26b..b9b29aa535 100644
--- a/Dockerfile.standalone-infisical
+++ b/Dockerfile.standalone-infisical
@@ -87,14 +87,12 @@ RUN npm i -g tsconfig-paths
ENV NODE_OPTIONS="--max-old-space-size=8192"
RUN npm run build
-# Production stage
-FROM base AS backend-runner
-
-ENV ChrystokiConfigurationPath=/usr/safenet/lunaclient/
+# Production dependencies (runs in parallel with backend-build)
+FROM base AS backend-prod-deps
WORKDIR /app
-# Install all required dependencies for runtime
+# Install build tools needed to compile native modules during npm ci
RUN apt-get update && apt-get install -y \
python3 \
make \
@@ -106,39 +104,48 @@ RUN apt-get update && apt-get install -y \
freetds-dev \
&& rm -rf /var/lib/apt/lists/*
+COPY backend/package*.json ./
+RUN npm ci --omit=dev
+
+# Production stage
+FROM base AS backend-runner
+
+ENV ChrystokiConfigurationPath=/usr/safenet/lunaclient/
+
+WORKDIR /app
+
+# Only runtime libraries needed — no compilation happens here
+RUN apt-get update && apt-get install -y \
+ unixodbc \
+ freetds-bin \
+ && rm -rf /var/lib/apt/lists/*
+
# Configure ODBC
RUN printf "[FreeTDS]\nDescription = FreeTDS Driver\nDriver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so\nSetup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so\nFileUsage = 1\n" > /etc/odbcinst.ini
COPY --from=backend-build /app .
RUN rm -rf ./node_modules ./bdd ./e2e-test
-RUN npm ci --omit=dev
+COPY --from=backend-prod-deps /app/node_modules ./node_modules
RUN mkdir frontend-build
# Production stage
FROM base AS production
+# Only runtime dependencies — no compilation happens in this stage
RUN apt-get update && apt-get install -y \
- build-essential \
- autoconf \
- automake \
- libtool \
- libssl-dev \
ca-certificates \
bash \
curl \
git \
- python3 \
- make \
- g++ \
unixodbc \
freetds-bin \
- unixodbc-dev \
- libc-dev \
- freetds-dev \
wget \
perl \
openssh-client \
+ libaio1t64 \
+ unzip \
+ smbclient \
&& rm -rf /var/lib/apt/lists/*
# Install Oracle Instant Client for OracleDB mTLS wallet support
@@ -147,7 +154,6 @@ RUN ARCH=$(dpkg --print-architecture) && \
ORACLE_ZIP="instantclient-basic-linux.x64-23.26.0.0.0.zip" && \
ORACLE_URL="https://download.oracle.com/otn_software/linux/instantclient/2326000/${ORACLE_ZIP}" && \
EXPECTED_SHA="d6c79cbcf0ff209363e779855c690d4fc730aed847e9198a2c439bcf34760af5" && \
- apt-get update && apt-get install -y libaio1t64 unzip && \
ln -sf /lib/x86_64-linux-gnu/libaio.so.1t64 /lib/x86_64-linux-gnu/libaio.so.1 && \
wget -q "$ORACLE_URL" && \
echo "$EXPECTED_SHA $ORACLE_ZIP" | sha256sum -c - && \
@@ -157,7 +163,6 @@ RUN ARCH=$(dpkg --print-architecture) && \
ORACLE_ZIP="instantclient-basic-linux.arm64-23.26.0.0.0.zip" && \
ORACLE_URL="https://download.oracle.com/otn_software/linux/instantclient/2326000/${ORACLE_ZIP}" && \
EXPECTED_SHA="9c9a32051e97f087016fb334b7ad5c0aea8511ca8363afd8e0dc6ec4fc515c32" && \
- apt-get update && apt-get install -y libaio1t64 unzip && \
ln -sf /lib/aarch64-linux-gnu/libaio.so.1t64 /lib/aarch64-linux-gnu/libaio.so.1 && \
wget -q "$ORACLE_URL" && \
echo "$EXPECTED_SHA $ORACLE_ZIP" | sha256sum -c - && \
@@ -165,11 +170,7 @@ RUN ARCH=$(dpkg --print-architecture) && \
rm "$ORACLE_ZIP"; \
fi && \
echo /opt/oracle/instantclient_23_26 > /etc/ld.so.conf.d/oracle-instantclient.conf && \
- ldconfig && \
- rm -rf /var/lib/apt/lists/*
-
-# Install smbclient for Windows SMB operations
-RUN apt-get update && apt-get install -y smbclient && rm -rf /var/lib/apt/lists/*
+ ldconfig
# Build OpenSSL 3.5.6 for PQC (ML-DSA / SLH-DSA) certificate support.
# Installed to /opt/openssl-pqc so it does not conflict with the system OpenSSL.
@@ -199,12 +200,10 @@ RUN groupadd --system --gid 1001 nodejs \
&& useradd --system --uid 1001 --gid nodejs non-root-user
# Give non-root-user permission to update SSL certs
-RUN chown -R non-root-user /etc/ssl/certs
-RUN chown non-root-user /etc/ssl/certs/ca-certificates.crt
-RUN chmod -R u+rwx /etc/ssl/certs
-RUN chmod u+rw /etc/ssl/certs/ca-certificates.crt
-RUN chown non-root-user /usr/sbin/update-ca-certificates
-RUN chmod u+rx /usr/sbin/update-ca-certificates
+RUN chown -R non-root-user /etc/ssl/certs \
+ && chmod -R u+rwx /etc/ssl/certs \
+ && chown non-root-user /usr/sbin/update-ca-certificates \
+ && chmod u+rx /usr/sbin/update-ca-certificates
## set pre baked keys
ARG POSTHOG_API_KEY
diff --git a/backend/Dockerfile b/backend/Dockerfile
index ad555bb8d6..992375e8ca 100644
--- a/backend/Dockerfile
+++ b/backend/Dockerfile
@@ -3,48 +3,60 @@ FROM node:22.22.0-trixie-slim AS build
WORKDIR /app
-# Required for pkcs11js
+# Required for pkcs11js and TDS driver (SAP ASE dynamic secrets)
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
openssh-client \
- openssl
-
-# Install dependencies for TDS driver (required for SAP ASE dynamic secrets)
-RUN apt-get install -y \
+ openssl \
unixodbc \
freetds-bin \
freetds-dev \
unixodbc-dev \
- libc-dev
+ libc-dev \
+ && rm -rf /var/lib/apt/lists/*
COPY package*.json ./
-RUN npm ci --only-production
+RUN npm ci
COPY . .
RUN npm run build
-# Production stage
-FROM node:22.22.0-trixie-slim
-WORKDIR /app
-
-ENV npm_config_cache /home/node/.npm
+# Production dependencies (runs in parallel with build)
+FROM node:22.22.0-trixie-slim AS prod-deps
-COPY package*.json ./
+WORKDIR /app
+# Build tools needed to compile native modules during npm ci
RUN apt-get update && apt-get install -y \
python3 \
make \
- g++
-
-# Install dependencies for TDS driver (required for SAP ASE dynamic secrets)
-RUN apt-get install -y \
+ g++ \
unixodbc \
freetds-bin \
freetds-dev \
unixodbc-dev \
- libc-dev
+ libc-dev \
+ && rm -rf /var/lib/apt/lists/*
+
+COPY package*.json ./
+RUN npm ci --omit=dev
+
+# Production stage
+FROM node:22.22.0-trixie-slim
+WORKDIR /app
+
+ENV npm_config_cache /home/node/.npm
+
+# Only runtime dependencies — no compilation happens here
+RUN apt-get update && apt-get install -y \
+ unixodbc \
+ freetds-bin \
+ libaio1t64 \
+ unzip \
+ wget \
+ && rm -rf /var/lib/apt/lists/*
RUN printf "[FreeTDS]\nDescription = FreeTDS Driver\nDriver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so\nSetup = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so\nFileUsage = 1\n" > /etc/odbcinst.ini
@@ -54,7 +66,6 @@ RUN ARCH=$(dpkg --print-architecture) && \
ORACLE_ZIP="instantclient-basic-linux.x64-23.26.0.0.0.zip" && \
ORACLE_URL="https://download.oracle.com/otn_software/linux/instantclient/2326000/${ORACLE_ZIP}" && \
EXPECTED_SHA="d6c79cbcf0ff209363e779855c690d4fc730aed847e9198a2c439bcf34760af5" && \
- apt-get update && apt-get install -y libaio1t64 unzip wget && \
ln -sf /lib/x86_64-linux-gnu/libaio.so.1t64 /lib/x86_64-linux-gnu/libaio.so.1 && \
wget -q "$ORACLE_URL" && \
echo "$EXPECTED_SHA $ORACLE_ZIP" | sha256sum -c - && \
@@ -64,7 +75,6 @@ RUN ARCH=$(dpkg --print-architecture) && \
ORACLE_ZIP="instantclient-basic-linux.arm64-23.26.0.0.0.zip" && \
ORACLE_URL="https://download.oracle.com/otn_software/linux/instantclient/2326000/${ORACLE_ZIP}" && \
EXPECTED_SHA="9c9a32051e97f087016fb334b7ad5c0aea8511ca8363afd8e0dc6ec4fc515c32" && \
- apt-get update && apt-get install -y libaio1t64 unzip wget && \
ln -sf /lib/aarch64-linux-gnu/libaio.so.1t64 /lib/aarch64-linux-gnu/libaio.so.1 && \
wget -q "$ORACLE_URL" && \
echo "$EXPECTED_SHA $ORACLE_ZIP" | sha256sum -c - && \
@@ -72,13 +82,11 @@ RUN ARCH=$(dpkg --print-architecture) && \
rm "$ORACLE_ZIP"; \
fi && \
echo /opt/oracle/instantclient_23_26 > /etc/ld.so.conf.d/oracle-instantclient.conf && \
- ldconfig && \
- rm -rf /var/lib/apt/lists/*
-
-RUN npm ci --only-production && npm cache clean --force
+ ldconfig
COPY --from=build /app .
-RUN rm -rf ./bdd ./e2e-test
+RUN rm -rf ./node_modules ./bdd ./e2e-test
+COPY --from=prod-deps /app/node_modules ./node_modules
# Install smbclient for Windows SMB operations
RUN apt-get update && apt-get install -y smbclient