Skip to content

Commit

Permalink
[POC]: Add esbuild and update enhanced dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
branberry committed Sep 14, 2023
1 parent 702b864 commit ad7694a
Show file tree
Hide file tree
Showing 7 changed files with 1,907 additions and 125 deletions.
73 changes: 41 additions & 32 deletions Dockerfile.enhanced
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
# Build the Typescript app
FROM node:18.16.0-alpine as ts-compiler
WORKDIR /home/docsworker-xlarge
COPY config config/
COPY package*.json ./
COPY tsconfig*.json ./
RUN npm ci --legacy-peer-deps
COPY . ./
RUN npm run build

# install persistence module
RUN cd ./modules/persistence \
&& npm ci --legacy-peer-deps \
&& npm run build

# Build modules
# OAS Page Builder
RUN cd ./modules/oas-page-builder \
&& npm ci --legacy-peer-deps \
&& npm run build

# where repo work will happen
FROM ubuntu:20.04
FROM ubuntu:20.04 as dependency-installer
ARG WORK_DIRECTORY=/home/docsworker-xlarge
ARG SNOOTY_PARSER_VERSION=0.14.6
ARG SNOOTY_FRONTEND_VERSION=0.14.13
Expand Down Expand Up @@ -59,11 +38,11 @@ RUN npm install -g npm@8

# install snooty parser
RUN curl -L -o snooty-parser.zip https://github.com/mongodb/snooty-parser/releases/download/v${SNOOTY_PARSER_VERSION}/snooty-v${SNOOTY_PARSER_VERSION}-linux_x86_64.zip \
&& unzip -d /opt/ snooty-parser.zip
&& unzip snooty-parser.zip

# install mut
RUN curl -L -o mut.zip https://github.com/mongodb/mut/releases/download/v${MUT_VERSION}/mut-v${MUT_VERSION}-linux_x86_64.zip \
&& unzip -d /opt/ mut.zip
&& unzip mut.zip

# setup user and root directory
RUN useradd -ms /bin/bash docsworker-xlarge
Expand Down Expand Up @@ -91,30 +70,60 @@ RUN git clone -b @dop/redoc-cli@${REDOC_CLI_VERSION} --depth 1 https://github.co
&& cd redoc/ \
&& npm ci --prefix cli/ --omit=dev

COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/package*.json ./
COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/config config/
COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/build ./
RUN npm install
# Build the Typescript app
FROM node:18.16.0-alpine as ts-compiler
WORKDIR /home/docsworker-xlarge
COPY config config/
COPY package*.json ./
COPY tsconfig*.json ./
RUN npm ci --legacy-peer-deps
COPY . ./
RUN npm run build:enhanced

# install persistence module
RUN cd ./modules/persistence \
&& npm ci --legacy-peer-deps \
&& npm run build:enhanced

# Build modules
# OAS Page Builder
RUN cd ./modules/oas-page-builder \
&& npm ci --legacy-peer-deps \
&& npm run build:enhanced

FROM node:18.16.0-alpine
ARG WORK_DIRECTORY=/home/docsworker-xlarge

COPY --from=dependency-installer --chown=docsworker-xlarge /home/docsworker-xlarge/snooty /opt/
COPY --from=dependency-installer --chown=docsworker-xlarge /home/docsworker-xlarge/mut /opt/
COPY --from=dependency-installer --chown=docsworker-xlarge /usr/ /usr/
COPY --from=dependency-installer --chown=docsworker-xlarge /venv/ /venv/

COPY --from=dependency-installer --chown=docsworker-xlarge /home/docsworker-xlarge/redoc ./
COPY --from=dependency-installer --chown=docsworker-xlarge /home/docsworker-xlarge/shared.mk ./

COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/dist ./

ENV PATH="${PATH}:/opt/snooty:/opt/mut:/home/docsworker-xlarge/.local/bin:/usr/local/lib/python2.7/dist-packages/virtualenv/bin"

# Persistence module copy
# Create directory and add permissions to allow node module installation
RUN mkdir -p modules/persistence && chmod 755 modules/persistence
COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/modules/persistence/package*.json ./modules/persistence/
COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/modules/persistence/dist ./modules/persistence/
ENV PERSISTENCE_MODULE_PATH=${WORK_DIRECTORY}/modules/persistence/index.js
RUN cd ./modules/persistence/ && ls && npm ci --legacy-peer-deps

# OAS Page Builder module copy
# Create directory and add permissions to allow node module installation
RUN mkdir -p modules/oas-page-builder && chmod 755 modules/oas-page-builder
COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/modules/oas-page-builder/package*.json ./modules/oas-page-builder/
COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/modules/oas-page-builder/dist ./modules/oas-page-builder/
RUN cd ./modules/oas-page-builder/ && npm ci --legacy-peer-deps

# Needed for OAS Page Builder module in shared.mk
ENV REDOC_PATH=${WORK_DIRECTORY}/redoc/cli/index.js
ENV OAS_MODULE_PATH=${WORK_DIRECTORY}/modules/oas-page-builder/index.js

# Activate python env for Giza
RUN source /venv/bin/activate

RUN mkdir repos && chmod 755 repos
EXPOSE 3000
CMD ["node", "enhanced/enhancedApp.js"]
8 changes: 8 additions & 0 deletions cdk-infra/lib/constructs/worker/worker-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export class WorkerConstruct extends Construct {

const containerProps: AssetImageProps = {
file: isEnhanced() ? 'Dockerfile.enhanced' : undefined,
cacheFrom: [
{
type: 'gha',
},
],
cacheTo: {
type: 'gha',
},
buildArgs: {
NPM_BASE_64_AUTH: dockerEnvironment.NPM_BASE_64_AUTH,
NPM_EMAIL: dockerEnvironment.NPM_EMAIL,
Expand Down
Loading

0 comments on commit ad7694a

Please sign in to comment.