Skip to content

Instantly share code, notes, and snippets.

@aaberg
Created October 25, 2022 14:27
Show Gist options
  • Save aaberg/56ac7ed9e34502c45e6a1d1ecff526c7 to your computer and use it in GitHub Desktop.
Save aaberg/56ac7ed9e34502c45e6a1d1ecff526c7 to your computer and use it in GitHub Desktop.
Dockerfile for a svelte kit application
# Base image for
FROM node:16 as dependencies_base
ARG NPM_TOKEN
WORKDIR /app
COPY package*.json ./
RUN npm config set @aaberg:registry https://gitlab.com/api/v4/packages/npm/
RUN npm config set -- '//gitlab.com/api/v4/packages/npm/:_authToken' "${NPM_TOKEN}"
# Dependencies used for build
FROM dependencies_base as dependencies
RUN npm install --ignore-scripts
RUN npm audit fix
# Runtime dependencies used runtime
FROM dependencies_base as runtime_dependencies
RUN ls
RUN npm install --omit=dev --ignore-scripts
RUN ls node_modules
# Build
FROM node:16 as build
ARG NPM_TOKEN
WORKDIR /app
COPY --from=dependencies /app/node_modules ./node_modules
COPY . .
RUN npm install
RUN npm run build
# Application
FROM node:16-alpine as runner
WORKDIR /app
RUN node --version
COPY --from=build /app/package*.json ./
COPY --from=build /app/build .
COPY --from=runtime_dependencies /app/node_modules ./node_modules
USER node
EXPOSE 3000
ENV PORT 3000
ENV NODE_ENV Docker
CMD ["node", "index"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment