Last active
October 10, 2022 22:57
-
-
Save tswaters/27676f14d02132ad929a21fbbccae16e to your computer and use it in GitHub Desktop.
node dockerfile
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
.git | |
node_modules | |
dist | |
public |
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
# syntax = docker/dockerfile:1.4 | |
FROM node:18-bullseye-slim AS base | |
WORKDIR /app | |
COPY --link package.json package-lock.json /app/ | |
FROM base AS dependencies | |
RUN --mount=type=cache,target=/root/.npm npm ci --omit=dev | |
FROM base AS build | |
RUN --mount=type=cache,target=/root/.npm npm ci | |
COPY --link . /app | |
RUN npm run build | |
FROM gcr.io/distroless/nodejs:18 | |
COPY --link --from=build /app/dist /app/dist/ | |
COPY --link --from=dependencies /app/node_modules /app/node_modules | |
COPY --link . /app | |
EXPOSE 3000 | |
EXPOSE 9229 | |
CMD ["/app/dist/index.js"] |
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
#!/bin/bash | |
set -euxo pipefail | |
export DOCKER_BUILDKIT=1 | |
docker build . --target build --tag test-image:test | |
docker run --rm --entrypoint node test-image:test --version | |
docker run --rm --entrypoint npm test-image:test --version | |
docker run --rm --entrypoint npm test-image:test run test | |
docker run --rm --entrypoint npm test-image:test run lint | |
docker rmi test-image:test | |
docker build . --tag test-image:release | |
# push tags to remote |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated with using docker buildkit, distroless container for the release, and a few different caching options.