Skip to content

Commit

Permalink
Fix frontend deploy and Heroku staging (badges#1288)
Browse files Browse the repository at this point in the history
- Heroku reads the Node version from package.json. We're about to upgrade to Node 8 so this change to `engines` is only pre-emptive. It won't have any effect on the production servers.
- The production deploy scripts were missing the frontend files. This fixes that.
- This modifies the build setup to allow `BASE_URL=/`, which makes all requests relative to the page itself. That simplifies deploying the "debugging" frontend to the production servers, and makes it easy to host the frontend on Heroku.
  • Loading branch information
paulmelnikow authored Nov 29, 2017
1 parent f3965ae commit c5e31b5
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ before_script:
script:
- npm run lint
- npm run test:js
- if node_modules/.bin/check-node-version --node '< 8.0' > /dev/null; then echo "Skipping build."; else make website; fi
- if node_modules/.bin/check-node-version --node '< 8.0' > /dev/null; then echo "Skipping build."; else BASE_URL=/ npm run build; fi

jobs:
include:
Expand Down
15 changes: 6 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,28 @@ favicon:
node lib/badge-cli.js '' '' '#bada55' .png > favicon.png

website:
LONG_CACHE=false BASE_URL=https://img.shields.io npm run build
LONG_CACHE=false BASE_URL=/ npm run build

deploy: deploy-s0 deploy-s1 deploy-s2 deploy-gh-pages
deploy: website deploy-s0 deploy-s1 deploy-s2 deploy-gh-pages

deploy-s0:
# Ship a copy of the front end to each server for debugging.
# https://github.com/badges/shields/issues/1220
LONG_CACHE=false BASE_URL=https://s0.shields-server.com npm run build
git add -f Verdana.ttf private/secret.json index.html
git add -f Verdana.ttf private/secret.json build/
git commit -m'MUST NOT BE ON GITHUB'
git push -f s0 HEAD:master
git reset HEAD~1
git checkout master

deploy-s1:
LONG_CACHE=false BASE_URL=https://s1.shields-server.com npm run build
git add -f Verdana.ttf private/secret.json index.html
git add -f Verdana.ttf private/secret.json build/
git commit -m'MUST NOT BE ON GITHUB'
git push -f s1 HEAD:master
git reset HEAD~1
git checkout master

deploy-s2:
LONG_CACHE=false BASE_URL=https://s2.shields-server.com npm run build
git add -f Verdana.ttf private/secret.json index.html
git add -f Verdana.ttf private/secret.json build/
git commit -m'MUST NOT BE ON GITHUB'
git push -f s2 HEAD:master
git reset HEAD~1
Expand All @@ -43,7 +40,7 @@ deploy-gh-pages:
git checkout master

deploy-heroku:
git add -f Verdana.ttf private/secret.json index.html
git add -f Verdana.ttf private/secret.json build/
git commit -m'MUST NOT BE ON GITHUB'
git push -f heroku HEAD:master
git reset HEAD~1
Expand Down
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"NPM_CONFIG_PRODUCTION": {
"description": "Configure whether devDependencies are installed (they are needed for the build).",
"value": "false"
},
"BASE_URL": {
"description": "The base URL to use in the frontend build",
"value": "/"
}
},
"formation": {
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/badge-examples.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { URL } from '../lib/url-api';
import URLPath from 'url-path';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

function resolveUri (uri, baseUri, options) {
const { longCache } = options || {};
const result = new URL(uri, baseUri);
const result = new URLPath(uri, baseUri);
if (longCache) {
result.searchParams.maxAge = '2592000';
result.searchParams.set('maxAge', '2592000');
}
return result.href;
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/static-badge-uri.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { URL } from './url-api';
import URLPath from 'url-path';

export function encodeField(s) {
return encodeURIComponent(s.replace(/-/g, '--').replace(/_/g, '__'));
}

export default function staticBadgeUri(baseUri, subject, status, color, options) {
const path = [subject, status, color].map(encodeField).join('-');
const uri = new URL(`/badge/${path}.svg`, baseUri);
const uri = new URLPath(`/badge/${path}.svg`, baseUri);
Object.keys(options || {}).forEach(k => {
uri.searchParams.set(k, options[k]);
})
Expand Down
8 changes: 0 additions & 8 deletions frontend/lib/url-api.js

This file was deleted.

68 changes: 37 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@
"rimraf": "^2.6.2",
"sazerac": "^0.4.2",
"semver-regex": "^1.0.0",
"sinon": "^4.0.1"
"sinon": "^4.0.1",
"url-path": "^0.1.1"
},
"engines": {
"node": "6.x",
"node": "8.x",
"npm": "5.x"
}
}
1 change: 1 addition & 0 deletions public/_next
2 changes: 1 addition & 1 deletion public/index.html
1 change: 0 additions & 1 deletion public/logo.svg

This file was deleted.

1 change: 1 addition & 0 deletions public/static

0 comments on commit c5e31b5

Please sign in to comment.