forked from change-metrics/monocle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.dhall
254 lines (233 loc) · 9.71 KB
/
docker-compose.dhall
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
-- # Monocle.
-- # Copyright (C) 2021 Monocle authors
-- #
-- # This program is free software: you can redistribute it and/or modify
-- # it under the terms of the GNU Affero General Public License as published
-- # by the Free Software Foundation, either version 3 of the License, or
-- # (at your option) any later version.
-- #
-- # This program is distributed in the hope that it will be useful,
-- # but WITHOUT ANY WARRANTY; without even the implied warranty of
-- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- # GNU Affero General Public License for more details.
-- #
-- # You should have received a copy of the GNU Affero General Public License
-- # along with this program. If not, see <https://www.gnu.org/licenses/>.
let Compose =
https://raw.githubusercontent.com/sbdchd/dhall-docker-compose/master/compose/v3/package.dhall
let monocleImage =
\(name : Text) ->
"quay.io/change-metrics/monocle_${name}:\${MONOCLE_VERSION:-latest}"
let buildContext =
\(name : Text) ->
{ context = "."
, dockerfile = "Dockerfile-${name}"
, args =
let -- todo: add default upstream
default =
Compose.ListOrDict.Dict
([] : List { mapKey : Text, mapValue : Text })
in default
}
let envFile = Some (Compose.StringOrList.String ".secrets")
let mkEnvDefault =
\(env-var-name : Text) ->
\(default-value : Text) ->
"\${" ++ env-var-name ++ ":-" ++ default-value ++ "}"
let mkPort =
\(env-var-prefix : Text) ->
\(default-port : Natural) ->
\(container-port : Natural) ->
Compose.StringOrNumber.String
( mkEnvDefault "MONOCLE_${env-var-prefix}_ADDR" "0.0.0.0"
++ ":"
++ mkEnvDefault
"MONOCLE_${env-var-prefix}_PORT"
(Natural/show default-port)
++ ":${Natural/show container-port}"
)
let mkHealthCheck =
\(command : Text) ->
Compose.Healthcheck::{
, test = Some (Compose.StringOrList.String command)
, retries = Some 6
, timeout = Some "60s"
}
let createElasticService =
\(dev : Bool) ->
let service =
{ image = Some
"docker.elastic.co/elasticsearch/elasticsearch:7.10.1"
, healthcheck = Some
( mkHealthCheck
"curl --silent --fail localhost:9200/_cluster/health || exit 1"
)
, ulimits = Some
( toMap
{ nofile =
Compose.Ulimits.Object { hard = 65535, soft = 65535 }
}
)
, volumes = Some [ "./data:/usr/share/elasticsearch/data:Z" ]
, environment = Some
( Compose.ListOrDict.Dict
[ { mapKey = "ES_JAVA_OPTS"
, mapValue = "-Xms\${ES_XMS:-512m} -Xmx\${ES_XMX:-512m}"
}
, { mapKey = "discovery.type", mapValue = "single-node" }
]
)
}
in if dev
then Compose.Service::( service
// { ports = Some
[ mkPort "ELASTIC" 9200 9200 ]
}
)
else Compose.Service::( service
// { restart = Some "unless-stopped"
, expose = Some
[ Compose.StringOrNumber.Number 9200
]
}
)
let apiBuildContext =
Compose.Build.Object
{ context = "."
, dockerfile = "Dockerfile-api"
, args =
Compose.ListOrDict.Dict
[ { mapKey = "MONOCLE_COMMIT"
, mapValue = mkEnvDefault "MONOCLE_COMMIT" "HEAD"
}
]
}
let createApiService =
\(dev : Bool) ->
let service =
{ healthcheck = Some
( mkHealthCheck
"curl --silent --fail localhost:\$MONOCLE_API_PORT/health || exit 1"
)
, depends_on = Some [ "elastic" ]
, command = Some (Compose.StringOrList.String "monocle api")
, volumes = Some [ "./etc:/etc/monocle:z" ]
, env_file = envFile
, environment = Some
( Compose.ListOrDict.Dict
[ { mapKey = "CONFIG"
, mapValue = "/etc/monocle/config.yaml"
}
, { mapKey = "ELASTIC_CONN", mapValue = "elastic:9200" }
]
)
}
in if dev
then Compose.Service::( service
// { build = Some apiBuildContext
, ports = Some
[ mkPort "API" 9898 9898 ]
}
)
else Compose.Service::( service
// { image = Some (monocleImage "api")
, expose = Some
[ Compose.StringOrNumber.Number 9898
]
, restart = Some "unless-stopped"
}
)
let createCrawlerService =
\(dev : Bool) ->
let service =
{ depends_on = Some [ "api" ]
, command = Some (Compose.StringOrList.String "monocle crawler")
, healthcheck = Some
( mkHealthCheck
"curl --silent --fail localhost:9001/health || exit 1"
)
, volumes = Some [ "./etc:/etc/monocle:z" ]
, env_file = envFile
, environment = Some
( Compose.ListOrDict.Dict
[ { mapKey = "CONFIG"
, mapValue = "/etc/monocle/config.yaml"
}
]
)
}
in if dev
then Compose.Service::(service // { build = Some apiBuildContext })
else Compose.Service::( service
// { image = Some (monocleImage "api")
, restart = Some "unless-stopped"
}
)
let createCrawlerLegacyService =
\(dev : Bool) ->
let service =
{ depends_on = Some [ "elastic" ]
, command = Some
( Compose.StringOrList.String
"monocle --elastic-conn elastic:9200 crawler --config /etc/monocle/config.yaml"
)
, env_file = envFile
, volumes = Some
[ "./etc:/etc/monocle:z", "./dump:/var/lib/crawler:Z" ]
}
in if dev
then Compose.Service::( service
// { build = Some
(Compose.Build.String ".")
}
)
else Compose.Service::( service
// { image = Some (monocleImage "backend")
, restart = Some "unless-stopped"
}
)
let createWebService =
\(dev : Bool) ->
let service =
{ depends_on = Some [ "api" ]
, ports = Some [ mkPort "WEB" 8080 8080 ]
, volumes = Some [ "./web/conf:/etc/nginx/conf.d:z" ]
, environment = Some
( Compose.ListOrDict.Dict
[ { mapKey = "REACT_APP_API_URL"
, mapValue =
"\${MONOCLE_PUBLIC_URL:-http://localhost:8080}"
}
, { mapKey = "REACT_APP_TITLE"
, mapValue = "\${MONOCLE_TITLE}"
}
]
)
}
let -- podman v3.1.0 doesn't seem to work with build directory
-- adding a build context and a dockerfile next to the compose file is a working combo
build =
buildContext "web" // { context = "web" }
in if dev
then Compose.Service::( service
// { build = Some
(Compose.Build.Object build)
}
)
else Compose.Service::( service
// { image = Some (monocleImage "web")
, restart = Some "unless-stopped"
}
)
let createServices =
\(dev : Bool) ->
toMap
{ api = createApiService dev
, web = createWebService dev
, crawler-legacy = createCrawlerLegacyService dev
, crawler = createCrawlerService dev
, elastic = createElasticService dev
}
in { img = Compose.Config::{ services = Some (createServices False) }
, dev = Compose.Config::{ services = Some (createServices True) }
}