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

Add dependency caching to reduce build time #1973

Draft
wants to merge 3 commits into
base: reduce-docker-buildtime
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ terraform/
**/dist
*.md
reports
.env
.env
.turbo
out/
**/out/
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
},
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
},
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
};
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ playwright
tests/**/report/*.html
tests/api/report
tests/e2e/report

.turbo
**/.turbo
# Ignore /doc => /docs symbolic link created for adr-tools
/doc

Expand Down Expand Up @@ -46,3 +47,6 @@ newrelic_agent.log

# Python cache
__pycache__/
out/
**/out/
.vscode/*
20 changes: 20 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#f58793",
"activityBar.background": "#f58793",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#cafac4",
"activityBarBadge.foreground": "#15202b",
"commandCenter.border": "#15202b99",
"sash.hoverBorder": "#f58793",
"statusBar.background": "#f15869",
"statusBar.foreground": "#15202b",
"statusBarItem.hoverBackground": "#ed293f",
"statusBarItem.remoteBackground": "#f15869",
"statusBarItem.remoteForeground": "#15202b",
"titleBar.activeBackground": "#f15869",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveBackground": "#f1586999",
"titleBar.inactiveForeground": "#15202b99"
},
"peacock.color": "#f15869"
}
45 changes: 45 additions & 0 deletions .yarnclean
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# test directories
__tests__
test
tests
powered-test

# asset directories
docs
doc
website
images
assets

# examples
example
examples

# code coverage directories
coverage
.nyc_output

# build scripts
Makefile
Gulpfile.js
Gruntfile.js

# configs
appveyor.yml
circle.yml
codeship-services.yml
codeship-steps.yml
wercker.yml
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.travis.yml

# misc
*.md
63 changes: 63 additions & 0 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
FROM node:18.18.2 as base
ENV TURBO_TELEMETRY_DISABLED=1
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init lcov chromium
RUN yarn global add turbo node-gyp

FROM base AS prune
ENV TURBO_TOKEN=
ENV TURBO_TEAM=
# Set working directory
WORKDIR /app
COPY backend/ backend/
COPY package.json .
COPY yarn.lock .
COPY turbo.json .
COPY .eslintrc.js .
RUN turbo prune --docker @repo/backend

# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
ENV TURBO_TELEMETRY_DISABLED=1
WORKDIR /app

# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --link --from=prune /app/out/json/ .
COPY --link --from=prune /app/turbo.json .
COPY --link --from=prune /app/out/yarn.lock ./yarn.lock
RUN --mount=type=cache,target=/root/.yarn \
YARN_CACHE_FOLDER=/root/.yarn \
yarn install

FROM base as builder
ENV TURBO_TOKEN=
ENV TURBO_TEAM=
WORKDIR /app

# Build the project
COPY --link --from=prune /app/out/full/ .
COPY --link --from=prune /app/turbo.json .
COPY --link --from=installer /app/node_modules/ /app/node_modules/
# COPY --link --from=installer /app/bckend/node_modules /app/backend/node_modules
RUN turbo run build --filter=@repo/backend

# Copy the build artifacts to a new image
FROM node:18.18.2-slim AS backend
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init lcov chromium
WORKDIR /app
ENV DISABLE_ESLINT_PLUGIN=true
COPY --link --from=base /usr/bin/dumb-init /usr/bin/dumb-init
#https://github.com/facebook/relay/issues/2699
# RUN chmod g=u /etc/passwd
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --link --chown=node:node --from=builder /app/backend/build/ /app/
COPY --link --chown=node:node --from=builder /app/node_modules/ /app/node_modules/
COPY --link --chown=node:node --from=builder /app/package.json /app/package.json

# ENTRYPOINT ["/usr/bin/dumb-init", "--"]
USER node
CMD ["/usr/bin/dumb-init", "yarn", "serve"]

FROM backend as worker
FROM backend as testingonly
19 changes: 11 additions & 8 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init lcov chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
COPY package.json yarn.lock ./
COPY backend/package.json backend/yarn.lock ./
RUN yarn global add node-gyp &&\
yarn install &&\
yarn cache clean
# --mount=type=cache,target=/root/.yarn \
# YARN_CACHE_FOLDER=/root/.yarn \
yarn install

FROM node:18.18.2-alpine as frontend-base
WORKDIR /app
RUN apk update && apk add yarn dumb-init
COPY frontend/package.json frontend/yarn.lock ./
RUN yarn install &&\
yarn cache clean
RUN --mount=type=cache,target=/root/.yarn \
YARN_CACHE_FOLDER=/root/.yarn \
yarn install

FROM node:18.18.2 as build
ENV NODE_OPTIONS=--max_old_space_size=2048
RUN apt-get update && apt-get install -y --no-install-recommends yarn
WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
COPY --from=base /app/package.json /app/package.json
COPY src/ /app/src/
COPY tests/ /app/tests/
COPY config/ /app/config/
COPY backend/src/ /app/src/
COPY backend/tests/ /app/tests/
COPY backend/config/ /app/config/
RUN yarn tsc --build --verbose src

FROM node:18.18.2-alpine as frontend-build
Expand Down
58 changes: 58 additions & 0 deletions Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
FROM node:18.18.2-alpine as base
ENV TURBO_TELEMETRY_DISABLED=1
RUN apk add --no-cache libc6-compat dumb-init
RUN apk update
RUN yarn global add turbo node-gyp

FROM base AS prune
ENV TURBO_TOKEN=
ENV TURBO_TEAM=
RUN apk update
# Set working directory
WORKDIR /app
COPY frontend/ frontend/
COPY package.json .
COPY yarn.lock .
COPY turbo.json .
COPY .eslintrc.js .
RUN turbo prune --docker @repo/frontend

# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
ENV TURBO_TELEMETRY_DISABLED=1
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app

# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --link --from=prune /app/out/json/ .
COPY --link --from=prune /app/turbo.json .
COPY --link --from=prune /app/out/yarn.lock ./yarn.lock
RUN --mount=type=cache,target=/root/.yarn \
YARN_CACHE_FOLDER=/root/.yarn \
yarn install

FROM base as builder
ENV TURBO_TOKEN=
ENV TURBO_TEAM=
WORKDIR /app
RUN apk add --no-cache libc6-compat
RUN apk update
# Build the project
COPY --link --from=prune /app/out/full/ .
COPY --link --from=prune /app/turbo.json .
COPY --link --from=installer /app/node_modules /app/node_modules
RUN turbo run build --filter=@repo/frontend

FROM base AS frontend
WORKDIR /app
ENV DISABLE_ESLINT_PLUGIN=true
COPY --from=base --chown=node:node /usr/bin/dumb-init /usr/bin/dumb-init
USER node
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --link --from=builder --chown=node:node /app/frontend /app/
COPY --link --from=builder --chown=node:node /app/node_modules /app/node_modules
# ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["yarn", "react-scripts", "start"]
3 changes: 2 additions & 1 deletion src/.eslintrc β†’ backend/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 2020
}
},
"extends": ["turbo"]
}
54 changes: 54 additions & 0 deletions backend/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require('dotenv').config();

const singleLineLogger = (
queryString,
) => console.log(queryString.replace(/\n/g, '\\n')); // eslint-disable-line no-console

module.exports = {
development: {
username: process.env.POSTGRES_USERNAME,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
host: (process.env.POSTGRES_HOST || 'localhost'),
port: (process.env.POSTGRES_PORT || 5432),
dialect: 'postgres',
logging: singleLineLogger,
logQueryParameters: true,
minifyAliases: true,
},
test: {
username: process.env.POSTGRES_USERNAME,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
host: (process.env.POSTGRES_HOST || 'localhost'),
port: (process.env.POSTGRES_PORT || 5432),
dialect: 'postgres',
logging: false,
minifyAliases: true,
},
dss: {
use_env_variable: 'DATABASE_URL',
username: process.env.POSTGRES_USERNAME,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
host: process.env.POSTGRES_HOST,
port: (process.env.POSTGRES_PORT || 5432),
dialect: 'postgres',
logging: singleLineLogger,
minifyAliases: true,
},
production: {
use_env_variable: 'DATABASE_URL',
username: process.env.POSTGRES_USERNAME,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
host: process.env.POSTGRES_HOST,
port: (process.env.POSTGRES_PORT || 5432),
dialect: 'postgres',
logging: singleLineLogger,
minifyAliases: true,
dialectOptions: {
ssl: true,
},
},
};
File renamed without changes.
File renamed without changes.
Loading