generated from serokell/metatemplates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.nix
102 lines (91 loc) · 2.32 KB
/
docker.nix
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
# SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
{ dockerTools
, backend
, frontend
, locale
, linkFarm
, runCommand
, writeTextDir }:
let
inherit (dockerTools) buildLayeredImage buildImage pullImage;
in
{
backend-image = let
# linkFarm seems to put a dangling symlink in the image when used here, so
# we use runCommand and copy the file instead.
init-sql = runCommand "edna-init-sql" {} ''
mkdir -p $out
cp ${./backend/sql/init.sql} $out/init.sql
'';
in buildLayeredImage {
name = "ghcr.io/serokell/edna-backend";
tag = "latest";
contents = [
backend
init-sql
# Unicode support
locale
];
config = {
Entrypoint = "/bin/edna-server";
Env = [
"LANG=C.UTF-8"
"LC_ALL=C.UTF-8"
"LOCALE_ARCHIVE=/lib/locale/locale-archive"
];
};
};
frontend-image = let
nginx = pullImage {
imageName = "nginx";
imageDigest = "sha256:e20c21e530f914fb6a95a755924b1cbf71f039372e94ac5ddcf8c3b386a44615";
sha256 = "1xfl1yx5mklxzcbywmfr8y48kkkp7if364r24ghjz33jkb3wm8vy";
finalImageName = "nginx";
finalImageTag = "alpine";
};
html = linkFarm "edna-frontend-bundle" [{
name = "usr/share/nginx/html";
path = "${frontend}";
}];
nginx-conf-template = writeTextDir "etc/nginx/templates/default.conf.template" ''
server {
listen 80 default_server;
root /usr/share/nginx/html;
location / {
add_header Cache-Control 'no-store';
try_files $uri /index.html =404;
}
location ''${API_PATH} {
proxy_pass http://''${API_HOST}:''${API_PORT}/;
}
location /health/ {
return 204;
}
}
'';
in buildImage {
name = "ghcr.io/serokell/edna-frontend";
tag = "latest";
fromImage = nginx;
contents = [
html
nginx-conf-template
];
config = {
# Somehow, all this gets lost when inheriting from the parent image.
Entrypoint = [ "/docker-entrypoint.sh" ];
Cmd = [ "nginx" "-g" "daemon off;" ];
ExposedPorts = {
"80/tcp" = {};
};
# Used in the conf template above
Env = [
"API_PATH=/api/"
"API_HOST=backend"
"API_PORT=9000"
];
};
};
}