/
services.js
138 lines (124 loc) · 3.84 KB
/
services.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
// Modules
const _ = require('lodash');
// Services that support SSL
const sslServices = ['nginx', 'nginx-drupal'];
// SQL services
const SQLServices = ['lagoon-mariadb', 'lagoon-postgres'];
/*
* Helper to map lagoon type data to a lando service
*/
const getLandoServiceType = type => {
switch (type) {
case 'basic': return 'lagoon-basic';
case 'elasticsearch': return 'lagoon-elasticsearch';
case 'nginx': return 'lagoon-nginx';
case 'nginx-drupal': return 'lagoon-nginx';
case 'none': return 'lagoon-none';
case 'mariadb': return 'lagoon-mariadb';
case 'mariadb-drupal': return 'lagoon-mariadb';
case 'node': return 'lagoon-node';
case 'php-cli': return 'lagoon-php-cli';
case 'php-cli-drupal': return 'lagoon-php-cli';
case 'php-fpm': return 'lagoon-php';
case 'python': return 'lagoon-python';
case 'redis': return 'lagoon-redis';
case 'ruby': return 'lagoon-ruby';
case 'solr': return 'lagoon-solr';
case 'solr-drupal': return 'lagoon-solr';
case 'postgres': return 'lagoon-postgres';
case 'postgres-drupal': return 'lagoon-postgres';
case 'varnish': return 'lagoon-varnish';
case 'varnish-drupal': return 'lagoon-varnish';
default: return false;
};
};
/*
* Helper to map lagoon type data to a flavor eg drupal
*/
const getFlavor = type => {
switch (type) {
case 'mariadb-drupal': return 'drupal';
case 'nginx-drupal': return 'drupal';
case 'node': return 'lando-node';
case 'php-cli-drupal': return 'drupal';
case 'solr-drupal': return 'drupal';
case 'postgres-drupal': return 'drupal';
default: return 'lagoon';
};
};
/*
* Helper to map into a lando service
*/
const getLandoService = lagoon => {
// Start with the defaults
const lando = {
name: lagoon.name,
image: lagoon.type,
flavor: getFlavor(lagoon.type),
type: getLandoServiceType(lagoon.type),
ssl: _.includes(sslServices, lagoon.type),
sslExpose: false,
lagoon: lagoon.compose,
config: _.get(lagoon, 'config', {}),
};
// If this is a php-cli service then add in the build steps
if (lando.type === 'lagoon-php-cli') {
lando.build_internal = _.get(lagoon, 'config.config.build', []);
}
// Return
return lando;
};
/*
* Helper to get service names by type
*/
const getServicesByType = (services, type) => _(services)
.filter(service => service.type === type)
.map('name')
.value();
/*
* Helper to get a lagoon envvar with a fallback based on flavor
*/
exports.getLagoonEnv = (service, key, fallback = 'lagoon') => {
return _.get(service, `lagoon.environment.${key}`, fallback);
};
/*
* Determines if we need to add extra services
*/
exports.getLandoAuxServices = (services = {}, config) => {
// If we can add mailhog, lets add it
if (!_.isEmpty(getServicesByType(services, 'lagoon-php'))) {
services.mailhog = {type: 'lagoon-mailhog:v1.0.0', hogfrom: getServicesByType(services, 'lagoon-php')};
}
// Add in lagoon CLI
// @TODO: do we want a legit lagoon service for this or is compose sufficient?
services.lagooncli = {
type: 'lando',
services: {
image: 'amazeeio/lagoon-cli',
command: 'tail -f /dev/null',
volumes: [
`${config.home}:/root`,
],
},
};
// Return it all
return services;
};
/*
* Maps parsed lagoon config into related Lando things
*/
exports.getLandoServices = (services = []) => _(services)
// Filter out services that are not supported yet
.filter(service => getLandoServiceType(service.type) !== false)
// Merge in other needed lando things
.map(service => _.merge({}, getLandoService(service)))
// Finally map to an object
.map(service => ([service.name, service])).fromPairs()
.value();
/*
* Returns SQL services
*/
exports.getSQLServices = (services = []) => _(services)
.filter(service => _.includes(SQLServices, service.type))
.value();