From 5090797f199c4499921126133fc3e5ad4c142060 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Tue, 10 Dec 2019 01:28:46 -0500 Subject: Add multi-stage dockerfile as node:alpine image --- .dockerignore | 6 ++++++ CHANGELOG.md | 1 + Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..de6bbd2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.vscode +build +.env* +dist +node_modules \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d2b7ef3..036104e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Scripts added: `start:dev` for integrated watcher, `start:prod` for running server as production - Formatting and linting scripts - Template file converter, and bash template for serving +- Multi-stage dockerfile ### Changed diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..31b60f5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1. Base +FROM node:carbon AS base +WORKDIR /app + +# Stage 2. Dependencies +FROM base AS dependencies +COPY package*.json ./ +RUN npm install + +# Stage 3. TS compilation +FROM dependencies AS build +COPY src /app/src +COPY tsconfig.json /app +RUN npm run tsc + +# Stage 4. Release Image +FROM node:alpine AS release +WORKDIR /app + +COPY --from=dependencies /app/package.json ./ +RUN npm install --only=production +COPY --from=build /app/build ./build +COPY public ./public + +ENV NODE_ENV=production \ + PORT=8080 \ + BIND_ADDRESS=0.0.0.0 \ + UPLOAD_LIMIT=134217700 \ + LOG_LEVEL=info \ + HOST_DIR=/data + +RUN mkdir -p ${HOST_DIR} +VOLUME [ ${HOST_DIR} ] +EXPOSE ${PORT} + +CMD [ "node", "./build/index.js" ] \ No newline at end of file -- cgit