-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.orig.js
115 lines (107 loc) · 3.41 KB
/
index.orig.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'use strict';
// Modules
const _ = require('lodash');
const ip = require('ip');
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
// Default env values
const defaults = {
config: {
appEnv: {
COLUMNS: 256,
LANDO: 'ON',
LANDO_WEBROOT_USER: 'www-data',
LANDO_WEBROOT_GROUP: 'www-data',
TERM: 'xterm',
},
appLabels: {
'io.lando.container': 'TRUE',
},
},
};
/*
* Helper to get user conf
*/
const uc = (uid, gid, username) => ({
config: {
appEnv: {
LANDO_HOST_UID: uid,
LANDO_HOST_GID: gid,
LANDO_HOST_USER: username,
},
gid,
uid,
username,
},
});
/*
* Helper to get ca run object
*/
const getCaRunner = (project, files) => ({
id: [project, 'ca', '1'].join('_'),
compose: files,
project: project,
cmd: '/setup-ca.sh',
opts: {
mode: 'attach',
services: ['ca'],
autoRemove: true,
},
});
module.exports = lando => {
// Set some stuff and set seom stuff up
const caDir = path.join(lando.config.userConfRoot, 'certs');
const caDomain = lando.config.domain;
const caCert = path.join(caDir, `${caDomain}.pem`);
const caKey = path.join(caDir, `${caDomain}.key`);
const caProject = `landocasetupkenobi38ahsoka${lando.config.instance}`;
const sshDir = path.join(lando.config.home, '.ssh');
// Ensure some dirs exist before we start
_.forEach([caDir, sshDir], dir => mkdirp.sync(dir));
// Make sure we have a host-exposed root ca if we don't already
// NOTE: we don't run this on the caProject otherwise infinite loop happens!
lando.events.on('pre-engine-start', 2, data => {
if (!fs.existsSync(caCert) && data.project !== caProject) {
const LandoCa = lando.factory.get('_casetup');
const env = _.cloneDeep(lando.config.appEnv);
const labels = _.cloneDeep(lando.config.appLabels);
const caData = new LandoCa(lando.config.userConfRoot, env, labels);
const caFiles = lando.utils.dumpComposeData(caData, caDir);
lando.log.debug('setting up Lando Local CA at %s', caCert);
return lando.engine.run(getCaRunner(caProject, caFiles));
}
});
// Let's also make a copy of caCert with the standarized .crt ending for better linux compat
// See: https://github.com/lando/lando/issues/1550
lando.events.on('pre-engine-start', 3, data => {
const caNormalizedCert = path.join(caDir, `${caDomain}.crt`);
if (fs.existsSync(caCert) && !fs.existsSync(caNormalizedCert)) {
// @NOTE: we need to use pre node 8.x-isms because pld roles with node 7.9 currently
fs.writeFileSync(caNormalizedCert, fs.readFileSync(caCert));
}
});
// Return some default things
return _.merge({}, defaults, uc(lando.user.getUid(), lando.user.getGid(), lando.user.getUsername()), {config: {
appEnv: {
LANDO_CA_CERT: '/lando/certs/' + path.basename(caCert),
LANDO_CA_KEY: '/lando/certs/' + path.basename(caKey),
LANDO_CONFIG_DIR: lando.config.userConfRoot,
LANDO_DOMAIN: lando.config.domain,
LANDO_HOST_HOME: lando.config.home,
LANDO_HOST_OS: lando.config.os.platform,
LANDO_HOST_IP: (process.platform === 'linux') ? ip.address() : 'host.docker.internal',
LANDO_LEIA: _.toInteger(lando.config.leia),
LANDO_MOUNT: '/app',
},
appLabels: {
'io.lando.id': lando.config.instance,
},
bindAddress: '127.0.0.1',
caCert,
caDomain,
caKey,
caProject,
maxKeyWarning: 10,
}});
};