-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodimd.tf
115 lines (106 loc) · 2.45 KB
/
codimd.tf
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
resource "kubernetes_service" "codimd_service" {
metadata {
name = "codimd-svc"
namespace = "productivity-stack-srikanth-iyengar"
}
spec {
type = "ClusterIP"
publish_not_ready_addresses = true
port {
name = "codimd-port"
port = "3000"
target_port = "3000"
}
selector = {
App = "codimd-sts"
}
}
}
resource "kubernetes_config_map" "codimd_entrypoint" {
metadata {
name = "codimd-startscript"
namespace = "productivity-stack-srikanth-iyengar"
labels = {
conf = "codimd"
}
}
data = {
"start.sh" = <<EOF
#!/usr/bin/env bash
set -euo pipefail
npm install pg --save
if [[ "$#" -gt 0 ]]; then
exec "$@"
exit $?
fi
# check database and redis is ready
pcheck -env CMD_DB_URL
# run DB migrate
NEED_MIGRATE=`CMD_AUTO_MIGRATE:=true`
if [[ "$NEED_MIGRATE" = "true" ]] && [[ -f .sequelizerc ]] ; then
npx sequelize db:migrate
fi
# start application
node app.js
EOF
}
}
resource "kubernetes_stateful_set" "codimd_sts" {
metadata {
name = "codimd-sts"
namespace = "productivity-stack-srikanth-iyengar"
}
spec {
service_name = "codimd-svc"
pod_management_policy = "OrderedReady"
replicas = 1
selector {
match_labels = {
App = "codimd-sts"
}
}
template {
metadata {
labels = {
App = "codimd-sts"
}
}
spec {
security_context {
fs_group = 1001
}
container {
name = "codimd-container"
image = "hackmdio/hackmd"
security_context {
run_as_non_root = true
run_as_user = 1001
allow_privilege_escalation = false
}
volume_mount {
name = "datadir"
mount_path = "/home/hackmd/app/public/uploads"
}
env {
name = "CMD_DB_URL"
value = "mysql://root:${random_string.mysql_password.result}@mysql-service.productivity-stack-srikanth-iyengar.svc.cluster.local:3306/codimd"
}
}
}
}
volume_claim_template {
metadata {
name = "datadir"
namespace = "productivity-stack-srikanth-iyengar"
}
spec {
access_modes = ["ReadWriteOnce"]
resources {
requests = {
storage = "1024Mi"
}
}
}
}
}
}