forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.ts
88 lines (77 loc) · 2.92 KB
/
docker.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { Command } from 'commander';
import * as utils from './utils';
import * as contract from './contract';
const IMAGES = [
'server',
'prover',
'nginx',
'geth',
'dev-ticker',
'keybase',
'ci',
'exit-tool',
'dev-liquidity-token-watcher',
'zk-environment',
'event-listener',
'data-restore'
];
async function dockerCommand(command: 'push' | 'build', image: string) {
if (image == 'rust') {
await dockerCommand(command, 'server');
await dockerCommand(command, 'prover');
return;
}
if (!IMAGES.includes(image)) {
throw new Error(`Wrong image name: ${image}`);
}
if (image == 'keybase') {
image = 'keybase-secret';
}
if (command == 'build') {
await _build(image);
} else if (command == 'push') {
await _push(image);
}
}
async function _build(image: string) {
if (image == 'nginx') {
await utils.spawn('yarn explorer build');
}
if (image == 'server' || image == 'prover') {
await contract.build();
}
await utils.spawn(`CARGO_HOME=./cargo cargo fetch`);
const { stdout: imageTag } = await utils.exec('git rev-parse --short HEAD');
const latestImage = `-t matterlabs/${image}:latest`;
const taggedImage = ['nginx', 'server', 'prover'].includes(image) ? `-t matterlabs/${image}:${imageTag}` : '';
await utils.spawn(`DOCKER_BUILDKIT=1 docker build ${latestImage} ${taggedImage} -f ./docker/${image}/Dockerfile .`);
}
async function _push(image: string) {
await utils.spawn(`docker push matterlabs/${image}:latest`);
if (['nginx', 'server', 'prover', 'event-listener'].includes(image)) {
const { stdout: imageTag } = await utils.exec('git rev-parse --short HEAD');
await utils.spawn(`docker push matterlabs/${image}:${imageTag}`);
await utils.spawn(
`docker tag matterlabs/${image}:${imageTag} us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/${image}:${imageTag}`
);
await utils.spawn(`docker push us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/${image}:${imageTag}`);
}
}
export async function build(image: string) {
await dockerCommand('build', image);
}
export async function push(image: string) {
await dockerCommand('build', image);
await dockerCommand('push', image);
}
export async function restart(container: string) {
await utils.spawn(`docker-compose restart ${container}`);
}
export async function pull() {
await utils.spawn('docker-compose pull');
}
export const command = new Command('docker').description('docker management');
command.command('build <image>').description('build docker image').action(build);
command.command('push <image>').description('build and push docker image').action(push);
command.command('pull').description('pull all containers').action(pull);
command.command('restart <container>').description('restart container in docker-compose.yml').action(restart);