Skip to content

Commit

Permalink
Merge pull request #14553 from artsy/main2
Browse files Browse the repository at this point in the history
refactor(ci): Simplify CI pipeline
  • Loading branch information
damassi authored Sep 24, 2024
2 parents ffe4f84 + 0eebb7f commit 6c32a3b
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 495 deletions.
423 changes: 175 additions & 248 deletions .circleci/config.yml

Large diffs are not rendered by default.

200 changes: 21 additions & 179 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,185 +1,27 @@
# syntax=docker/dockerfile:1.3
# +------------------+
# | |
# | builder-base |
# | |
# +---------+--------+
# ^
# |
# |
# +---------+--------+
# | |
# | yarn-base +<------------------------------------------------+
# | | |
# +---------+--------+ |
# ^ |
# | |
# | |
# +---------+--------+ +----------+-------+
# | | | |
# | yarn-deps | | yarn-deps-prod |
# | | | |
# +---------+--------+ +----------+-------+
# ^ ^
# | |
# | |
# +---------+--------+ |
# | | |
# | builder-src |<------------------------------+ |
# | | | |
# +---+-----------+--+ | |
# ^ ^ | |
# | | | |
# | | | |
# +---------------+--+ +---+--------------+ |
# | | | | |
# | builder-client | | builder-server | |
# | | | | |
# +---------------+--+ +---+--------------+ |
# ^ ^ ^ |
# | | | |
# | | | |
# +---+-----------+--+ | |
# | |-------------------------------+ |
# | builder +<------------------------------------------+ |
# | | | |
# +--------+---------+ | |
# ^ | |
# | | |
# | | |
# +--------+---------+ +---+-----+--------+
# | | | |
# | electron-runner | | production |
# | | | |
# +------------------+ +------------------+

# ---------------------------------------------------------
# Base build dependencies
# ---------------------------------------------------------
FROM node:18.15.0-alpine3.17 as builder-base
FROM node:18.15-alpine as builder-base

WORKDIR /app

# Install system dependencies
RUN apk --no-cache --quiet add \
bash \
build-base \
curl \
dumb-init \
git

# ---------------------------------------------------------
# Yarn base
# ---------------------------------------------------------
FROM builder-base as yarn-base

# Copy files required for installation of application dependencies
# Copy files required to install application dependencies
COPY package.json yarn.lock ./
COPY patches ./patches

# ---------------------------------------------------------
# Yarn dependencies
# ---------------------------------------------------------
FROM yarn-base as yarn-deps

RUN --mount=type=cache,id=yarndev,target=/usr/local/share/.cache \
--mount=type=cache,id=cypress,sharing=locked,target=/root/.cache/Cypress \
yarn install --frozen-lockfile --quiet

# ---------------------------------------------------------
# Yarn dependencies
# ---------------------------------------------------------
FROM yarn-base as yarn-deps-prod

RUN --mount=type=cache,id=yarnprod,target=/usr/local/share/.cache \
--mount=type=cache,id=cypress,sharing=locked,target=/root/.cache/Cypress \
yarn install --production --frozen-lockfile --quiet

# ---------------------------------------------------------
# Builder with source code
# ---------------------------------------------------------
FROM yarn-deps as builder-src
# Install packages
RUN yarn install --production --frozen-lockfile --quiet && \
mv node_modules /opt/node_modules.prod && \
yarn install --frozen-lockfile --quiet && \
yarn cache clean --force

# Copy application code
COPY __mocks__ ./__mocks__
COPY cypress ./cypress
COPY data ./data
COPY patches ./patches
COPY src ./src
COPY webpack ./webpack
COPY .git ./.git
COPY .env.oss \
.env.test \
.eslintrc.js \
.nvmrc \
.prettierignore \
.swcrc.js \
babel.config.js \
cypress.config.ts \
dangerfile.ts \
jest.config.js \
package.json \
relay.config.js \
relativeci.config.js \
tsconfig.json \
yarn.lock \
./

# ---------------------------------------------------------
# Compile client
# ---------------------------------------------------------
FROM builder-src as builder-client

RUN yarn build:client:prod

# ---------------------------------------------------------
# Compile server
# ---------------------------------------------------------
FROM builder-src as builder-server

# Build application
RUN yarn build:server:prod

# ---------------------------------------------------------
# All development assets
# ---------------------------------------------------------
FROM builder-src as builder

# Scripts
COPY ./scripts ./scripts

# Client assets
COPY --from=builder-client /app/manifest.json .
COPY --from=builder-client /app/public ./public
COPY --from=builder-client /app/src ./src

# Server assets
COPY --from=builder-server /app/server.dist.js .
COPY --from=builder-server /app/server.dist.js.map .

# ---------------------------------------------------------
# Image with xvfb to run Electron with a virtual display
# ---------------------------------------------------------
FROM node:18.15.0-bullseye-slim as electron-runner

WORKDIR /app
COPY . ./

# Install electron deps
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
libgtk2.0-0 \
libgtk-3-0 \
libgbm-dev \
libnotify-dev \
libgconf-2-4 \
libnss3 \
libxss1 \
libasound2 \
libxtst6 \
xauth \
xvfb \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /app /app
RUN yarn build

# ---------------------------------------------------------
# Release image
Expand All @@ -201,23 +43,23 @@ RUN chown deploy:deploy $(pwd)
USER deploy

# Production node modules.
COPY --chown=deploy:deploy --from=yarn-deps-prod /app/node_modules ./node_modules
COPY --chown=deploy:deploy --from=builder-base /opt/node_modules.prod ./node_modules

# Base code
COPY --chown=deploy:deploy --from=builder /app/data ./data
COPY --chown=deploy:deploy --from=builder /app/package.json .
COPY --chown=deploy:deploy --from=builder /app/scripts ./scripts
COPY --chown=deploy:deploy --from=builder /app/webpack ./webpack
COPY --chown=deploy:deploy --from=builder /app/yarn.lock .
COPY --chown=deploy:deploy --from=builder-base /app/data ./data
COPY --chown=deploy:deploy --from=builder-base /app/package.json .
COPY --chown=deploy:deploy --from=builder-base /app/scripts ./scripts
COPY --chown=deploy:deploy --from=builder-base /app/webpack ./webpack
COPY --chown=deploy:deploy --from=builder-base /app/yarn.lock .

# Client assets
COPY --chown=deploy:deploy --from=builder /app/manifest.json .
COPY --chown=deploy:deploy --from=builder /app/public ./public
COPY --chown=deploy:deploy --from=builder /app/src ./src
COPY --chown=deploy:deploy --from=builder-base /app/manifest.json .
COPY --chown=deploy:deploy --from=builder-base /app/public ./public
COPY --chown=deploy:deploy --from=builder-base /app/src ./src

# Server assets
COPY --chown=deploy:deploy --from=builder /app/server.dist.js .
COPY --chown=deploy:deploy --from=builder /app/server.dist.js.map .
COPY --chown=deploy:deploy --from=builder-base /app/server.dist.js .
COPY --chown=deploy:deploy --from=builder-base /app/server.dist.js.map .

ENTRYPOINT ["/usr/bin/dumb-init", "--"]

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"build-storybook": "build-storybook",
"bundle-report:client": "WEBPACK_BUNDLE_REPORT=true yarn build:client:prod",
"bundle-report:server": "WEBPACK_BUNDLE_REPORT=true yarn build:server:prod",
"bundle-stats": "yarn bundle-report:client --json webpack-stats.json && npx relative-ci-agent",
"clean": "scripts/clean.sh",
"clean:relay": "rm -rf '$TMPDIR'/RelayFindGraphQLTags-*",
"compile": "babel src --out-dir dist -s --source-map --extensions '.js,.jsx,.ts,.tsx' --ignore src/**/__tests__",
"cypress:run": "./node_modules/.bin/cypress run",
"cypress": "./node_modules/.bin/cypress open",
"danger:ci": "yarn danger ci --verbose",
"dead-code": "./scripts/check-dead-code.sh",
"dead-code:production": "./scripts/check-dead-code.sh production",
"delete-review-app": "kubectl --context staging delete namespace",
Expand Down Expand Up @@ -53,8 +55,8 @@
"sync-schema": "scripts/sync-schema-pull.sh",
"sync-schema-local": "scripts/sync-schema-local.sh",
"test": "scripts/jest.sh",
"test:smoke": "scripts/smoke_test.sh",
"test:smoke:spec": "./node_modules/.bin/cypress run -s",
"test:smoke": "npx cypress run",
"test:smoke:spec": "npx cypress run --spec",
"translations": "node scripts/list-translations",
"type-check": "tsc",
"stats:client": "WEBPACK_STATS=normal yarn build:client:prod --profile --json > stats-client.json",
Expand Down
63 changes: 0 additions & 63 deletions scripts/smoke_test.sh

This file was deleted.

9 changes: 8 additions & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ if [ "${NODE_ENV}" != "production" ]; then
fi
OPT+=(--preserve-symlinks)

yarn concurrently --kill-others 'yarn relay --watch' 'node --max_old_space_size=3072 ./src/dev.js'
# Smoke Tests
if [ "$CIRCLECI" = "true" ]; then
exec node --max_old_space_size=3072 ./src/dev.js
# Dev
else
yarn concurrently --kill-others 'yarn relay --watch' 'node --max_old_space_size=3072 ./src/dev.js'
fi
# Prod
else
exec node "${OPT[@]}" --no-experimental-fetch ./server.dist.js
fi
4 changes: 4 additions & 0 deletions src/Components/CookieConsentManager/CookieConsentManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const CookieConsentManager: FC<CookieConsentManagerProps> = ({
setMode("Idle")
}

if (!getENV("SEGMENT_WRITE_KEY")) {
return <>{children}</>
}

return (
<CookieConsentManagerProvider openConsentManager={handleManage}>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/Server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const SALESFORCE_CHAT_AUCTION_ESW_LIVE_AGENT_DEV_NAME: any = null
export const SECURE_IMAGES_URL: any = "https://d1ycxz9plii3tb.cloudfront.net"
export const SEGMENT_AMP_WRITE_KEY: any = null
export const SEGMENT_WRITE_KEY_SERVER: any = null
export const SEGMENT_WRITE_KEY: any = "replace-me"
export const SEGMENT_WRITE_KEY: any = null
export const SENTRY_PRIVATE_DSN: any = null
export const SENTRY_PUBLIC_DSN: any = null
export const SESSION_COOKIE_KEY: any = "force.sess"
Expand Down
4 changes: 3 additions & 1 deletion src/Server/passport/lib/app/analytics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const Analytics = require("analytics-node")
const { data: sd } = require("sharify")

export const analytics = new Analytics(sd.SEGMENT_WRITE_KEY)
export const analytics = sd.SEGMENT_WRITE_KEY
? new Analytics(sd.SEGMENT_WRITE_KEY)
: null

module.exports.setCampaign = function (req, _res, next) {
if (!sd.SEGMENT_WRITE_KEY) {
Expand Down

0 comments on commit 6c32a3b

Please sign in to comment.