Skip to content

Commit 1c0bc81

Browse files
committed
Refactor Dockerfiles to use node:22-alpine and optimize npm install with cache
1 parent e111f43 commit 1c0bc81

2 files changed

Lines changed: 7 additions & 27 deletions

File tree

infra/bigquery-export/Dockerfile

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
# checkov:skip=CKV_DOCKER_3:Ensure that a user for the container has been created
2-
FROM node:22-slim
1+
FROM node:22-alpine
32

4-
# Set the working directory
53
WORKDIR /app
64

7-
# Create a non-root user
8-
RUN groupadd -r appuser && useradd -r -g appuser appuser
5+
RUN addgroup -S appuser && adduser -S -G appuser appuser
96

10-
# Copy package files first for better layer caching
117
COPY package*.json ./
128

13-
# Install dependencies (this layer will be cached unless package files change)
14-
RUN npm ci --only=production --quiet --no-fund --no-audit && npm cache clean --force
9+
RUN --mount=type=cache,target=/root/.npm npm ci --only=production --quiet --no-fund --no-audit && npm cache clean --force
1510

1611
ENV EXPORT_CONFIG=""
1712

18-
# Copy source code
1913
COPY . .
2014

21-
# Change ownership of the app directory to the non-root user
2215
RUN chown -R appuser:appuser /app
2316

24-
# Switch to non-root user
2517
USER appuser
2618

27-
# No healthcheck needed for one-time job containers
2819
HEALTHCHECK NONE
2920

3021
CMD ["node", "index.js"]

infra/dataform-service/Dockerfile

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
1-
FROM node:22-slim
1+
FROM node:22-alpine
22

3-
# Set the working directory
43
WORKDIR /app
54

6-
# Create a non-root user
7-
RUN groupadd -r appuser && useradd -r -g appuser appuser
5+
RUN addgroup -S appuser && adduser -S -G appuser appuser
86

9-
# Copy package files first for better layer caching
107
COPY package*.json ./
118

12-
# Install dependencies (this layer will be cached unless package files change)
13-
RUN npm ci --only=production --quiet --no-fund --no-audit && npm cache clean --force
9+
RUN --mount=type=cache,target=/root/.npm npm ci --only=production --quiet --no-fund --no-audit && npm cache clean --force
1410

15-
# Copy source code
1611
COPY . .
1712

18-
# Change ownership of the app directory to the non-root user
1913
RUN chown -R appuser:appuser /app
2014

21-
# Switch to non-root user
2215
USER appuser
2316

24-
# Set default port (Cloud Run will override this)
2517
ENV PORT=8080
2618

27-
# Expose port for Cloud Run
2819
EXPOSE 8080
2920

30-
# Add healthcheck
3121
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
3222
CMD node -e "require('http').get('http://localhost:$PORT/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => { process.exit(1) })" || exit 1
3323

34-
# Start the function
35-
CMD ["npm", "start"]
24+
CMD ["npx", "functions-framework", "--target=dataform-service"]

0 commit comments

Comments
 (0)