rewrite dockerfile to be multi-stage
This commit is contained in:
parent
3ccbaade89
commit
4973c66e77
1 changed files with 15 additions and 14 deletions
29
Dockerfile
29
Dockerfile
|
@ -1,28 +1,29 @@
|
|||
FROM node:lts-slim as runtime
|
||||
FROM node:lts AS base
|
||||
WORKDIR /app
|
||||
|
||||
# Ensure that both node_modules and package-lock.json are removed.
|
||||
COPY package.json .
|
||||
RUN rm -rf node_modules
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
# Perform a fresh installation of npm dependencies.
|
||||
RUN npm install
|
||||
FROM base AS prod-deps
|
||||
RUN npm ci --omit=dev
|
||||
|
||||
FROM base AS build-deps
|
||||
RUN npm ci
|
||||
|
||||
FROM build-deps AS build
|
||||
|
||||
# Copy the rest of your application files.
|
||||
COPY . .
|
||||
|
||||
ARG POCKETBASE_URL
|
||||
ARG PORT=4321
|
||||
# Set environment variables and expose the appropriate port.
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=${PORT}
|
||||
ENV POCKETBASE_URL=${POCKETBASE_URL}
|
||||
|
||||
# Build your application.
|
||||
RUN npm run build
|
||||
|
||||
FROM base AS runtime
|
||||
COPY --from=prod-deps /app/node_modules ./node_modules
|
||||
COPY --from=build /app/dist ./dist
|
||||
|
||||
ARG PORT=4321
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=${PORT}
|
||||
EXPOSE ${PORT}
|
||||
|
||||
# Define the command to run your application.
|
||||
CMD node ./dist/server/entry.mjs
|
Loading…
Add table
Reference in a new issue