Skip to content

Commit

Permalink
chore(ci): copy deployment files inside the respective Firebase direc…
Browse files Browse the repository at this point in the history
…tories

We have the `scripts/{code,docs}.angularjs.org-firebase/` directories,
which contain the necessary code and config for deploying built files to
the `code-angularjs-org` and `docs-angularjs-org` Firebase projects
respectively.

Previously, some of the files that needed to be deployed to Firebase (or
Google Cloud) were placed outside these directories (e.g. in
`deploy/{code,docs}/`).

Since these files are only used for deploying to Firebase/Google Cloud,
this commit changes the deployment process to instead copy the files
inside the directories. In a subsequent commit, this will allow
simplifying the deployment process, by running it from inside each
directory instead of having to copy the `firebase.json` files to the
repository root (and adjust the paths).

These are the destination directory changes:

| Before       | After                                       |
|--------------|---------------------------------------------|
| deploy/code/ | scripts/code.angularjs.org-firebase/deploy/ |
| deploy/docs/ | scripts/docs.angularjs.org-firebase/deploy/ |
  • Loading branch information
gkalpak authored and Ankush Agarwal committed Jun 29, 2022
1 parent 1dc22b6 commit 33c540e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ jobs:
- custom_attach_workspace
- init_environment
- skip_unless_tag_or_master_or_stable_branch
- run: ls deploy/code
- run: ls scripts/code.angularjs.org-firebase/deploy
- run:
name: Authenticate and configure Docker
command: |
Expand All @@ -369,7 +369,7 @@ jobs:
- run:
name: Sync files to code.angularjs.org
command: |
gsutil -m rsync -r deploy/code gs://code-angularjs-org-338b8.appspot.com
gsutil -m rsync -r scripts/code.angularjs.org-firebase/deploy gs://code-angularjs-org-338b8.appspot.com
# The `deploy-docs` job should only run when all of these conditions are true for the build:
# - It is for the `angular/angular.js` repository (not a fork).
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/build/
/deploy/
/benchpress-build/
.DS_Store
gen_docs.disable
Expand All @@ -23,5 +22,7 @@ npm-debug.log
.vscode
*.log
*.stackdump
scripts/code.angularjs.org-firebase/deploy
scripts/docs.angularjs.org-firebase/deploy
scripts/docs.angularjs.org-firebase/functions/content
/firebase.json
17 changes: 9 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var semver = require('semver');
var exec = require('shelljs').exec;
var pkg = require(__dirname + '/package.json');

var codeScriptFolder = util.codeScriptFolder;
var docsScriptFolder = util.docsScriptFolder;

// Node.js version checks
Expand Down Expand Up @@ -166,9 +167,9 @@ module.exports = function(grunt) {
build: ['build'],
tmp: ['tmp'],
deploy: [
'deploy/docs',
'deploy/code',
docsScriptFolder + '/functions/html'
codeScriptFolder + '/deploy',
docsScriptFolder + '/deploy',
docsScriptFolder + '/functions/content'
]
},

Expand Down Expand Up @@ -372,7 +373,7 @@ module.exports = function(grunt) {
{
cwd: 'build',
src: '**',
dest: 'deploy/code/' + deployVersion + '/',
dest: codeScriptFolder + '/deploy/' + deployVersion + '/',
expand: true
}
]
Expand All @@ -382,19 +383,19 @@ module.exports = function(grunt) {
// The source files are needed by the embedded examples in the docs app.
{
src: ['build/angular*.{js,js.map,min.js}', 'build/sitemap.xml'],
dest: 'deploy/docs/',
dest: docsScriptFolder + '/deploy/',
expand: true,
flatten: true
},
{
cwd: 'build/docs',
src: ['**', '!ptore2e/**', '!index*.html'],
dest: 'deploy/docs/',
dest: docsScriptFolder + '/deploy/',
expand: true
},
{
src: 'build/docs/index-production.html',
dest: 'deploy/docs/index.html'
dest: docsScriptFolder + '/deploy/index.html'
},
{
src: 'build/docs/index-production.html',
Expand All @@ -403,7 +404,7 @@ module.exports = function(grunt) {
{
cwd: 'build/docs',
src: 'partials/**',
dest: docsScriptFolder + '/functions/content',
dest: docsScriptFolder + '/functions/content/',
expand: true
}
]
Expand Down
10 changes: 7 additions & 3 deletions lib/grunt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ var spawn = require('npm-run').spawn;

var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP mode. */\n\n';

const codeScriptFolder = 'scripts/code.angularjs.org-firebase';
const docsScriptFolder = 'scripts/docs.angularjs.org-firebase';

module.exports = {

codeScriptFolder,

docsScriptFolder,

startKarma: function(config, singleRun, done) {
var browsers = grunt.option('browsers');
var reporters = grunt.option('reporters');
Expand Down Expand Up @@ -303,17 +308,16 @@ module.exports = {
};
},

docsScriptFolder,

// Our Firebase projects are in subfolders, but the firebase tool expects them in the root,
// so we need to modify the upload folder path and copy the file into the root
firebaseDocsJsonForCI: function() {
var fileName = docsScriptFolder + '/firebase.json';
var json = grunt.file.readJSON(fileName);

(json.hosting || (json.hosting = {})).public = 'deploy/docs';
(json.hosting || (json.hosting = {})).public = docsScriptFolder + '/deploy';
(json.functions || (json.functions = {})).source = docsScriptFolder + '/functions';

grunt.file.write('firebase.json', JSON.stringify(json));
}

};
16 changes: 8 additions & 8 deletions scripts/code.angularjs.org-firebase/readme.firebase.code.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Firebase for code.angularjs.org
===============================

This folder contains the Google Firebase scripts for the code.angularjs.org setup.
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.
`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.

functions/index.js also contains a rule that deletes outdated build zip files
from the snapshot and snapshot-stable folders when new zip files are uploaded.
`functions/index.js` also contains a rule that deletes outdated build zip files from the snapshot and snapshot-stable folders when new zip files are uploaded.

The deployment to the Google Cloud Storage bucket happens automatically via CI.
See the .circleci/config.yml file in the repository root.
See `/scripts/docs.angularjs.org-firebase/readme.firebase.code.md` for the Firebase deployment to `docs.angularjs.org`.

See /readme.firebase.docs.md for the firebase deployment to docs.angularjs.org
# Continuous integration

The code is deployed to Google Firebase hosting and functions as well as to the Google Cloud Storage bucket automatically via CI.
See `.circleci/config.yml` for the complete deployment config and build steps.
2 changes: 1 addition & 1 deletion scripts/docs.angularjs.org-firebase/firebase.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hosting": {
"public": "../../deploy/docs",
"public": "deploy",
"redirects": [
{
"source": "/error/:namespace\\::error*",
Expand Down
23 changes: 10 additions & 13 deletions scripts/docs.angularjs.org-firebase/readme.firebase.docs.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
Firebase for docs.angularjs.org
===============================

This folder contains the Google Firebase scripts for the `docs.angularjs.org` setup.

See `/scripts/code.angularjs.org-firebase/readme.firebase.code.md` for the Firebase deployment to `code.angularjs.org`.

# Continuous integration

The docs are deployed to Google Firebase hosting via a CI deployment config, which expects
firebase.json to be in the repository root, which is done by a Grunt task
(`firebaseDocsJsonForCI` which is included in `prepareDeploy`).
The `firebaseDocsJsonForCI` task modifies the paths in the `firebase.json` and copies it to the
repository root.
The docs are deployed to Google Firebase hosting via a CI deployment config, which expects `firebase.json` to be in the repository root, which is done by a Grunt task (`firebaseDocsJsonForCI` which is included in `prepareDeploy`).
The `firebaseDocsJsonForCI` task modifies the paths in the `firebase.json` and copies it to the repository root.

See .circleci/config.yml for the complete deployment config and build steps.
See `.circleci/config.yml` for the complete deployment config and build steps.

# Serving locally:

- Run `yarn grunt package`.
This builds the files that will be deployed.

- Run `yarn grunt prepareDeploy`.
This copies docs content files into deploy/docs and the partials for Search Engine AJAX
Crawling into ./functions/content.
It also moves the firebase.json file to the root folder, where the firebase-cli expects it
This copies docs content files into `./deploy` and the partials for Search Engine AJAX Crawling into `./functions/content`.
It also moves the `firebase.json` file to the root folder, where the firebase-cli expects it.

- Run `firebase serve --only functions,hosting`
Creates a server at localhost:5000 that serves from deploy/docs and uses the local function

See /scripts/code.angularjs.org-firebase/readme.firebase.code.md for the firebase deployment to
code.angularjs.org
Creates a server at http://localhost:5000 that serves from `./deploy` and uses the local function.

0 comments on commit 33c540e

Please sign in to comment.