forked from GoogleChrome/web.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(firebase): reconfigure site to be hosted by firebase, fixes Goo…
…gleChrome#2722, fixes GoogleChrome#4382, fixes GoogleChrome#3913, fixes GoogleChrome#2687 (GoogleChrome#4381) * build(firebase): reconfigure site to be hosted by firebase * refactor: make tweaks based on feedback * build(deploy): use node 12 * Update src/build/output-permalink.js Co-authored-by: Rob Dodson <[email protected]> * Update src/build/output-permalink.js Co-authored-by: Rob Dodson <[email protected]> * build(firebase): add redirects.yaml and generate firebase.json on the fly Co-authored-by: Rob Dodson <[email protected]>
- Loading branch information
1 parent
cd36c94
commit 76eff20
Showing
61 changed files
with
3,605 additions
and
2,036 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
steps: | ||
- name: node:12 | ||
entrypoint: npm | ||
args: ['ci'] | ||
- name: node:12 | ||
entrypoint: npm | ||
args: ['run', 'cloud-secrets'] | ||
env: | ||
- 'PROJECT_ID=$PROJECT_ID' | ||
- name: node:12 | ||
entrypoint: npm | ||
args: ['run', 'build'] | ||
env: | ||
- 'ELEVENTY_ENV=prod' | ||
- name: node:12 | ||
entrypoint: npm | ||
args: ['run', 'firebase-config'] | ||
- name: 'gcr.io/$PROJECT_ID/firebase' | ||
args: ['deploy'] | ||
- name: node:12 | ||
entrypoint: npm | ||
args: ['run', 'algolia'] | ||
timeout: 1800s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"default": "web-dev-production-1" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,3 +83,5 @@ entrypoint.hashmanifest.json | |
|
||
# Temporary files | ||
.tmp | ||
.firebase | ||
firebase.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @fileoverview This file generates a `.env` file from the lastest active secrets stored | ||
* in the Google Cloud Secret Manager. This is ran from the Cloud Build Deploy script. | ||
*/ | ||
|
||
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); | ||
|
||
const client = new SecretManagerServiceClient(); | ||
|
||
const cloudSecrets = async () => { | ||
if (!process.env.PROJECT_ID) { | ||
return console.warn( | ||
'No Google Cloud Project ID found, no .env file is being generated.', | ||
); | ||
} | ||
|
||
console.log('Generating .env file.'); | ||
|
||
const project = `projects/${process.env.PROJECT_ID}`; | ||
let dotenv = ''; | ||
const fetchedSecrets = []; | ||
const [secretsList] = await client.listSecrets({parent: project}); | ||
|
||
for (const secretItem of secretsList) { | ||
const key = secretItem.name.split('/').pop(); | ||
const [versions] = await client.listSecretVersions({ | ||
parent: secretItem.name, | ||
}); | ||
const version = versions.find((v) => v.state === 'ENABLED'); | ||
|
||
if (version) { | ||
const [accessedSecret] = await client.accessSecretVersion({ | ||
name: version.name, | ||
}); | ||
const value = accessedSecret.payload.data.toString(); | ||
dotenv += `${key}=${value}\n`; | ||
fetchedSecrets.push(key); | ||
} | ||
} | ||
|
||
require('fs').writeFileSync('.env', dotenv); | ||
|
||
console.log( | ||
`The following environment variables have been added to the generated .env file: ${fetchedSecrets.join( | ||
', ', | ||
)}`, | ||
); | ||
}; | ||
|
||
cloudSecrets().catch((e) => { | ||
console.warn('Ooops, there was an error in generating the .env file.', e); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const yaml = require('js-yaml'); | ||
const fs = require('fs'); | ||
|
||
const redirectsYaml = fs.readFileSync('./redirects.yaml', 'utf8'); | ||
const {redirects: parsedRedirects} = yaml.safeLoad(redirectsYaml); | ||
|
||
const firebaseJson = require('./firebase.incl.json'); | ||
firebaseJson.hosting.redirects = parsedRedirects.reduce( | ||
(redirects, redirect) => { | ||
if (redirect.source && redirect.destination) { | ||
redirects.push({ | ||
source: redirect.source, | ||
destination: redirect.destination, | ||
type: 301, | ||
}); | ||
} | ||
return redirects; | ||
}, | ||
[], | ||
); | ||
|
||
fs.writeFileSync('./firebase.json', JSON.stringify(firebaseJson, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"hosting": { | ||
"public": "dist", | ||
"headers": [ | ||
{ | ||
"source": "**", | ||
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "public,max-age=31536000,immutable" | ||
} | ||
] | ||
} | ||
], | ||
"i18n": { | ||
"root": "/i18n" | ||
}, | ||
"redirects": [] | ||
}, | ||
"emulators": { | ||
"hosting": { | ||
"port": 8080 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.