Skip to content

Commit

Permalink
Deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Apr 28, 2019
1 parent 8d2bbf8 commit cf8a5b9
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 14 deletions.
10 changes: 1 addition & 9 deletions TODO
@@ -1,14 +1,6 @@
# football

deploy script
- build
- rsync gen (delete disabled)
- rsync other
- invalidate cloudflare cache
- beta?
- yarn run deploy beta.basketball-gm.com
- check if arg contains basketball or football or neither
- use for dir on server
lint

death rate scale number games

Expand Down
4 changes: 4 additions & 0 deletions flow-typed/env.js
@@ -1,9 +1,13 @@
// https://github.com/facebook/flow/issues/1192 - build script guarantees SPORT is never null or undefined
declare class process {
static argv: string[];

static env: {
SPORT: string,
[string]: ?string,
};

static exit(code: number): void;

static hrtime(time?: [number, number]): [number, number];
}
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -14,6 +14,7 @@
"scripts": {
"start": "node tools/server.js",
"build": "node tools/build.js && node tools/build-js.js && node tools/minify-js.js && node tools/build-sw.js",
"deploy": "yarn run build && node tools/deploy.js",
"start-watch": "concurrently --kill-others 'yarn run start' 'yarn run watch'",
"watch": "node tools/pre-watch.js && concurrently --kill-others 'yarn run watch-css' 'yarn run watch-js'",
"watch-css": "node tools/watch-css.js",
Expand Down Expand Up @@ -79,6 +80,7 @@
"cheerio": "^1.0.0-rc.3",
"chokidar": "^2.1.5",
"clean-css": "^4.2.1",
"cloudflare": "^2.4.1",
"concurrently": "^4.1.0",
"envify": "^4.1.0",
"eslint": "^5.16.0",
Expand Down
12 changes: 8 additions & 4 deletions tools/buildFuncs.js
Expand Up @@ -85,8 +85,6 @@ const buildSW = async () => {
};

const setSport = () => {
console.log("Setting sport...");

if (process.env.SPORT === "football") {
replace({
regex: "basketball",
Expand Down Expand Up @@ -162,10 +160,16 @@ const genRev = () => {
};

const getSport = () => {
if (typeof process.env.SPORT === "string") {
if (
process.env.SPORT === "football" ||
process.env.SPORT === "basketball"
) {
return process.env.SPORT;
}
return "basketball";
if (process.env.SPORT === undefined) {
return "basketball";
}
throw new Error(`Invalid SPORT: ${process.env.SPORT}`);
};

const minifyJS = (name /*: string */) => {
Expand Down
86 changes: 86 additions & 0 deletions tools/deploy.js
@@ -0,0 +1,86 @@
// @flow

const { spawn } = require("child_process");
const cloudflare = require("cloudflare");
const build = require("./buildFuncs");
const cloudflareConfig = require("../../../.config/cloudflare.json");

const getSubdomain = () => {
if (process.argv[2] === "beta" || process.argv[2] === "play") {
return process.argv[2];
}
if (process.argv[2] === undefined) {
return "play";
}
throw new Error(
`Invalid subdomain ${
process.argv[2]
} - should be either beta or play (default is play)`,
);
};

const mySpawn = (command, args) => {
return new Promise(resolve => {
console.log(`${command} ${args.join(" ")}`);

const cmd = spawn(command, args, { shell: true, stdio: "inherit" });
cmd.on("close", code => {
if (code !== 0) {
console.log(`child process exited with code ${code}`);
process.exit(code);
}
resolve();
});
});
};

(async () => {
const subdomain = getSubdomain();
const sport = build.getSport();
const domain = `${subdomain}.${sport}-gm.com`;

console.log(`Deploying to ${domain}...`);

// Copy gen first, so index.html never links to partial file
console.log("Copying gen...");
await mySpawn("rsync", [
"-vhrl",
"./build/gen/",
`jersch50@garibaldi.dreamhost.com:/home/jersch50/${domain}/gen/`,
]);

console.log("Copying other files...");
const excludes = ["--exclude", "/gen"];
if (subdomain === "beta") {
excludes.push("--exclude", "/sw.js*");
}
await mySpawn("rsync", [
"-vhrl",
"--delete",
...excludes,
"./build/",
`jersch50@garibaldi.dreamhost.com:/home/jersch50/${domain}/`,
]);

if (subdomain !== "beta") {
console.log("Invalidating Cloudflare cache...");

const zone = cloudflareConfig.zones[sport];

const cf = cloudflare({
email: "jdscheff@gmail.com",
key: cloudflareConfig.apiKey,
});

const response = await cf.zones.purgeCache(zone, {
purge_everything: true,
});
if (!response.success) {
console.log(response);
}
} else {
console.log("No Cloudfare cache invalidation needed in beta");
}

console.log("\nDone!");
})();
74 changes: 73 additions & 1 deletion yarn.lock
Expand Up @@ -730,6 +730,11 @@ atob@^2.1.1:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==

autocreate@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/autocreate/-/autocreate-1.2.0.tgz#522167992c4172c15479e5f88f3486a452a40cba"
integrity sha1-UiFnmSxBcsFUeeX4jzSGpFKkDLo=

aws-sign2@~0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"
Expand Down Expand Up @@ -1292,6 +1297,11 @@ camelcase@^5.0.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

capture-stack-trace@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/capture-stack-trace/-/capture-stack-trace-1.0.1.tgz#a6c0bbe1f38f3aa0b92238ecb6ff42c344d4135d"
integrity sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw==

caseless@~0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
Expand Down Expand Up @@ -1443,6 +1453,19 @@ cliui@^4.0.0:
strip-ansi "^4.0.0"
wrap-ansi "^2.0.0"

cloudflare@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/cloudflare/-/cloudflare-2.4.1.tgz#11f5ba2a62bf5afef093a7517ce8f35716cfd81b"
integrity sha512-L1KMiguQ4J1GlHwPD1iSNU+Yw6R7cuYasdXWb1d1Vkx7LftdbfLVqekoe9RaN0gnPURSckC34+fuc8cyTbDkOg==
dependencies:
autocreate "^1.1.0"
es-class "^2.1.1"
got "^6.3.0"
https-proxy-agent "^2.1.1"
object-assign "^4.1.0"
should-proxy "^1.0.4"
url-pattern "^1.0.3"

code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
Expand Down Expand Up @@ -1642,6 +1665,13 @@ create-ecdh@^4.0.0:
bn.js "^4.1.0"
elliptic "^6.0.0"

create-error-class@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/create-error-class/-/create-error-class-3.0.2.tgz#06be7abef947a3f14a30fd610671d401bca8b7b6"
integrity sha1-Br56vvlHo/FKMP1hBnHUAbyot7Y=
dependencies:
capture-stack-trace "^1.0.0"

create-hash@^1.1.0, create-hash@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/create-hash/-/create-hash-1.2.0.tgz#889078af11a63756bcfb59bd221996be3a9ef196"
Expand Down Expand Up @@ -2176,6 +2206,11 @@ es-abstract@^1.11.0, es-abstract@^1.12.0, es-abstract@^1.5.1, es-abstract@^1.7.0
is-regex "^1.0.4"
object-keys "^1.0.12"

es-class@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/es-class/-/es-class-2.1.1.tgz#6ec2243b5a1e3581c0b7eecee0130c9c0d6fb2b7"
integrity sha1-bsIkO1oeNYHAt+7O4BMMnA1vsrc=

es-to-primitive@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.0.tgz#edf72478033456e8dda8ef09e00ad9650707f377"
Expand Down Expand Up @@ -2925,6 +2960,23 @@ globule@^1.0.0:
lodash "~4.17.10"
minimatch "~3.0.2"

got@^6.3.0:
version "6.7.1"
resolved "https://registry.yarnpkg.com/got/-/got-6.7.1.tgz#240cd05785a9a18e561dc1b44b41c763ef1e8db0"
integrity sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA=
dependencies:
create-error-class "^3.0.0"
duplexer3 "^0.1.4"
get-stream "^3.0.0"
is-redirect "^1.0.0"
is-retry-allowed "^1.0.0"
is-stream "^1.0.0"
lowercase-keys "^1.0.0"
safe-buffer "^5.0.1"
timed-out "^4.0.0"
unzip-response "^2.0.1"
url-parse-lax "^1.0.0"

got@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/got/-/got-7.1.0.tgz#05450fd84094e6bbea56f451a43a9c289166385a"
Expand Down Expand Up @@ -3167,7 +3219,7 @@ https-browserify@^1.0.0:
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=

https-proxy-agent@^2.2.0, https-proxy-agent@^2.2.1:
https-proxy-agent@^2.1.1, https-proxy-agent@^2.2.0, https-proxy-agent@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0"
integrity sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==
Expand Down Expand Up @@ -3552,6 +3604,11 @@ is-promise@^2.1.0:
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
integrity sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=

is-redirect@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-redirect/-/is-redirect-1.0.0.tgz#1d03dded53bd8db0f30c26e4f95d36fc7c87dc24"
integrity sha1-HQPd7VO9jbDzDCbk+V02/HyH3CQ=

is-regex@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491"
Expand Down Expand Up @@ -5888,6 +5945,11 @@ shell-quote@^1.4.2, shell-quote@^1.6.1:
array-reduce "~0.0.0"
jsonify "~0.0.0"

should-proxy@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/should-proxy/-/should-proxy-1.0.4.tgz#c805a501abf69539600634809e62fbf238ba35e4"
integrity sha1-yAWlAav2lTlgBjSAnmL78ji6NeQ=

signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
Expand Down Expand Up @@ -6670,6 +6732,11 @@ unstated@^2.1.1:
dependencies:
create-react-context "^0.1.5"

unzip-response@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"
integrity sha1-0vD3N9FrBhXnKmk17QQhRXLVb5c=

unzipper@^0.8.11:
version "0.8.14"
resolved "https://registry.yarnpkg.com/unzipper/-/unzipper-0.8.14.tgz#ade0524cd2fc14d11b8de258be22f9d247d3f79b"
Expand Down Expand Up @@ -6709,6 +6776,11 @@ url-parse-lax@^1.0.0:
dependencies:
prepend-http "^1.0.1"

url-pattern@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/url-pattern/-/url-pattern-1.0.3.tgz#0409292471b24f23c50d65a47931793d2b5acfc1"
integrity sha1-BAkpJHGyTyPFDWWkeTF5PStaz8E=

url-search-params-polyfill@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/url-search-params-polyfill/-/url-search-params-polyfill-5.1.0.tgz#f0405dcc2e921bf7f5fdf8c4e616f1e8088ef31b"
Expand Down

0 comments on commit cf8a5b9

Please sign in to comment.