-
Notifications
You must be signed in to change notification settings - Fork 27.4k
chore: deploy docs|code .angularjs.org to Firebase via Travis #16093
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"default": "docs-angularjs-org-9p2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"hosting": { | ||
"public": "build/docs", | ||
"ignore": [ | ||
"/index.html", | ||
"/index-debug.html", | ||
"/index-jquery.html" | ||
], | ||
"rewrites": [ | ||
{ | ||
"source": "/", | ||
"destination": "/index-production.html" | ||
}, | ||
{ | ||
"source": "/index.html", | ||
"destination": "/index-production.html" | ||
}, | ||
{ | ||
"source": "**/*!(.jpg|.jpeg|.gif|.png|.html|.js|.json|.css|.svg|.ttf|.woff|.woff2|.eot)", | ||
"destination": "/index-production.html" | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Firebase for docs.angularjs.org | ||
=============================== | ||
|
||
The docs are deployed to Google Firebase hosting via Travis deployment config, which expects | ||
firebase.json and .firebaserc in the repository root. | ||
|
||
See travis.yml for the complete deployment config. | ||
|
||
See /scripts/code.angularjs.org-firebase/readme.firebase.code.md for the firebase deployment to | ||
code.angularjs.org |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"env": { | ||
"es6": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"default": "code-angularjs-org-338b8" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"hosting": { | ||
"public": "public", | ||
"redirects": [ | ||
{ | ||
"source": "/:version/docs", | ||
"destination": "/:version/docs/index.html", | ||
"type": 301 | ||
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. I am less concerned about this redirect but it is a bit sad that Firebase doesn't support it via rewrites :-(. 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. For some reason, redirect to |
||
} | ||
], | ||
"rewrites": [ | ||
{ | ||
"source": "/**", | ||
"function": "sendStoredFile" | ||
} | ||
] | ||
}, | ||
"storage": { | ||
"rules": "storage.rules" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict'; | ||
|
||
const functions = require('firebase-functions'); | ||
const gcs = require('@google-cloud/storage')(); | ||
const path = require('path'); | ||
|
||
const gcsBucketId = `${process.env.GCLOUD_PROJECT}.appspot.com`; | ||
const LOCAL_TMP_FOLDER = '/tmp/'; | ||
|
||
const BROWSER_CACHE_DURATION = 300; | ||
const CDN_CACHE_DURATION = 600; | ||
|
||
function sendStoredFile(request, response) { | ||
let filePathSegments = request.path.split('/').filter((segment) => { | ||
// Remove empty leading or trailing path parts | ||
return segment !== ''; | ||
}); | ||
|
||
const version = filePathSegments[0]; | ||
const isDocsPath = filePathSegments[1] === 'docs'; | ||
const lastSegment = filePathSegments[filePathSegments.length - 1]; | ||
const bucket = gcs.bucket(gcsBucketId); | ||
|
||
let downloadSource; | ||
let downloadDestination; | ||
let fileName; | ||
|
||
if (isDocsPath && filePathSegments.length === 2) { | ||
fileName = 'index.html'; | ||
filePathSegments = [version, 'docs', fileName]; | ||
} else { | ||
fileName = lastSegment; | ||
} | ||
|
||
downloadSource = path.join.apply(null, filePathSegments); | ||
downloadDestination = `${LOCAL_TMP_FOLDER}${fileName}`; | ||
|
||
downloadAndSend(downloadSource, downloadDestination).catch(error => { | ||
if (isDocsPath && error.code === 404) { | ||
fileName = 'index.html'; | ||
filePathSegments = [version, 'docs', fileName]; | ||
downloadSource = path.join.apply(null, filePathSegments); | ||
downloadDestination = `${LOCAL_TMP_FOLDER}${fileName}`; | ||
|
||
return downloadAndSend(downloadSource, downloadDestination); | ||
} | ||
|
||
return Promise.reject(error); | ||
}).catch(error => { | ||
let message = 'General error'; | ||
if (error.code === 404) { | ||
if (fileName.split('.').length === 1) { | ||
message = 'Directory listing is not supported'; | ||
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. This is a shame. Could we look into supporting this in a future PR? 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. Could we host directly from Google storage (something like this)? 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. Probably. But I'm not convinced it is worth the effort to basically split the config in two. At the moment, direct access to gcs is only needed to upload the files, everything else goes through firebase |
||
} else { | ||
message = 'File not found'; | ||
} | ||
} | ||
|
||
return response.status(error.code).send(message); | ||
}); | ||
|
||
function downloadAndSend(downloadSource, downloadDestination) { | ||
return bucket.file(downloadSource).download({ | ||
destination: downloadDestination | ||
}).then(() => { | ||
return response.status(200) | ||
.set({ | ||
'Cache-Control': `public, max-age=${BROWSER_CACHE_DURATION}, s-maxage=${CDN_CACHE_DURATION}` | ||
}) | ||
.sendFile(downloadDestination); | ||
}); | ||
} | ||
} | ||
|
||
exports.sendStoredFile = functions.https.onRequest(sendStoredFile); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "functions-firebase-code.angularjs.org", | ||
"description": "Cloud Functions to serve files from gcs to code.angularjs.org", | ||
"dependencies": { | ||
"@google-cloud/storage": "^1.1.1", | ||
"firebase-admin": "^4.2.1", | ||
"firebase-functions": "^0.5.9" | ||
}, | ||
"private": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
google-site-verification: googleb96cceae5888d79f.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>AngularJS</title> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
User-agent: * | ||
|
||
Disallow: /*docs/ | ||
Disallow: /*i18n/ | ||
Disallow: /*.zip$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Firebase for code.angularjs.org | ||
=============================== | ||
|
||
This folder contains the Google Firebase scripts for the code.angularjs.org setup. | ||
|
||
firebase.json contains the rewrite rules that route every subdirectory request to the cloud function | ||
in functions/index.js that serves the docs from the Firebase Google Cloud Storage bucket. | ||
|
||
The deployment to the Google Cloud Storage bucket happens automatically via Travis. See the travis.yml | ||
file in the repository root. | ||
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. Could be worth a link to the other doc here, just in case people come across this file when they are looking for the other firebase configuration. |
||
|
||
See /readme.firebase.docs.md for the firebase deployment to docs.angularjs.org |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
service firebase.storage { | ||
match /b/{bucket}/o { | ||
match /{allPaths=**} { | ||
allow read, write: if request.auth!=null; | ||
} | ||
} | ||
} |
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.
It might be worth linking to scripts/code.angularjs.org-firebase/readme.firebase.code.md (the different code.angularjs.org deployment) in this file too.