Skip to content

Commit

Permalink
Use local.main instead of !var.test
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed Oct 1, 2024
1 parent 4154d18 commit 5180552
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 60 deletions.
92 changes: 46 additions & 46 deletions jobs/fastcgi.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ variable "mysql_password_mediawiki" {
default = ""
}

locals {
main = !var.test
}

job "fastcgi" {
datacenters = ["dc1"]

Expand All @@ -33,8 +37,8 @@ job "fastcgi" {
"-c",
format(
"while ! ncat --send-only %s %s < /dev/null; do sleep 1; done",
var.test ? NOMAD_UPSTREAM_IP_mysql : "127.0.0.1",
var.test ? NOMAD_UPSTREAM_PORT_mysql : "3306"
local.main ? "127.0.0.1" : NOMAD_UPSTREAM_IP_mysql,
local.main ? "3306" : NOMAD_UPSTREAM_PORT_mysql,
),
]
}
Expand All @@ -52,8 +56,8 @@ job "fastcgi" {
args = [
"-c",
format("while ! ncat --send-only %s %s < /dev/null; do sleep 1; done",
var.test ? NOMAD_UPSTREAM_IP_memcached : "127.0.0.1",
var.test ? NOMAD_UPSTREAM_PORT_memcached : "11211"
local.main ? "127.0.0.1" : NOMAD_UPSTREAM_IP_memcached,
local.main ? "11211 : NOMAD_UPSTREAM_PORT_memcached"
),
]
}
Expand Down Expand Up @@ -105,7 +109,7 @@ job "fastcgi" {
}

template {
data = var.test ? var.hotfix_test : var.hotfix
data = local.main ? var.hotfix : var.hotfix_test
destination = "local/Hotfix.php"
change_mode = "noop"
}
Expand Down Expand Up @@ -154,7 +158,7 @@ job "fastcgi" {
]

cpu_hard_limit = true
network_mode = var.test ? "bridge" : "host"
network_mode = local.main ? "host" : "bridge"
}

resources {
Expand All @@ -164,71 +168,67 @@ job "fastcgi" {
}

dynamic "env" {
for_each = !var.test ? [] : [{}]
content {
MEDIAWIKI_SKIP_INSTALL = var.test ? "0" : "1"
MEDIAWIKI_SKIP_IMPORT_SITES = "1"
MEDIAWIKI_SKIP_UPDATE = var.test ? "0" : "1"
}
}

dynamic "env" {
for_each = var.test ? [] : [{}]
for_each = local.main ? [{}] : []
content {
NOMAD_UPSTREAM_ADDR_http = "127.0.0.1:80"
NOMAD_UPSTREAM_ADDR_mysql = "127.0.0.1:3306"
NOMAD_UPSTREAM_ADDR_memcached = "127.0.0.1:11211"
MEDIAWIKI_SKIP_INSTALL = var.test ? "0" : "1"
MEDIAWIKI_SKIP_INSTALL = local.main ? "1" : "0"
MEDIAWIKI_SKIP_IMPORT_SITES = "1"
MEDIAWIKI_SKIP_UPDATE = var.test ? "0" : "1"
MEDIAWIKI_SKIP_UPDATE = local.main ? "1" : "0"
}
}
}

dynamic "network" {
for_each = var.test ? [{}] : []
content {
mode = "bridge"
dynamic "env" {
for_each = var.test ? [{}] : []
content {
MEDIAWIKI_SKIP_INSTALL = local.main ? "1" : "0"
MEDIAWIKI_SKIP_IMPORT_SITES = "1"
MEDIAWIKI_SKIP_UPDATE = local.main ? "1" : "0"
}
}
}

dynamic "service" {
for_each = !var.test ? [] : [{}]
for_each = var.test ? [{}] : []

content {
name = "fastcgi"
port = "9000"

dynamic "connect" {
for_each = !var.test ? [] : [{}]

content {
sidecar_service {
proxy {
upstreams {
destination_name = "mysql"
local_bind_port = 3306
}

upstreams {
destination_name = "memcached"
local_bind_port = 11211
}
connect {
sidecar_service {
proxy {
upstreams {
destination_name = "mysql"
local_bind_port = 3306
}
}

sidecar_task {
config {
memory_hard_limit = 300
}
resources {
memory = 20
upstreams {
destination_name = "memcached"
local_bind_port = 11211
}
}
}

sidecar_task {
config {
memory_hard_limit = 300
}
resources {
memory = 20
}
}
}
}
}

dynamic "network" {
for_each = var.test ? [{}] : []
content {
mode = "bridge"
}
}
}

reschedule {
Expand Down
23 changes: 13 additions & 10 deletions jobs/http.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ variable "test" {
default = false
}

locals {
main = !var.test
}

job "http" {
datacenters = ["dc1"]

Expand All @@ -24,17 +28,8 @@ job "http" {
destination = "/etc/caddycerts"
read_only = false
}

dynamic "template" {
for_each = !var.test ? [] : [{}]

content {
data = var.caddyfile_for_test
destination = "local.Caddyfile"
}
}
dynamic "artifact" {
for_each = var.test ? [] : [{}]
for_each = local.main ? [{}] : []

content {
source = "https://github.com/femiwiki/nomad/raw/main/caddy/Caddyfile"
Expand All @@ -44,6 +39,14 @@ job "http" {
options { checksum = "md5:ee0300e384afa6aca74f09a44323ee6e" }
}
}
dynamic "template" {
for_each = var.test ? [{}] : []

content {
data = var.caddyfile_for_test
destination = "local.Caddyfile"
}
}

artifact {
source = "https://github.com/femiwiki/nomad/raw/main/res/robots.txt"
Expand Down
6 changes: 5 additions & 1 deletion jobs/memcached.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ variable "test" {
default = false
}

locals {
main = !var.test
}

job "memcached" {
datacenters = ["dc1"]

Expand Down Expand Up @@ -33,7 +37,7 @@ job "memcached" {
}

dynamic "service" {
for_each = var.test ? [] : [{}]
for_each = local.main ? [{}] : []
content {
provider = "nomad"
name = "memcached"
Expand Down
10 changes: 7 additions & 3 deletions jobs/mysql.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ variable "test" {
default = false
}

locals {
main = !var.test
}

job "mysql" {
datacenters = ["dc1"]

group "mysql" {
dynamic "volume" {
for_each = var.test ? [] : [{}]
for_each = local.main ? [{}] : []
labels = ["mysql"]

content {
Expand All @@ -25,7 +29,7 @@ job "mysql" {
driver = "docker"

dynamic "volume_mount" {
for_each = var.test ? [] : [{}]
for_each = local.main ? [{}] : []

content {
volume = "mysql"
Expand Down Expand Up @@ -60,7 +64,7 @@ job "mysql" {
network {
mode = "bridge"
dynamic "port" {
for_each = var.test ? [] : [{}]
for_each = local.main ? [{}] : []
labels = ["network"]

content {
Expand Down

0 comments on commit 5180552

Please sign in to comment.