File size: 1,659 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const { execSync } = require('child_process');
const error = require('./utils/error');
const parse = require('./utils/parse-argv');
const path = require('path');

const exec = cmd =>
  execSync(cmd, { cwd: path.join(__dirname, '../'), stdio: 'inherit' });

const { args } = parse(process.argv);

const VALID_SERVERS = ['all', 'api', 'hyperion'];

const serverType = s => (['api', 'hyperion'].includes(s) ? 'web' : 'worker');

let servers = args;

/*
 * Must provide at least one server
 */
if (servers.length === 0)
  error(
    'Server name missing',
    `Please provide one of the following server names: ${VALID_SERVERS.map(
      s => `"${s}"`
    ).join(', ')}`
  );

/*
 * Must provide valid server names
 */
servers.forEach(s => {
  if (VALID_SERVERS.indexOf(s) === -1)
    error(
      `Cannot deploy unknown server "${args[0]}"`,
      `Please provide one of the following server names: ${VALID_SERVERS.map(
        s => `"${s}"`
      ).join(', ')}`
    );
});

/*
 * Allow targetting all deployments
 */
if (servers.indexOf('all') > -1) {
  servers = VALID_SERVERS.filter(s => s !== 'all');
}

console.log(
  `Deploying the following servers: ${servers.map(s => `"${s}"`).join(', ')}`
);

/*
 * Build and push Docker images for each server
 */
servers.forEach(s => {
  const type = serverType(s);

  exec(
    `docker build -t spectrum_${s} -t registry.heroku.com/spectrum-chat-${s}/${type} -f docker/Dockerfile.${s} .`
  );

  exec(`docker push registry.heroku.com/spectrum-chat-${s}/${type}`);
});

/*
 * Release new images for each server
 */
servers.forEach(s => {
  exec(`heroku container:release ${serverType(s)} -a spectrum-chat-${s}`);
});