From 7006309eb58547347c25cc845da37ac966752d71 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Tue, 21 May 2024 00:54:09 -0400 Subject: [PATCH] build: fix dockerfile --- Dockerfile | 41 ++++++++++++++++++++--------------------- package.json | 2 +- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 364f8a8..846d9eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,17 +15,30 @@ ARG NODE_VER=20-alpine ARG DIR=/usr/src/app/ -FROM node:$NODE_VER AS install +FROM node:$NODE_VER AS base ARG DIR +# Install needed packages +RUN apk add --no-cache \ + dumb-init + WORKDIR ${DIR} COPY ./.yarn ${DIR}.yarn COPY ./package.json ./yarn.lock ./.yarnrc.yml ${DIR} +RUN chown -R node:node ${DIR} +# Do not run service as root +USER node + RUN yarn workspaces focus --all --production -FROM install AS build +# Launch entrypoint with dumb-init +# Remap SIGTERM to SIGINT https://github.com/Yelp/dumb-init#signal-rewriting +ENTRYPOINT ["/usr/bin/dumb-init", "--rewrite", "15:2", "--", "yarn", "run"] +CMD ["start"] + +FROM base AS build ARG DIR # Install dev deps too @@ -33,25 +46,11 @@ RUN yarn install --immutable COPY . ${DIR} -# Build code and remove dev deps -RUN yarn build --verbose && rm -rfv .yarn .pnp* +# Build code +RUN yarn build --verbose -FROM node:$NODE_VER AS production +FROM base AS production ARG DIR -# Install needed packages -RUN apk add --no-cache \ - dumb-init - -# Do not run service as root -USER node - -WORKDIR ${DIR} - -COPY --from=install ${DIR} ${DIR} -COPY --from=build ${DIR} ${DIR} - -# Launch entrypoint with dumb-init -# Remap SIGTERM to SIGINT https://github.com/Yelp/dumb-init#signal-rewriting -ENTRYPOINT ["/usr/bin/dumb-init", "--rewrite", "15:2", "--", "yarn", "run"] -CMD ["start"] +# Copy in build code +COPY --from=build ${DIR}/dist ${DIR}/dist diff --git a/package.json b/package.json index 26768bf..1b223ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@trellisfw/monitor", - "version": "2.2.0", + "version": "2.2.2", "description": "A Trellis microservice to respond to monitor pings, spawn and check things internally, and respond with success or fail", "main": "dist/index.js", "type": "module",