-
Notifications
You must be signed in to change notification settings - Fork 10
/
f1bot.nomad.hcl
137 lines (111 loc) · 3.83 KB
/
f1bot.nomad.hcl
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
variable "image_id" {
type = string
description = "ghcr.io/<owner>/<repo> URL"
}
variable "image_version" {
type = string
}
variable "ghcr_password" {
type = string
description = "Github Container Registry password (personal access token with scope read:packages)"
}
variable "environment" {
type = string
description = "Environment name (e.g. dev, staging, prod)"
}
locals {
config_scope = "apps/f1bot_${var.environment}"
prod_hostname = "${var.environment == "master" ? "racing.recursiveprojects.cloud" : null}"
dev_hostname = "${var.environment == "develop" ? "racing-dev.recursiveprojects.cloud" : null}"
hostname = "${coalesce(local.dev_hostname, local.prod_hostname, "")}"
prod_data_root = "${var.environment == "master" ? "/srv/f1bot/prod" : null}"
dev_data_root = "${var.environment == "develop" ? "/srv/f1bot/dev" : null}"
data_root = "${coalesce(local.dev_data_root, local.prod_data_root, "/srv/f1bot/unknown")}"
}
job "f1bot-____INSERT_ENV_HERE____" {
datacenters = ["dc1"]
type = "service"
group "f1bot" {
count = 1
network {
port "http" {
}
}
service {
name = "f1bot-${var.environment}"
port = "http"
tags = [
"traefik.enable=true",
"traefik.http.routers.f1bot-${var.environment}.rule=Host(`${local.hostname}`)",
]
check {
type = "http"
path = "/health-check"
interval = "2s"
timeout = "2s"
}
}
task "f1bot-elixir" {
driver = "docker"
template {
data = <<EOH
DISCORD_TOKEN="{{key "${local.config_scope}/DISCORD_TOKEN"}}"
DISCORD_CHANNEL_IDS_MESSAGES="{{key "${local.config_scope}/DISCORD_CHANNEL_IDS_MESSAGES" | regexReplaceAll "#.*" "" | replaceAll "\n" "," }}"
DISCORD_CHANNEL_IDS_RADIOS="{{key "${local.config_scope}/DISCORD_CHANNEL_IDS_RADIOS" | regexReplaceAll "#.*" "" | replaceAll "\n" "," }}"
DISCORD_SERVER_IDS_COMMANDS="{{key "${local.config_scope}/DISCORD_SERVER_IDS_COMMANDS" | regexReplaceAll "#.*" "" | replaceAll "\n" "," }}"
SECRET_KEY_BASE="{{key "${local.config_scope}/SECRET_KEY_BASE"}}"
PHX_HOST="{{key "${local.config_scope}/PHX_HOST"}}"
DEMO_MODE_URL="{{key "${local.config_scope}/DEMO_MODE_URL"}}"
EOH
destination = ".env"
change_mode = "noop"
env = true
}
env {
PORT = "${NOMAD_PORT_http}"
PHX_SERVER = "true"
DATABASE_PATH = "/data/f1bot.db"
}
config {
image = "${var.image_id}:${var.image_version}"
auth {
server_address = split("/", var.image_id)[0]
username = split("/", var.image_id)[1]
password = var.ghcr_password
}
ports = ["http"]
volumes = [
"${local.data_root}:/data",
]
}
resources {
cpu = 4000 # Mhz
memory = 4096 # MB
}
kill_timeout = "20s"
}
restart {
# The number of attempts to run the job within the specified interval.
attempts = 10
interval = "2m"
# The "delay" parameter specifies the duration to wait before restarting
# a task after it has failed.
delay = "3s"
# The "mode" parameter controls what happens when a task has restarted
# "attempts" times within the interval. "delay" mode delays the next
# restart until the next interval. "fail" mode does not restart the task
# if "attempts" has been hit within the interval.
mode = "delay"
}
}
update {
# The "max_parallel" parameter specifies the maximum number of updates to
# perform in parallel. In this case, this specifies to update a single task
# at a time.
max_parallel = 1
min_healthy_time = "10s"
healthy_deadline = "90s"
progress_deadline = "0"
auto_revert = true
}
}