Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC]: Add esbuild and update enhanced dockerfile #906

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/update-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand Down Expand Up @@ -47,7 +48,6 @@ jobs:
npm ci
npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \
auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-webhooks

- name: Update Worker Stack
if: steps.filter.outputs.worker == 'true'
run: |
Expand Down
89 changes: 57 additions & 32 deletions Dockerfile.enhanced
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
# 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
ARG MUT_VERSION=0.10.5
ARG REDOC_CLI_VERSION=1.2.0
ARG REDOC_CLI_VERSION=1.2.2
ARG NPM_BASE_64_AUTH
ARG NPM_EMAIL
ENV DEBIAN_FRONTEND=noninteractive
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 All @@ -85,36 +64,82 @@ RUN git clone -b v${SNOOTY_FRONTEND_VERSION} --depth 1 https://github.com/mongod
&& mv ./docs-tools/themes/mongodb/static ./static/docs-tools \
&& mv ./docs-tools/themes/guides/static/images/bg-accent.svg ./static/docs-tools/images/bg-accent.svg


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 snooty-parser.zip

# install redoc fork
RUN git clone -b @dop/redoc-cli@${REDOC_CLI_VERSION} --depth 1 https://github.com/mongodb-forks/redoc.git redoc \
# Install dependencies for Redoc CLI
&& cd redoc/ \
&& npm ci --prefix cli/ --omit=dev

COPY --from=ts-compiler --chown=docsworker-xlarge /home/docsworker-xlarge/package*.json ./
# 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
WORKDIR ${WORK_DIRECTORY}

# setup user and root directory
RUN adduser -D --home ${WORK_DIRECTORY} --shell /bin/sh docsworker-xlarge
RUN chmod 755 -R ${WORK_DIRECTORY}
RUN chown -Rv docsworker-xlarge ${WORK_DIRECTORY}
USER docsworker-xlarge


# the /opt/ dir contains snooty and mut
COPY --from=dependency-installer --chown=docsworker-xlarge /opt/ /opt/
# all of the dependencies we need for python 2 live here
COPY --from=dependency-installer --chown=docsworker-xlarge /usr/ /usr/
# giza lives here so we will need that
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 ./
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

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"]
5 changes: 3 additions & 2 deletions cdk-infra/lib/constructs/api/webhook-env-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StringParameter } from 'aws-cdk-lib/aws-ssm';
import { Construct } from 'constructs';
import { getSsmPathPrefix } from '../../../utils/ssm';
import { getDashboardUrl } from '../../../utils/slack';
import { getEnv } from '../../../utils/env';
import { getEnv, getFeatureName } from '../../../utils/env';

interface WebhookEnvConstructProps {
jobsQueue: IQueue;
Expand All @@ -18,10 +18,11 @@ export class WebhookEnvConstruct extends Construct {

const ssmPrefix = getSsmPathPrefix();
const env = getEnv();
const featureName = getFeatureName();

// Create configurable feature flag that lives in parameter store.
const monorepoPathFeature = new StringParameter(this, 'monorepoPathFeature', {
parameterName: `${ssmPrefix}/monorepo/path_feature`,
parameterName: `${ssmPrefix}/${featureName}/monorepo/path_feature`,
stringValue: env === 'dotcomstg' || env === 'stg' ? 'true' : 'false',
});

Expand Down
1 change: 1 addition & 0 deletions cdk-infra/lib/constructs/worker/worker-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class WorkerConstruct extends Construct {
desiredCount: env === 'prd' ? 10 : 1,
minHealthyPercent: 100,
maxHealthyPercent: 200,
enableExecuteCommand: true, // debugging help
});

this.clusterName = cluster.clusterName;
Expand Down
2 changes: 2 additions & 0 deletions cdk-infra/lib/constructs/worker/worker-env-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class WorkerEnvConstruct extends Construct {
`/docs/worker_pool/preview_webhook/snooty_gatsby_cloud_test/data_source`
);

console.log('random-test2');

// front end feature flag for chatbot UI
const gatsbyUseChatbot = StringParameter.valueFromLookup(this, `${ssmPrefix}/flag/use_chatbot`);

Expand Down
Loading
Loading