-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy-to-heroku.ts
60 lines (47 loc) · 1.28 KB
/
deploy-to-heroku.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import child_process from 'child_process';
class Deployer {
readonly processType: string = 'web';
constructor(readonly herokuAppName: string) {
}
get containerTag() {
return `registry.heroku.com/${this.herokuAppName}/${this.processType}`;
}
private runSync(cmdline: string) {
console.log(`$ ${cmdline}`)
child_process.execSync(cmdline, {stdio: 'inherit'});
}
loginToRegistry() {
this.runSync(`heroku container:login`);
return this;
}
pullFromRegistry() {
this.runSync(`docker pull ${this.containerTag}`);
return this;
}
pushToRegistry() {
this.runSync(`docker push ${this.containerTag}`);
return this;
}
buildContainer() {
this.runSync(`docker build --cache-from ${this.containerTag}:latest -t ${this.containerTag} .`);
return this;
}
releaseContainer() {
this.runSync(`heroku container:release -a ${this.herokuAppName} ${this.processType}`);
return this;
}
}
if (!module.parent) {
const herokuAppName = process.argv[2];
if (!herokuAppName) {
console.log(`usage: deploy-to-heroku <heroku app name>`);
process.exit(1);
}
const deployer = new Deployer(herokuAppName);
deployer
.loginToRegistry()
.pullFromRegistry()
.buildContainer()
.pushToRegistry()
.releaseContainer();
}