Created
February 24, 2022 00:23
-
-
Save nwesterhausen/5820044f1777b5faa67e146912b3811e to your computer and use it in GitHub Desktop.
Dockerize nodejs, pnpm using distroless
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ignore All | |
* | |
# Allow Some | |
!bin/www | |
!db/** | |
!public/** | |
!routes/** | |
!util/** | |
!views/** | |
!app.js | |
!package.json | |
!pnpm-lock.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "build" app with full node container | |
FROM registry.hub.docker.com/library/node:16 AS build-env | |
# Default working directory | |
WORKDIR /app | |
# Download and install PNPM | |
RUN curl -f https://get.pnpm.io/v6.16.js | \ | |
node - add --global pnpm | |
# pnpm fetch does require only lockfile | |
COPY pnpm-lock.yaml ./ | |
RUN pnpm fetch --prod | |
# Bundle app source (use a .dockerignore file to only move what you want) | |
ADD . ./ | |
# Install using fetched data from lockfile | |
RUN pnpm install -r --offline --prod | |
# Move "built" app into distroless node container | |
FROM gcr.io/distroless/nodejs:16 | |
COPY --from=build-env /app /app | |
WORKDIR /app | |
# Include ENV and VOLUME stuff here. | |
CMD ["./bin/www"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment