Last active
August 19, 2022 20:07
-
-
Save linkdd/2a19e51f6158e53e89ff525544ac3f04 to your computer and use it in GitHub Desktop.
Javascript SPA with NginX dockerfile
This file contains 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
# Tooling configuration files | |
FROM scratch AS context | |
ADD package.json \ | |
yarn.lock \ | |
.eslintrc.js \ | |
.eslintignore \ | |
/workspace/ | |
# Source code | |
FROM scratch AS sources | |
ADD src /workspace/src | |
# Install dependencies | |
FROM node:alpine AS dependencies | |
COPY --from=context /workspace/package.json /workspace/package.json | |
COPY --from=context /workspace/yarn.lock /workspace/yarn.lock | |
WORKDIR /workspace | |
RUN yarn install --network-timeout 300000 --production | |
# Install dev dependencies | |
FROM node:alpine AS dev-dependencies | |
COPY --from=dependencies /workspace /workspace | |
WORKDIR /workspace | |
RUN yarn install --network-timeout 300000 | |
# Lint | |
FROM node:alpine AS linter | |
COPY --from=context /workspace /workspace | |
COPY --from=dev-dependencies /workspace/node_modules /workspace/node_modules | |
COPY --from=sources /workspace/src /workspace/src | |
WORKDIR /workspace | |
RUN yarn run lint | |
# Build | |
FROM node:alpine AS builder | |
COPY --from=context /workspace /workspace | |
COPY --from=dev-dependencies /workspace/node_modules /workspace/node_modules | |
COPY --from=sources /workspace/src /workspace/src | |
WORKDIR /workspace | |
RUN yarn run build | |
# Final artifact | |
FROM nginx:alpine AS runner | |
COPY --from=builder /workspace/dist/spa /usr/share/nginx/html | |
WORKDIR /workspace | |
ADD entrypoint.sh /workspace/entrypoint.sh | |
EXPOSE 8000 | |
CMD ["/bin/sh", "/workspace/entrypoint.sh"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment