-
Notifications
You must be signed in to change notification settings - Fork 394
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
Upgrade to Gatsby 3 and fix Heroku caching #2851
Changes from all commits
3750ee3
53ace1c
6863876
4c7d438
d4727f1
e674ed3
860f675
02e28ef
386cec9
6e7175e
ccd015b
e781b51
ae3c67f
3387acf
c93dc11
2f7f75f
56d81f5
cb4811f
3ba0119
51d8cab
f0bcb34
7e015ff
c9c17b6
1be35ce
8097ab6
40c137c
51a6012
68d9221
3aeb49b
79c73c6
7ed3594
104133d
225e23a
14fa14f
fc9eca5
7baf746
e8f3abc
c8f7206
bb0a1db
c044388
9875576
ed08dea
140bd2d
af79020
4b82c90
da9cd1c
bdbf382
02752d1
7556490
0f18563
9dfd4fe
2db284f
de0d4f2
ab8bf2b
40ca6d1
bf9a0da
a4997b0
fe5d681
f23924d
3a7d057
eb4b2ea
8f5b6a9
2b4522d
db3d7df
4800070
840418d
937df1f
7512475
c461db0
071ff34
47971cc
7fa7d9e
50727fc
557eb74
fc9c31f
0a35457
4f00970
5df1fab
71ac4dc
a0d6bb0
1beffea
ef75571
57a62c1
6b2447e
3a847ca
0654d32
c71cb9c
d60ffd5
dc792c7
7ebf117
c235488
30b9cee
2a1bf7e
7b440f7
3c68213
400e544
a567e50
28f5963
4970815
cfb94d2
4a39095
6991d2f
dfb28e4
f22897c
f0604b2
968b5d9
988c58b
e6d9cac
0ab035f
8960b5f
2850fc7
3b4cc8d
07654aa
53f8af3
32f1423
c51badb
f072eeb
d07b9b9
65bcebe
5e79c19
edae234
f615efc
21c7e80
e4a7472
5b504a4
b352239
6e3202f
5c74094
8f26292
e382a69
51f46fa
ab4c1ea
e3ec823
e4b99c1
9d86766
98e18a5
f90bb07
66acf1d
1ea58e7
de3c76e
804fef3
e51afa0
f442dc8
880c082
6d757fa
cefd41d
b9655f2
d9c3b4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,6 @@ tags: | |
- Version Control | ||
- AI | ||
--- | ||
|
||
``` | ||
|
||
- `title` (**required**) - title of the post. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ const plugins = [ | |
path: path.join(__dirname, 'static') | ||
} | ||
}, | ||
'gatsby-plugin-image', | ||
'community-page', | ||
{ | ||
resolve: 'gatsby-transformer-remark', | ||
|
@@ -122,7 +123,14 @@ const plugins = [ | |
} | ||
}, | ||
'gatsby-transformer-sharp', | ||
'gatsby-plugin-sharp', | ||
{ | ||
resolve: 'gatsby-plugin-sharp', | ||
options: { | ||
defaults: { | ||
placeholder: 'blurred' | ||
} | ||
} | ||
}, | ||
{ | ||
resolve: 'gatsby-plugin-catch-links', | ||
options: { | ||
|
@@ -224,28 +232,6 @@ const plugins = [ | |
} | ||
] | ||
|
||
if (process.env.GITHUB_TOKEN) { | ||
plugins.push({ | ||
resolve: `gatsby-source-github-api`, | ||
options: { | ||
// token: required by the GitHub API | ||
token: process.env.GITHUB_TOKEN, | ||
|
||
// GraphQLquery: defaults to a search query | ||
graphQLQuery: ` | ||
{ | ||
repository(owner: "iterative", name: "dvc") { | ||
stargazers { | ||
totalCount | ||
} | ||
} | ||
} | ||
`, | ||
variables: {} | ||
} | ||
}) | ||
} | ||
|
||
if (process.env.CONTEXT === 'production') { | ||
plugins.push({ | ||
resolve: 'gatsby-plugin-google-analytics', | ||
|
@@ -258,11 +244,7 @@ if (process.env.CONTEXT === 'production') { | |
|
||
if (process.env.ANALYZE) { | ||
plugins.push({ | ||
resolve: 'gatsby-plugin-webpack-bundle-analyzer', | ||
options: { | ||
analyzerPort: 4000, | ||
production: process.env.NODE_ENV === 'production' | ||
} | ||
resolve: 'gatsby-plugin-webpack-bundle-analyser-v2' | ||
Comment on lines
-261
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newest version of the same thing. |
||
}) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
"author": "LIMIT_BLOG_PAGES=1 SKIP_DOCS=true gatsby develop", | ||
"build": "gatsby build", | ||
"start": "node ./src/server/index.js", | ||
"heroku-postbuild": "./scripts/deploy-with-s3.js", | ||
"heroku-postbuild": "./scripts/heroku-deploy.sh", | ||
"test": "jest", | ||
"format-staged": "pretty-quick --staged --no-restage --bail", | ||
"format-check": "prettier --check '**/*.{js,jsx,md,tsx,ts,json}'", | ||
|
@@ -33,50 +33,51 @@ | |
}, | ||
"homepage": "https://github.com/iterative/dvc.org#readme", | ||
"engines": { | ||
"node": "<=15.x" | ||
"node": "<=16.x" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the latest sharp means we can use the latest Node |
||
}, | ||
"dependencies": { | ||
"@hapi/wreck": "^17.0.0", | ||
"@octokit/graphql": "^4.3.1", | ||
"@reach/portal": "^0.10.0", | ||
"@reach/router": "^1.3.3", | ||
"@reach/tooltip": "^0.10.0", | ||
"@octokit/graphql": "^4.8.0", | ||
"@reach/portal": "^0.16.2", | ||
"@reach/router": "^1.3.4", | ||
"@reach/tooltip": "^0.16.2", | ||
"classnames": "^2.2.6", | ||
"color": "^3.1.2", | ||
"color": "^4.0.1", | ||
"compression": "^1.7.4", | ||
"date-fns": "^2.11.1", | ||
"date-fns": "^2.25.0", | ||
"docsearch.js": "^2.6.3", | ||
"ease-component": "^1.0.0", | ||
"express": "^4.17.1", | ||
"fs-extra": "^9.0.0", | ||
"gatsby": "^2.20.13", | ||
"gatsby-image": "^2.3.1", | ||
"gatsby-link": "^2.3.2", | ||
"fs-extra": "^10.0.0", | ||
"gatsby": "^3.14.3", | ||
"gatsby-link": "^3.14.0", | ||
"gatsby-plugin-image": "^1.14.1", | ||
"gatsby-plugin-parent-resolvers": "^1.0.1", | ||
"gatsby-source-github-api": "^0.2.1", | ||
"github-markdown-css": "^4.0.0", | ||
"iso-url": "^0.4.7", | ||
"isomorphic-fetch": "^2.2.1", | ||
"graphql": "^15.6.1", | ||
"iso-url": "^1.1.5", | ||
"isomorphic-fetch": "^3.0.0", | ||
"lodash": "^4.17.21", | ||
"moment": "^2.25.3", | ||
"nanoid": "^3.0.2", | ||
"nanoid": "^3.1.30", | ||
"node-cache": "^5.1.0", | ||
"perfect-scrollbar": "^1.5.0", | ||
"pretty-quick": "^2.0.1", | ||
"postcss": "^8.3.9", | ||
"pretty-quick": "^3.1.1", | ||
"prismjs": "^1.25.0", | ||
"promise-polyfill": "^8.1.3", | ||
"prop-types": "^15.7.2", | ||
"raf-polyfill": "^1.0.0", | ||
"react": "^16.13.1", | ||
"react": "^17.0.2", | ||
"react-collapse": "^5.0.1", | ||
"react-collapsible": "^2.7.0", | ||
"react-dom": "^16.13.1", | ||
"react-ga": "^2.7.0", | ||
"react-helmet": "^5.2.1", | ||
"react-dom": "^17.0.2", | ||
"react-ga": "^3.3.0", | ||
"react-helmet": "^6.1.0", | ||
"react-popover": "^0.5.10", | ||
"react-slick": "^0.25.2", | ||
"react-slick": "^0.28.1", | ||
"react-use": "^14.0.0", | ||
"rehype-react": "^5.0.1", | ||
"rehype-react": "^6.2.1", | ||
"remark-preset-lint-recommended": "^5.0.0", | ||
"repo-link-check": "^0.7.1", | ||
"reset-css": "^5.0.1", | ||
|
@@ -86,10 +87,10 @@ | |
"slick-carousel": "^1.8.1", | ||
"title-case": "^3.0.2", | ||
"unist-util-visit": "2.0.2", | ||
"upath": "^1.2.0" | ||
"upath": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.9.0", | ||
"@babel/core": "^7.15.8", | ||
"@svgr/webpack": "^5.3.1", | ||
"@types/classnames": "^2.2.10", | ||
"@types/isomorphic-fetch": "^0.0.35", | ||
|
@@ -99,66 +100,65 @@ | |
"@types/react-dom": "^16.9.6", | ||
"@types/react-helmet": "^5.0.15", | ||
"@types/react-popover": "^0.5.3", | ||
"@types/react-slick": "^0.23.4", | ||
"@types/react-slick": "^0.23.6", | ||
"@types/rehype-react": "^4.0.0", | ||
"@typescript-eslint/eslint-plugin": "^2.27.0", | ||
"@typescript-eslint/parser": "^2.27.0", | ||
"autoprefixer": "^9.7.6", | ||
"autoprefixer": "^10.3.7", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^26.0.1", | ||
"babel-plugin-transform-define": "^2.0.0", | ||
"babel-plugin-transform-define": "^2.0.1", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
"eslint-plugin-json": "^2.1.1", | ||
"eslint-plugin-json": "^3.1.0", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"eslint-plugin-react": "^7.19.0", | ||
"gatsby-plugin-catch-links": "^2.2.1", | ||
"gatsby-plugin-feed": "^2.4.1", | ||
"gatsby-plugin-google-analytics": "^2.2.2", | ||
"gatsby-plugin-manifest": "2.2.23", | ||
"gatsby-plugin-postcss": "^2.2.1", | ||
"gatsby-plugin-react-helmet": "^3.2.1", | ||
"eslint-plugin-react": "^7.26.1", | ||
"gatsby-plugin-catch-links": "^3.14.0", | ||
"gatsby-plugin-feed": "^3.14.0", | ||
"gatsby-plugin-google-analytics": "^3.14.0", | ||
"gatsby-plugin-manifest": "^3.14.0", | ||
"gatsby-plugin-postcss": "^4.14.0", | ||
"gatsby-plugin-react-helmet": "^4.14.0", | ||
"gatsby-plugin-sentry": "^1.0.1", | ||
"gatsby-plugin-sharp": "2.2.32", | ||
"gatsby-plugin-sitemap": "^2.3.1", | ||
"gatsby-plugin-svgr": "^2.0.2", | ||
"gatsby-plugin-twitter": "^2.2.2", | ||
"gatsby-plugin-typescript": "^2.3.1", | ||
"gatsby-plugin-webpack-bundle-analyzer": "^1.0.5", | ||
"gatsby-remark-autolink-headers": "^2.2.1", | ||
"gatsby-remark-copy-linked-files": "^2.2.1", | ||
"gatsby-plugin-sharp": "^3.14.1", | ||
"gatsby-plugin-sitemap": "^4.10.0", | ||
"gatsby-plugin-svgr": "^3.0.0-beta.0", | ||
"gatsby-plugin-twitter": "^3.14.0", | ||
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.25", | ||
"gatsby-remark-autolink-headers": "^4.11.0", | ||
"gatsby-remark-copy-linked-files": "^4.11.0", | ||
"gatsby-remark-embed-gist": "^1.1.9", | ||
"gatsby-remark-embedder": "^2.0.0", | ||
"gatsby-remark-embedder": "^5.0.0", | ||
"gatsby-remark-external-links": "^0.0.4", | ||
"gatsby-remark-images": "^3.2.2", | ||
"gatsby-remark-prismjs": "^3.4.1", | ||
"gatsby-remark-images": "^5.11.0", | ||
"gatsby-remark-prismjs": "^5.11.0", | ||
"gatsby-remark-relative-images": "0.2.3", | ||
"gatsby-remark-responsive-iframe": "^2.3.1", | ||
"gatsby-remark-smartypants": "^2.2.1", | ||
"gatsby-source-filesystem": "^2.2.2", | ||
"gatsby-transformer-remark": "^2.7.1", | ||
"gatsby-transformer-sharp": "2.2.23", | ||
"gatsby-remark-responsive-iframe": "^4.11.0", | ||
"gatsby-remark-smartypants": "^4.11.0", | ||
"gatsby-source-filesystem": "^3.14.0", | ||
"gatsby-transformer-remark": "^4.11.0", | ||
"gatsby-transformer-sharp": "^3.14.0", | ||
"hast-util-select": "^4.0.0", | ||
"husky": "^4.2.3", | ||
"jest": "^26.0.1", | ||
"lint-staged": "^10.1.2", | ||
"jest": "^27.3.0", | ||
"lint-staged": "^11.2.3", | ||
"postcss-color-mod-function": "^3.0.3", | ||
"postcss-custom-media": "^7.0.8", | ||
"postcss-custom-properties": "^9.1.1", | ||
"postcss-mixins": "^6.2.3", | ||
"postcss-nested": "^4.2.1", | ||
"prettier": "^2.2.1", | ||
"rehype-parse": "^6.0.2", | ||
"rehype-stringify": "^7.0.0", | ||
"remark": "^12.0.0", | ||
"remark-html": "^13.0.2", | ||
"postcss-custom-media": "^8.0.0", | ||
"postcss-custom-properties": "^12.0.0", | ||
"postcss-mixins": "^8.1.0", | ||
"postcss-nested": "^5.0.6", | ||
"prettier": "^2.4.1", | ||
"rehype-parse": "^7.0.1", | ||
"rehype-stringify": "^8.0.0", | ||
"remark": "^13.0.0", | ||
"remark-html": "^13.0.1", | ||
"remark-parse": "^8.0.2", | ||
"stylelint": "^13.3.0", | ||
"stylelint-config-standard": "^20.0.0", | ||
"stylelint-config-standard": "^22.0.0", | ||
"typescript": "^3.8.3", | ||
"unist-util-remove-position": "^2.0.1" | ||
"unist-util-remove-position": "^3.0.0" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ | |
require('dotenv').config() | ||
const path = require('path') | ||
const PRODUCTION_PREFIX = 'dvc-org-prod' | ||
const { mkdirSync } = require('fs') | ||
|
||
const { DEPLOY_OPTIONS } = process.env | ||
const { DEPLOY_OPTIONS, USE_PRODUCTION_CACHE } = process.env | ||
const clearCloudflareCache = require('./clear-cloudflare-cache') | ||
|
||
// Generate deploy options from a comma separated string in the DEPLOY_OPTIONS | ||
|
@@ -20,6 +21,7 @@ const deployOptions = DEPLOY_OPTIONS | |
: { | ||
download: true, | ||
build: true, | ||
retry: true, | ||
upload: true, | ||
clean: true, | ||
clearCloudflareCache: true | ||
|
@@ -69,9 +71,8 @@ const { | |
cleanEntry | ||
} = require('./s3-utils') | ||
const { move } = require('fs-extra') | ||
const { downloadAllFromS3, uploadAllToS3, cleanAllLocal } = withEntries( | ||
cacheDirs | ||
) | ||
const { downloadAllFromS3, uploadAllToS3, cleanAllLocal } = | ||
withEntries(cacheDirs) | ||
|
||
function run(command) { | ||
execSync(command, { | ||
|
@@ -86,32 +87,42 @@ async function main() { | |
// This greatly speeds up PR initial build time. | ||
|
||
if (deployOptions.download) { | ||
if (emptyPrefix) { | ||
if (USE_PRODUCTION_CACHE) { | ||
console.warn('USE_PRODUCTION_CACHE is set, downloading from production') | ||
await downloadAllFromS3(PRODUCTION_PREFIX) | ||
} else if (emptyPrefix) { | ||
console.warn( | ||
`The current prefix "${s3Prefix}" is empty! Attempting to fall back on production cache.` | ||
) | ||
await downloadAllFromS3(PRODUCTION_PREFIX) | ||
} else { | ||
await downloadAllFromS3(s3Prefix) | ||
} | ||
mkdirSync('.cache/json', { recursive: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mitigation for gatsbyjs/gatsby#33262, already a PR to fix it in gatsbyjs/gatsby#33431 |
||
} | ||
|
||
if (deployOptions.build) { | ||
try { | ||
run('yarn build') | ||
} catch (buildError) { | ||
// Sometimes gatsby build fails because of bad cache. | ||
// Clear it and try again. | ||
|
||
console.error('------------------------\n\n') | ||
console.error('The first Gatsby build attempt failed!\n') | ||
console.error(buildError) | ||
console.error('\nRetrying with a cleared cache:\n') | ||
|
||
// Clear only .cache so we re-use images | ||
await cleanEntry(cacheDirs[1]) | ||
|
||
run('yarn build') | ||
if (deployOptions.retry) { | ||
// Sometimes gatsby build fails because of bad cache. | ||
// Clear it and try again. | ||
|
||
console.error('------------------------\n\n') | ||
console.error('The first Gatsby build attempt failed!\n') | ||
console.error(buildError) | ||
console.error('\nRetrying with a cleared cache:\n') | ||
|
||
// Clear only .cache so we re-use images | ||
await cleanEntry(cacheDirs[1]) | ||
|
||
run('yarn build') | ||
} else { | ||
throw new Error( | ||
'The first Gatsby build attempt failed, and DEPLOY_OPTIONS does not include "retry"' | ||
) | ||
} | ||
Comment on lines
+108
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just here to debug caching without wasting time on the rebuild if it fails. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
NEWPWD="/tmp/gatsby-build" | ||
mv $OLDPWD $NEWPWD | ||
ln -s $NEWPWD $OLDPWD | ||
cd $NEWPWD | ||
./scripts/deploy-with-s3.js | ||
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moves the unstable Heroku build path (exposed via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point between our current pinned versions and now, the default placeholder got changed from blur to a "dominant color" strategy. I've changed the default back to blur for parity.
It doesn't seem there's any hit to build time for doing this, my first attempt looked like it but was a false positive.