feat(docker): create configs for dockerized setup (#44753)

This commit is contained in:
Mrugesh Mohapatra
2022-02-25 00:20:24 +05:30
committed by GitHub
parent 0d26a9e29d
commit 4748740386
7 changed files with 123 additions and 82 deletions

35
docker/api/Dockerfile Normal file
View File

@ -0,0 +1,35 @@
FROM node:16-buster AS builder
# Install doppler CLI
RUN (curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh) | sh -s -- --verify-signature
# node images create a non-root user that we can use
USER node
WORKDIR /home/node/build
COPY --chown=node:node . .
# Pass `DOPPLER_TOKEN` at build time to create an encrypted snapshot for high-availability
ARG DOPPLER_TOKEN
RUN \
doppler secrets download doppler.encrypted.json &&\
npm ci --no-progress --ignore-scripts &&\
doppler run --fallback=doppler.encrypted.json --command="npm run create:config" &&\
doppler run --fallback=doppler.encrypted.json --command="npm run build:curriculum" &&\
doppler run --fallback=doppler.encrypted.json --command="npm run build:server"
FROM node:16-alpine as depends
USER node
WORKDIR /home/node/depends
COPY --chown=node:node . .
RUN npm ci --production --workspace=api-server --include-workspace-root --no-progress --ignore-scripts
FROM node:16-alpine
RUN npm i -g pm2@4
USER node
WORKDIR /home/node/api
COPY --from=builder --chown=node:node /home/node/build/api-server/lib/ api-server/lib/
COPY --from=builder --chown=node:node /home/node/build/utils/ utils/
COPY --from=builder --chown=node:node /home/node/build/config/ config/
COPY --from=depends --chown=node:node /home/node/depends/api-server/node_modules/ api-server/node_modules/
COPY --from=depends --chown=node:node /home/node/depends/node_modules/ node_modules/
WORKDIR /home/node/api/api-server
CMD ["pm2-runtime", "./lib/production-start.js"]
# TODO: don't copy mocks/fixtures

28
docker/web/Dockerfile Normal file
View File

@ -0,0 +1,28 @@
FROM node:16-buster AS builder
# Install doppler CLI
RUN (curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh) | sh -s -- --verify-signature
# node images create a non-root user that we can use
USER node
WORKDIR /home/node/build
COPY --chown=node:node . .
# Pass `DOPPLER_TOKEN` at build time to create an encrypted snapshot for high-availability
ARG DOPPLER_TOKEN
RUN \
doppler secrets download doppler.encrypted.json &&\
# Install and donot ignore the scripts for sharp
npm ci --no-progress --ignore-scripts=false &&\
doppler run --fallback=doppler.encrypted.json --command="npm run create:config" &&\
doppler run --fallback=doppler.encrypted.json --command="npm run build:curriculum" &&\
doppler run --fallback=doppler.encrypted.json --command="npm run build:client"
# Use a lightweight image for the serving the files
FROM node:16-alpine
RUN npm i -g serve@13
USER node
WORKDIR /home/node
COPY --from=builder /home/node/build/client/public/ client/public
COPY --from=builder /home/node/build/docker/web/serve.json client/serve.json
EXPOSE 8000
CMD ["serve", "--config", "client/serve.json", "--cors", "--no-clipboard", "--no-port-switching", "-p", "8000", "client/public"]

60
docker/web/serve.json Normal file
View File

@ -0,0 +1,60 @@
{
"directoryListing": false,
"trailingSlash": false,
"rewrites": [
{
"source": "/certification/**",
"destination": "/certification/index.html"
}
],
"redirects": [
{
"source": "/challenges/:superblock?/:block?/:challenge?",
"destination": "/learn/:superblock?/:block?/:challenge?"
},
{
"source": "/learn/apis-and-microservices/apis-and-microservices-projects",
"destination": "/learn/back-end-development-and-apis/back-end-development-and-apis-projects"
},
{
"source": "/learn/apis-and-microservices/apis-and-microservices-projects/:challenge",
"destination": "/learn/back-end-development-and-apis/back-end-development-and-apis-projects/:challenge"
},
{
"source": "/learn/apis-and-microservices/:block?/:challenge?",
"destination": "/learn/back-end-development-and-apis/:block?/:challenge?"
},
{
"source": "/certification/:username/apis-and-microservices",
"destination": "/certification/:username/back-end-development-and-apis"
},
{
"source": "/learn/front-end-libraries/front-end-libraries-projects",
"destination": "/learn/front-end-development-libraries/front-end-development-libraries-projects"
},
{
"source": "/learn/front-end-libraries/front-end-libraries-projects/:challenge",
"destination": "/learn/front-end-development-libraries/front-end-development-libraries-projects/:challenge"
},
{
"source": "/learn/front-end-libraries/:block?/:challenge?",
"destination": "/learn/front-end-development-libraries/:block?/:challenge?"
},
{
"source": "/certification/:username/front-end-libraries",
"destination": "/certification/:username/front-end-development-libraries"
},
{
"source": "/learn/javascript-algorithms-and-data-structures/es6/explore-differences-between-the-var-and-let-keywords",
"destination": "/learn/javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords"
},
{
"source": "/learn/javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword",
"destination": "/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword"
},
{
"source": "/learn/responsive-web-design/applied-visual-design/adjust-the-size-of-a-header-versus-a-paragraph-tag",
"destination": "/learn/responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element"
}
]
}