Skip to content

Commit 37f73f0

Browse files
Heroku dev deps (github#19431)
* fix: req.csrfToken doesn't always exist (e.g. 500 page) * feat: update dockerfile and add nextjs to build * fix: run linter * move @babel deps -> dev deps * move webpack looking things from deps -> dev deps * move pa11y-ci to optional dep * explicitly include optional deps for pa11y * allow heroku dev deps to be installed * fix: update postcss module * fix: update dockerfile build * tmp: disable renderReact * see if another deploy is slower/faster * move a few more packages to devDeps * upgrade to package-lock v2 * use dayjs instead of date-fns * move cross-env to devDeps * remove unused 'del' package * commit husky precommit hooks * add hrtime to clone-for-build.js * Revert "add hrtime to clone-for-build.js" This reverts commit 70ee647bacce833f4ed2f621f62c63c1d85e5413. * update babel/eslint * fix: remove unused plugin * try a .slugignore * fix: heroku-postbuild to use npm run build * fix: i cannot spell dereferenced * add .next/cache to heroku cacheDirectories * test cached build * remove aws-sdk, see what breaks * move jest-puppeteer to optional deps * fix: update browser-test.yml to use newer node version * move jimp to optional dependencies * move puppeteer to optional dependencies * fix: ci optional include * fix: bad copy pasta * remove previous react experiment * update tests/README.md with note about optional deps * bump node test version back to 14 * convert package-lock back to v1 * fix: use node 15.x to leverage npm optional deps * fix: optional dep install * test: see what happens with heroku/nodejs-typescript buildpack * back to heroku/nodejs buildpack * move jest to optional * revert jest move * remove .slugignore * cleanup dockerfile, move xlsx-population to optional, add comment about optional deps * Update Dockerfile Co-authored-by: James M. Greene <[email protected]> Co-authored-by: James M. Greene <[email protected]>
1 parent 865b23f commit 37f73f0

21 files changed

+4982
-9666
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
es2020: true,
66
node: true
77
},
8-
parser: 'babel-eslint',
8+
parser: '@babel/eslint-parser',
99
extends: [
1010
'eslint:recommended',
1111
'standard'

.github/workflows/browser-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
${{ runner.os }}-node-
4040
4141
- name: Install dependencies
42-
run: npm ci
42+
run: npm ci --include=optional
4343

4444
- name: Run brower-test
4545
run: npm run browser-test

.github/workflows/build-docker-image.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
- name: Check out repo
2424
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
2525
- name: Build the container
26-
run: docker build .
26+
run: docker build --target production .

.github/workflows/pa11y.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
${{ runner.os }}-node-
3636
3737
- name: Install dependencies
38-
run: npm ci
38+
run: npm ci --include=optional
3939

4040
- name: Run build scripts
4141
run: npm run build

Dockerfile

+48-10
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,62 @@
33
# It uses two multi-stage builds: `install` and the main build to keep the image size down.
44

55
# --------------------------------------------------------------------------------
6-
# INSTALL IMAGE
7-
# A temporary image that installs production-only dependencies and builds the production-ready front-end bundles.
6+
# BASE IMAGE
7+
# --------------------------------------------------------------------------------
8+
FROM node:16.2.0-alpine as base
9+
10+
RUN apk add --no-cache make g++ git
811

9-
FROM node:14-alpine as install
10-
RUN apk add --no-cache python make g++
11-
ENV NODE_ENV production
1212
WORKDIR /usr/src/docs
13+
14+
15+
# ---------------
16+
# ALL DEPS
17+
# ---------------
18+
FROM base as all_deps
19+
1320
COPY package*.json ./
21+
22+
RUN npm ci
23+
24+
25+
# ---------------
26+
# PROD DEPS
27+
# ---------------
28+
FROM all_deps as prod_deps
29+
30+
RUN npm prune --production
31+
32+
33+
# ---------------
34+
# BUILDER
35+
# ---------------
36+
FROM all_deps as builder
37+
38+
ENV NODE_ENV production
39+
1440
COPY javascripts ./javascripts
1541
COPY stylesheets ./stylesheets
42+
COPY pages ./pages
43+
COPY components ./components
1644
COPY lib ./lib
45+
46+
# one part of the build relies on this content file to pull all-products
47+
COPY content/index.md ./content/index.md
48+
1749
COPY webpack.config.js ./webpack.config.js
18-
RUN npm ci --production
50+
COPY next.config.js ./next.config.js
51+
COPY tsconfig.json ./tsconfig.json
52+
53+
RUN npx tsc
54+
1955
RUN npm run build
2056

2157
# --------------------------------------------------------------------------------
2258
# MAIN IMAGE
59+
# --------------------------------------------------------------------------------
2360

24-
FROM node:14-alpine
61+
FROM node:16.2.0-alpine as production
2562

2663
# Let's make our home
2764
WORKDIR /usr/src/docs
@@ -32,11 +69,12 @@ RUN chown node:node /usr/src/docs -R
3269
# This should be our normal running user
3370
USER node
3471

35-
# Copy our dependencies
36-
COPY --chown=node:node --from=install /usr/src/docs/node_modules /usr/src/docs/node_modules
72+
# Copy just our prod dependencies
73+
COPY --chown=node:node --from=prod_deps /usr/src/docs/node_modules /usr/src/docs/node_modules
3774

3875
# Copy our front-end code
39-
COPY --chown=node:node --from=install /usr/src/docs/dist /usr/src/docs/dist
76+
COPY --chown=node:node --from=builder /usr/src/docs/dist /usr/src/docs/dist
77+
COPY --chown=node:node --from=builder /usr/src/docs/.next /usr/src/docs/.next
4078

4179
# We should always be running in production mode
4280
ENV NODE_ENV production

app.json

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "docs.github.com",
33
"env": {
44
"NODE_ENV": "production",
5-
"NPM_CONFIG_PRODUCTION": "true",
65
"ENABLED_LANGUAGES": "en",
76
"WEB_CONCURRENCY": "1"
87
},

components/Contribution.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export const Contribution = () => {
2020
</a>
2121
<p className="color-text-secondary f6 mt-2">
2222
{t`or`}{' '}
23-
<a href="https://github.com/github/docs/blob/main/CONTRIBUTING.md" target="_blank" rel="noopener">
23+
<a
24+
href="https://github.com/github/docs/blob/main/CONTRIBUTING.md"
25+
target="_blank"
26+
rel="noopener"
27+
>
2428
{t`to_guidelines`}
2529
</a>
2630
</p>

components/Header.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ export const Header = () => {
5050
<div className="width-full">
5151
<div className="d-inline-block width-full d-md-flex" style={{ zIndex: 1 }}>
5252
<div className="float-right d-md-none position-relative" style={{ zIndex: 3 }}>
53-
<ButtonOutline css onClick={() => setIsMenuOpen(!isMenuOpen)} aria-label="Navigation Menu">
53+
<ButtonOutline
54+
css
55+
onClick={() => setIsMenuOpen(!isMenuOpen)}
56+
aria-label="Navigation Menu"
57+
>
5458
{isMenuOpen ? <XIcon size="small" /> : <ThreeBarsIcon size="small" />}
5559
</ButtonOutline>
5660
</div>

components/landing/FeaturedArticles.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cx from 'classnames'
22
import Link from 'next/link'
3-
import { format } from 'date-fns'
3+
import dayjs from 'dayjs'
44

55
import { ArrowRightIcon } from '@primer/octicons-react'
66
import { FeaturedLink, useProductLandingContext } from 'components/context/ProductLandingContext'
@@ -93,9 +93,9 @@ const ArticleList = ({ title, viewAllHref, articles }: ArticleListProps) => {
9393
{link.date && (
9494
<time
9595
className="tooltipped tooltipped-n color-text-tertiary text-mono mt-1"
96-
aria-label={format(new Date(link.date), 'PPP')}
96+
aria-label={dayjs(link.date).format('LLL')}
9797
>
98-
{format(new Date(link.date), 'MMMM dd')}
98+
{dayjs(link.date).format('MMMM DD')}
9999
</time>
100100
)}
101101
</a>

lib/page.js

+1-25
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const Permalink = require('./permalink')
1111
const languages = require('./languages')
1212
const renderContent = require('./render-content')
1313
const processLearningTracks = require('./process-learning-tracks')
14-
const { renderReact } = require('./react/engine')
1514
const { productMap } = require('./all-products')
1615
const slash = require('slash')
1716
const statsd = require('./statsd')
@@ -168,31 +167,8 @@ class Page {
168167
this.introLinks.overview = await renderContent(this.introLinks.rawOverview, context, { textOnly: true })
169168
}
170169

171-
let markdown = this.markdown
172-
173-
// If the article is interactive parse the React!
174-
if (this.interactive) {
175-
// Search for the react code comments to find the react components
176-
const reactComponents = markdown.match(/<!--react-->(.*?)<!--end-react-->/gs)
177-
178-
// Render each of the react components in the markdown
179-
await Promise.all(reactComponents.map(async (reactComponent) => {
180-
let componentStr = reactComponent
181-
182-
// Remove the React comment indicators
183-
componentStr = componentStr.replace('<!--react-->\n', '').replace('<!--react-->', '')
184-
componentStr = componentStr.replace('\n<!--end-react-->', '').replace('<!--end-react-->', '')
185-
186-
// Get the rendered component
187-
const renderedComponent = await renderReact(componentStr)
188-
189-
// Replace the react component with the rendered markdown
190-
markdown = markdown.replace(reactComponent, renderedComponent)
191-
}))
192-
}
193-
194170
context.relativePath = this.relativePath
195-
const html = await renderContent(markdown, context)
171+
const html = await renderContent(this.markdown, context)
196172

197173
// product frontmatter may contain liquid
198174
if (this.product) {

lib/react/babel.js

-22
This file was deleted.

lib/react/engine.js

-57
This file was deleted.

next.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ const { productIds } = require('./lib/all-products')
22
const languages = require('./lib/languages')
33

44
module.exports = {
5+
// speed up production `next build` by ignoring typechecking during that step of build.
6+
// type-checking still occurs in the Dockerfile build
7+
typescript: {
8+
ignoreBuildErrors: true
9+
},
510
i18n: {
611
locales: Object.values(languages).map(({ code }) => code),
712
defaultLocale: 'en'

0 commit comments

Comments
 (0)