Skip to content

Commit

Permalink
Two stage docker build (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellabitta authored Jan 6, 2025
1 parent 51a8ae3 commit 7d66a66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:22-slim
RUN apt update \
&& apt --no-install-recommends install -y curl \
&& apt clean
# Our first stage, that is the Builder
FROM node:22-slim AS thumbnail-api-builder
WORKDIR /opt/thumbnail-api
COPY src /opt/thumbnail-api/src
COPY package.json /opt/thumbnail-api
COPY package-lock.json /opt/thumbnail-api
COPY tsconfig.json /opt/thumbnail-api
COPY eslint.config.mjs /opt/thumbnail-api
RUN npm install --ignore-scripts && npm run clean && npm run build

FROM node:22-slim AS thumbnail-api-prod
RUN apt update \
&& apt --no-install-recommends install -y curl \
&& apt clean
WORKDIR /opt/thumbnail-api
COPY package.json .
COPY package-lock.json .
COPY --from=thumbnail-api-builder /opt/thumbnail-api/dist /opt/thumbnail-api/dist
RUN chown -R node:node /opt/thumbnail-api
USER node
EXPOSE 3000
HEALTHCHECK CMD ["curl", "-f", "http://localhost:3000/health"]
RUN npm run clean \
&& npm ci --ignore-scripts \
&& npm run build
RUN npm install --omit=dev --omit=optional --ignore-scripts
CMD ["npm", "run", "start", "-s"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build": "tsc",
"clean": "rm -r dist thumbnail-api.zip 2> /dev/null ; exit 0",
"clean": "rm -r dist 2> /dev/null ; exit 0",
"start": "node dist/src/main.js",
"lint": "npx eslint",
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
Expand Down

0 comments on commit 7d66a66

Please sign in to comment.