From ca99827a3f464f2358959638d30aa4ab45fec736 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Thu, 10 Mar 2022 16:38:12 -0600 Subject: [PATCH] Added Dockerfile. Fixed tscconfig file --- Dockerfile | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 7 +++- 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9975025 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,98 @@ +# -------------------------------------------------------------------------------------------------- +# NOTE: This Dockerfile was designed to be run with BuildKit. +# +# Enable BuildKit using: +# $ export DOCKER_BUILDKIT=1 +# $ export COMPOSE_DOCKER_CLI_BUILD=1 +# -------------------------------------------------------------------------------------------------- + +# The service to build +ARG SERVICE + +# The base image to use +ARG BASE=alpine + +# Base Definitions --------------------------------------------------------------------------------- + +# Alpine base definition +FROM node:14-alpine AS base-alpine +RUN mkdir /var/autoplex && chown node:node -R /var/autoplex + +# Alpine dev definition +FROM base-alpine AS base-alpine-dev +RUN apk add build-base python3 + +# Slim base definition +FROM node:14-slim AS base-slim +RUN mkdir /var/autoplex && chown node:node -R /var/autoplex +RUN apt-get update +RUN apt-get full-upgrade -y +RUN apt-get install -y libasound2 iputils-ping curl gnupg1 apt-transport-https dirmngr +RUN apt-get autoremove --purge -y +RUN rm -rf /var/lib/apt/lists/* + +# Slim dev definition +FROM base-slim AS base-slim-dev + +# Development Image -------------------------------------------------------------------------------- + +# Define the base image +FROM base-${BASE}-dev AS dev-base +ARG SERVICE +WORKDIR /app +ENV PATH "/app/node_modules/.bin:/app/services/${SERVICE}/node_modules/.bin:$PATH" +COPY lerna.json package.json yarn.lock ./ +RUN yarn install +COPY tsconfig*.json ./ + +# Define the dev image +FROM dev-base AS dev +ARG SERVICE +# RUN ln -s /opt/app/services/${SERVICE} /app +WORKDIR /app/services/${SERVICE} +CMD [ "yarn", "run", "start:dev" ] + +# Build Definitions -------------------------------------------------------------------------------- + +# Create the builder image with all dependencies +FROM base-${BASE}-dev AS builder-base +WORKDIR /app +RUN yarn global add lerna typescript rimraf +COPY docker/scripts docker/scripts +COPY lerna.json package.json tsconfig*.json ./ +RUN yarn install +COPY api api +COPY packages packages + +# Copy service package.json and patch files if they exist +FROM builder-base AS builder +ARG SERVICE +COPY services/${SERVICE}/package.json ./services/${SERVICE}/ +COPY services/${SERVICE}/patches* ./services/${SERVICE}/patches + +# Cache an image containing only the prod-dependencies +FROM builder AS prod-deps +ARG BASE +RUN lerna bootstrap -- --production --no-optional +RUN yarn run export:deps ${BASE} + +# Build the service +FROM builder AS build +ARG BASE +ARG SERVICE +COPY services/${SERVICE} ./services/${SERVICE} +RUN lerna clean --yes && lerna bootstrap && lerna run clean && lerna run build +RUN yarn run export:builds ${BASE} + +# Return to base image with the compiled files and production dependencies +FROM base-${BASE} AS prod +ARG SERVICE +WORKDIR /app +COPY --from=prod-deps /app/build /opt +COPY --from=build /app/build /opt +RUN for link in $(find /opt/services -type l); do dir=$(readlink -f $link); rm $link; ln -s $dir $link; done +RUN mv /opt/services/${SERVICE}/* /app && rm -rf /opt/services +# TODO: Should remove unnecessary packages that were included + +# Default entrypoint +CMD [ "yarn", "run", "start" ] diff --git a/tsconfig.json b/tsconfig.json index 5679481..d4e6714 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -97,5 +97,10 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "exclude": [ + "/**/node_modules", + "/**dist/**/*.ts", + "/**/test/**/*.ts" + ] }