Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAP-2229 uof revert dockerfile changes #763

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 37 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,73 +1,66 @@
FROM node:22.12-bookworm-slim AS base
FROM node:22.12-bookworm-slim as builder

ARG BUILD_NUMBER
ARG GIT_REF
ARG GIT_BRANCH

LABEL maintainer="HMPPS Digital Studio <info@digital.justice.gov.uk>"

ENV TZ=Europe/London
RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone

RUN addgroup --gid 2000 --system appgroup && \
adduser --uid 2000 --system appuser --gid 2000

WORKDIR /app

# Cache breaking and ensure required build / git args defined
RUN test -n "$BUILD_NUMBER" || (echo "BUILD_NUMBER not set" && false)
RUN test -n "$GIT_REF" || (echo "GIT_REF not set" && false)
RUN test -n "$GIT_BRANCH" || (echo "GIT_BRANCH not set" && false)

# Define env variables for runtime health / info
ENV BUILD_NUMBER=${BUILD_NUMBER}
ENV GIT_REF=${GIT_REF}
ENV GIT_BRANCH=${GIT_BRANCH}

RUN apt-get update && \
apt-get upgrade -y && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
apt-get upgrade -y
RUN apt-get -y install g++ make python3 curl && rm -rf /var/lib/apt/lists/*

WORKDIR /app

RUN curl https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem \
> /app/root.cert

# Stage: build assets
FROM base AS build
COPY . .

ARG BUILD_NUMBER
ARG GIT_REF
ARG GIT_BRANCH
RUN CYPRESS_INSTALL_BINARY=0 npm ci --no-audit && \
npm run build && \
export BUILD_NUMBER=${BUILD_NUMBER:-1_0_0} && \
export GIT_REF=${GIT_REF:-dummy} && \
npm run record-build-info

COPY package*.json ./
RUN CYPRESS_INSTALL_BINARY=0 npm ci --no-audit
ENV NODE_ENV='production'
RUN npm prune --production

COPY . .
FROM node:22.12-bookworm-slim
LABEL maintainer="HMPPS Digital Studio <info@digital.justice.gov.uk>"

# Cache breaking
ENV BUILD_NUMBER ${BUILD_NUMBER:-1_0_0}

RUN apt-get update && \
apt-get upgrade -y && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

RUN npm run build
RUN npm prune --no-audit --omit=dev
RUN addgroup --gid 2000 --system appgroup && \
adduser --uid 2000 --system appuser --gid 2000

ENV TZ=Europe/London
RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone

# Stage: copy production assets and dependencies
FROM base
# Create app directory
RUN mkdir /app && chown appuser:appgroup /app
USER 2000
WORKDIR /app

COPY --from=build --chown=appuser:appgroup \
COPY --from=builder --chown=appuser:appgroup \
/app/package.json \
/app/package-lock.json \
/app/dist \
/app/root.cert \
/app/build-info.json \
./

COPY --from=build --chown=appuser:appgroup \
/app/dist ./dist
COPY --from=builder --chown=appuser:appgroup \
/app/assets ./assets

COPY --from=build --chown=appuser:appgroup \
COPY --from=builder --chown=appuser:appgroup \
/app/node_modules ./node_modules

COPY --from=builder --chown=appuser:appgroup \
/app/server/views ./server/views

ENV PORT=3000

EXPOSE 3000
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"watch-views": "nodemon --watch server/views -e html,njk -x npm run copy-views",
"watch-ts": "tsc -w",
"watch-node": "DEBUG=gov-starter-server* DB_PORT=5433 nodemon -r dotenv/config --watch dist/ dist/server.js | bunyan -o short",
"start": "node $NODE_OPTIONS dist/server.js | bunyan -o short",
"start:dev": "npm run build && concurrently -k -p \"[{name}]\" -n \"Views,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-views\" \"npm run watch-ts\" \"npm run watch-node\"",
"start-feature": "export $(cat feature.env) && node $NODE_DEBUG_OPTION dist/server.js | bunyan -o short",
"watch-node-feature": "export $(cat feature.env) && nodemon -r dotenv/config --watch dist/ $NODE_DEBUG_OPTION dist/server.js | bunyan -o short",
Expand Down
2 changes: 0 additions & 2 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ function get(name, fallback, options = {}) {
const requiredInProduction = { requireInProduction: true }

module.exports = {
buildNumber: get('BUILD_NUMBER', '1_0_0', requiredInProduction),

db: {
username: get('DB_USER', 'use-of-force'),
password: get('DB_PASS', 'use-of-force'),
Expand Down
Loading