Skip to content

Instantly share code, notes, and snippets.

@linkdd
Last active August 19, 2022 20:07
Show Gist options
  • Save linkdd/2a19e51f6158e53e89ff525544ac3f04 to your computer and use it in GitHub Desktop.
Save linkdd/2a19e51f6158e53e89ff525544ac3f04 to your computer and use it in GitHub Desktop.

Revisions

  1. linkdd revised this gist Aug 19, 2022. No changes.
  2. linkdd created this gist May 12, 2022.
    62 changes: 62 additions & 0 deletions node.dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    # 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"]