Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 24892ef

Browse files
committed
fixup! chore: deploy docs|code .angularjs.org to Firebase via Travis
1 parent 7b43332 commit 24892ef

File tree

6 files changed

+58
-47
lines changed

6 files changed

+58
-47
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ performance/temp*.html
99
*~
1010
*.swp
1111
angular.js.tmproj
12-
/node_modules/
13-
/scripts/code.angularjs.org-firebase/functions/node_modules/
12+
node_modules/
1413
bower_components/
1514
angular.xcodeproj
1615
.idea

.travis.yml

+26-24
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
11
language: node_js
22
sudo: false
33
node_js:
4-
- '6'
4+
- '6'
55
cache:
66
yarn: true
77
directories:
8-
- bower_components
8+
- bower_components
99
branches:
1010
except:
11-
- "/^g3_.*$/"
11+
- "/^g3_.*$/"
1212
env:
1313
matrix:
14-
- JOB=ci-checks
15-
- JOB=unit BROWSER_PROVIDER=saucelabs
16-
- JOB=docs-e2e BROWSER_PROVIDER=saucelabs
17-
- JOB=e2e TEST_TARGET=jqlite BROWSER_PROVIDER=saucelabs
18-
- JOB=e2e TEST_TARGET=jquery BROWSER_PROVIDER=saucelabs
14+
- JOB=ci-checks
15+
- JOB=unit BROWSER_PROVIDER=saucelabs
16+
- JOB=docs-e2e BROWSER_PROVIDER=saucelabs
17+
- JOB=e2e TEST_TARGET=jqlite BROWSER_PROVIDER=saucelabs
18+
- JOB=e2e TEST_TARGET=jquery BROWSER_PROVIDER=saucelabs
1919
global:
20-
- CXX=g++-4.8
21-
- SAUCE_USERNAME=angular-ci
22-
- SAUCE_ACCESS_KEY=9b988f434ff8-fbca-8aa4-4ae3-35442987
23-
- LOGS_DIR=/tmp/angular-build/logs
24-
- BROWSER_PROVIDER_READY_FILE=/tmp/browsersprovider-tunnel-ready
25-
- secure: oTBjhnOKhs0qDSKTf7fE4f6DYiNDPycvB7qfSF5QRIbJK/LK/J4UtFwetXuXj79HhUZG9qnoT+5e7lPaiaMlpsIKn9ann7ffqFWN1E8TMtpJF+AGigx3djYElwfgf5nEnFUFhwjFzvbfpZNnxVGgX5YbIZpe/WUbHkP4ffU0Wks=
20+
# node 4 likes the G++ v4.8 compiler
21+
# see https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Node.js-v4-(or-io.js-v3)-compiler-requirements
22+
- CXX=g++-4.8
23+
- SAUCE_USERNAME=angular-ci
24+
- SAUCE_ACCESS_KEY=9b988f434ff8-fbca-8aa4-4ae3-35442987
25+
- LOGS_DIR=/tmp/angular-build/logs
26+
- BROWSER_PROVIDER_READY_FILE=/tmp/browsersprovider-tunnel-ready
27+
- secure: oTBjhnOKhs0qDSKTf7fE4f6DYiNDPycvB7qfSF5QRIbJK/LK/J4UtFwetXuXj79HhUZG9qnoT+5e7lPaiaMlpsIKn9ann7ffqFWN1E8TMtpJF+AGigx3djYElwfgf5nEnFUFhwjFzvbfpZNnxVGgX5YbIZpe/WUbHkP4ffU0Wks=
2628
addons:
2729
apt:
2830
sources:
29-
- ubuntu-toolchain-r-test
31+
- ubuntu-toolchain-r-test
3032
packages:
31-
- g++-4.8
33+
- g++-4.8
3234
before_script:
33-
- du -sh ./node_modules ./bower_components/ || true
34-
- "./scripts/travis/before_build.sh"
35+
- du -sh ./node_modules ./bower_components/ || true
36+
- "./scripts/travis/before_build.sh"
3537
script:
36-
- "./scripts/travis/build.sh"
38+
- "./scripts/travis/build.sh"
3739
after_script:
38-
- "./scripts/travis/tear_down_browser_provider.sh"
39-
- "./scripts/travis/print_logs.sh"
40+
- "./scripts/travis/tear_down_browser_provider.sh"
41+
- "./scripts/travis/print_logs.sh"
4042
notifications:
4143
webhooks:
4244
urls:
43-
- https://webhooks.gitter.im/e/d2120f3f2bb39a4531b2
44-
- http://104.197.9.155:8484/hubot/travis/activity
45+
- https://webhooks.gitter.im/e/d2120f3f2bb39a4531b2
46+
- http://104.197.9.155:8484/hubot/travis/activity
4547
on_success: always
4648
on_failure: always
4749
on_start: always
@@ -52,7 +54,7 @@ jobs:
5254
- JOB=deploy
5355
before_script: skip
5456
script:
55-
- "./scripts/travis/build.sh"
57+
- "./scripts/travis/build.sh"
5658
# Work around the 10min Travis timeout so the code.angularjs firebase+gcs code deploy can complete
5759
before_deploy: |
5860
function keep_alive() {

firebase.json

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@
22
"hosting": {
33
"public": "build/docs",
44
"ignore": [
5+
"/index.html",
56
"/index-debug.html",
67
"/index-jquery.html"
78
],
8-
"redirects": [
9+
"rewrites": [
910
{
1011
"source": "/",
11-
"destination": "/index-production.html",
12-
"type": 301
12+
"destination": "/index-production.html"
1313
},
1414
{
1515
"source": "/index.html",
16-
"destination": "/index-production.html",
17-
"type": 301
18-
}
19-
],
20-
"rewrites": [
16+
"destination": "/index-production.html"
17+
},
2118
{
2219
"source": "**/*!(.jpg|.jpeg|.gif|.png|.html|.js|.json|.css|.svg|.ttf|.woff|.woff2|.eot)",
2320
"destination": "/index-production.html"

readme.firebase.docs.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ The docs are deployed to Google Firebase hosting via Travis deployment config, w
55
firebase.json and .firebaserc in the repository root.
66

77
See travis.yml for the complete deployment config.
8+
9+
See /scripts/code.angularjs.org-firebase/readme.firebase.code.md for the firebase deployment to
10+
code.angularjs.org

scripts/code.angularjs.org-firebase/functions/index.js

+21-13
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@ const functions = require('firebase-functions');
44
const gcs = require('@google-cloud/storage')();
55
const path = require('path');
66

7-
const gcsBucket = 'code-angularjs-org-338b8.appspot.com';
7+
const gcsBucketId = `${process.env.GCLOUD_PROJECT}.appspot.com`;
88
const LOCAL_TMP_FOLDER = '/tmp/';
99

10+
const BROWSER_CACHE_DURATION = 300;
11+
const CDN_CACHE_DURATION = 600;
12+
1013
function sendStoredFile(request, response) {
1114
let filePathSegments = request.path.split('/').filter((segment) => {
15+
// Remove empty leading or trailing path parts
1216
return segment !== '';
1317
});
1418

1519
const version = filePathSegments[0];
1620
const isDocsPath = filePathSegments[1] === 'docs';
1721
const lastSegment = filePathSegments[filePathSegments.length - 1];
18-
let downloadPath;
22+
const bucket = gcs.bucket(gcsBucketId);
23+
24+
let downloadSource;
25+
let downloadDestination;
1926
let fileName;
2027

2128
if (isDocsPath && filePathSegments.length === 2) {
@@ -25,16 +32,17 @@ function sendStoredFile(request, response) {
2532
fileName = lastSegment;
2633
}
2734

28-
downloadPath = path.join.apply(null, filePathSegments);
35+
downloadSource = path.join.apply(null, filePathSegments);
36+
downloadDestination = `${LOCAL_TMP_FOLDER}${fileName}`;
2937

30-
const bucket = gcs.bucket(gcsBucket);
31-
32-
downloadAndSend().catch(error => {
38+
downloadAndSend(downloadSource, downloadDestination).catch(error => {
3339
if (isDocsPath && error.code === 404) {
3440
fileName = 'index.html';
3541
filePathSegments = [version, 'docs', fileName];
36-
downloadPath = path.join.apply(null, filePathSegments);
37-
return downloadAndSend();
42+
downloadSource = path.join.apply(null, filePathSegments);
43+
downloadDestination = `${LOCAL_TMP_FOLDER}${fileName}`;
44+
45+
return downloadAndSend(downloadSource, downloadDestination);
3846
}
3947

4048
return Promise.reject(error);
@@ -51,15 +59,15 @@ function sendStoredFile(request, response) {
5159
return response.status(error.code).send(message);
5260
});
5361

54-
function downloadAndSend() {
55-
return bucket.file(downloadPath).download({
56-
destination: `/tmp/${fileName}`
62+
function downloadAndSend(downloadSource, downloadDestination) {
63+
return bucket.file(downloadSource).download({
64+
destination: downloadDestination
5765
}).then(() => {
5866
return response.status(200)
5967
.set({
60-
'Cache-Control': 'public, max-age=300, s-maxage=600'
68+
'Cache-Control': `public, max-age=${BROWSER_CACHE_DURATION}, s-maxage=${CDN_CACHE_DURATION}`
6169
})
62-
.sendFile(`${LOCAL_TMP_FOLDER}${fileName}`);
70+
.sendFile(downloadDestination);
6371
});
6472
}
6573
}

scripts/code.angularjs.org-firebase/readme.firebase.code.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ in functions/index.js that serves the docs from the Firebase Google Cloud Storag
88

99
The deployment to the Google Cloud Storage bucket happens automatically via Travis. See the travis.yml
1010
file in the repository root.
11+
12+
See /readme.firebase.docs.md for the firebase deployment to docs.angularjs.org

0 commit comments

Comments
 (0)