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

Commit 34b612a

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

File tree

6 files changed

+69
-50
lines changed

6 files changed

+69
-50
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

+37-27
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,68 @@
11
language: node_js
22
sudo: false
33
node_js:
4-
- '6'
4+
- '6'
5+
56
cache:
67
yarn: true
78
directories:
8-
- bower_components
9+
- bower_components
10+
911
branches:
1012
except:
11-
- "/^g3_.*$/"
13+
- "/^g3_.*$/"
14+
1215
env:
1316
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
17+
- JOB=ci-checks
18+
- JOB=unit BROWSER_PROVIDER=saucelabs
19+
- JOB=docs-e2e BROWSER_PROVIDER=saucelabs
20+
- JOB=e2e TEST_TARGET=jqlite BROWSER_PROVIDER=saucelabs
21+
- JOB=e2e TEST_TARGET=jquery BROWSER_PROVIDER=saucelabs
1922
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=
23+
# node 4 likes the G++ v4.8 compiler
24+
# see https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Node.js-v4-(or-io.js-v3)-compiler-requirements
25+
- CXX=g++-4.8
26+
- SAUCE_USERNAME=angular-ci
27+
- SAUCE_ACCESS_KEY=9b988f434ff8-fbca-8aa4-4ae3-35442987
28+
- LOGS_DIR=/tmp/angular-build/logs
29+
- BROWSER_PROVIDER_READY_FILE=/tmp/browsersprovider-tunnel-ready
30+
- secure: oTBjhnOKhs0qDSKTf7fE4f6DYiNDPycvB7qfSF5QRIbJK/LK/J4UtFwetXuXj79HhUZG9qnoT+5e7lPaiaMlpsIKn9ann7ffqFWN1E8TMtpJF+AGigx3djYElwfgf5nEnFUFhwjFzvbfpZNnxVGgX5YbIZpe/WUbHkP4ffU0Wks=
31+
2632
addons:
2733
apt:
2834
sources:
29-
- ubuntu-toolchain-r-test
35+
- ubuntu-toolchain-r-test
3036
packages:
31-
- g++-4.8
37+
- g++-4.8
38+
3239
before_script:
33-
- du -sh ./node_modules ./bower_components/ || true
34-
- "./scripts/travis/before_build.sh"
40+
- du -sh ./node_modules ./bower_components/ || true
41+
- "./scripts/travis/before_build.sh"
3542
script:
36-
- "./scripts/travis/build.sh"
43+
- "./scripts/travis/build.sh"
44+
3745
after_script:
38-
- "./scripts/travis/tear_down_browser_provider.sh"
39-
- "./scripts/travis/print_logs.sh"
46+
- "./scripts/travis/tear_down_browser_provider.sh"
47+
- "./scripts/travis/print_logs.sh"
48+
4049
notifications:
4150
webhooks:
4251
urls:
43-
- https://webhooks.gitter.im/e/d2120f3f2bb39a4531b2
44-
- http://104.197.9.155:8484/hubot/travis/activity
45-
on_success: always
46-
on_failure: always
47-
on_start: always
52+
- https://webhooks.gitter.im/e/d2120f3f2bb39a4531b2
53+
- http://104.197.9.155:8484/hubot/travis/activity #hubot-server
54+
on_success: always # options: [always|never|change] default: always
55+
on_failure: always # options: [always|never|change] default: always
56+
on_start: always # default: false
57+
4858
jobs:
4959
include:
5060
- stage: deploy
5161
env:
5262
- JOB=deploy
5363
before_script: skip
5464
script:
55-
- "./scripts/travis/build.sh"
65+
- "./scripts/travis/build.sh"
5666
# Work around the 10min Travis timeout so the code.angularjs firebase+gcs code deploy can complete
5767
before_deploy: |
5868
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)