Merge pull request #205 from hugomd/chore/use-non-root-user

Trim Docker image size
This commit is contained in:
Mike Cao 2020-09-22 17:41:12 -07:00 committed by GitHub
commit bac2b32ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,17 +1,39 @@
FROM node:12.18-alpine # Build image
FROM node:12.18-alpine AS build
ARG DATABASE_TYPE ARG DATABASE_TYPE
ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" \ ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" \
DATABASE_TYPE=$DATABASE_TYPE DATABASE_TYPE=$DATABASE_TYPE
WORKDIR /build
WORKDIR /app COPY package.json yarn.lock /build/
EXPOSE 3000
COPY package.json yarn.lock /app/ # Install only the production dependencies
RUN yarn install --frozen-lockfile RUN yarn install --production
COPY . /app # Cache these modules for production
RUN cp -R node_modules/ prod_node_modules/
# Install development dependencies
RUN yarn install
COPY . /build
RUN yarn build RUN yarn build
# Production image
FROM node:12.18-alpine AS production
WORKDIR /app
# Copy cached dependencies
COPY --from=build /build/prod_node_modules ./node_modules
# Copy generated Prisma client
COPY --from=build /build/node_modules/\.prisma/ ./node_modules/\.prisma/
COPY --from=build /build/yarn.lock /build/package.json ./
COPY --from=build /build/.next ./.next
COPY --from=build /build/public ./public
USER node
EXPOSE 3000
CMD ["yarn", "start"] CMD ["yarn", "start"]