Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed Sep 2, 2024
1 parent 3a191fb commit 34080ed
Show file tree
Hide file tree
Showing 12 changed files with 467 additions and 48 deletions.
13 changes: 13 additions & 0 deletions jobs/backupbot.nomad
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
variable "test" {
type = bool
description = "Uses jobs for the test server. Without CSI"
default = false
}

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

Expand Down Expand Up @@ -25,6 +31,13 @@ job "backupbot" {
memory = 100
}
}

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

reschedule {
Expand Down
43 changes: 36 additions & 7 deletions jobs/development/fastcgi.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ job "fastcgi" {
]

cpu_hard_limit = true

network_mode = "host"
}

resources {
Expand All @@ -85,15 +83,46 @@ job "fastcgi" {
}

env {
NOMAD_UPSTREAM_ADDR_http = "127.0.0.1:8080"
NOMAD_UPSTREAM_ADDR_mysql = "127.0.0.1:3306"
NOMAD_UPSTREAM_ADDR_memcached = "127.0.0.1:11211"
MEDIAWIKI_DEBUG_MODE = "1"
MEDIAWIKI_SERVER = "http://localhost:8080"
MEDIAWIKI_DEBUG_MODE = "1"
MEDIAWIKI_SERVER = "http://localhost:8080"
# MEDIAWIKI_SKIP_INSTALL = "1"
# MEDIAWIKI_SKIP_IMPORT_SITES = "1"
# MEDIAWIKI_SKIP_UPDATE = "1"
}
}

network {
mode = "bridge"
}

service {
name = "fastcgi"
port = "9000"

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

upstreams {
destination_name = "memcached"
local_bind_port = 11211
}
}
}

sidecar_task {
config {
memory_hard_limit = 300
}
resources {
memory = 32
}
}
}
}
}
}
43 changes: 39 additions & 4 deletions jobs/development/http.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ variable "caddyfile_for_dev" {
auto_https off
order mwcache before rewrite
}
http://127.0.0.1:8080 http://localhost:8080
http://127.0.0.1:{$NOMAD_HOST_PORT_http} http://localhost:{$NOMAD_HOST_PORT_http}
root * /srv/femiwiki.com
php_fastcgi 127.0.0.1:9000
php_fastcgi {$NOMAD_UPSTREAM_ADDR_fastcgi}
file_server
encode gzip
mwcache {
Expand Down Expand Up @@ -58,8 +58,6 @@ job "http" {
command = "caddy"
args = ["run"]

network_mode = "host"

volumes = [
# Overwrite production Caddyfile
"local/Caddyfile:/srv/femiwiki.com/Caddyfile"
Expand Down Expand Up @@ -94,5 +92,42 @@ job "http" {
memory_max = 400
}
}

network {
mode = "bridge"

port "http" {
static = 80
}

port "https" {
static = 443
}
}

service {
name = "http"
port = "80"

connect {
sidecar_service {
proxy {
upstreams {
destination_name = "fastcgi"
local_bind_port = 9000
}
}
}

sidecar_task {
config {
memory_hard_limit = 500
}
resources {
memory = 300
}
}
}
}
}
}
18 changes: 16 additions & 2 deletions jobs/development/memcached.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@ job "memcached" {

network {
mode = "bridge"
}

service {
name = "memcached"
port = "11211"

connect {
sidecar_service {}

port "memcached" {
static = 11211
sidecar_task {
config {
memory_hard_limit = 300
}
resources {
memory = 30
}
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions jobs/development/mysql.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,23 @@ EOF
static = 3306
}
}

service {
name = "mysql"
port = "3306"

connect {
sidecar_service {}

sidecar_task {
config {
memory_hard_limit = 300
}
resources {
memory = 30
}
}
}
}
}
}
115 changes: 100 additions & 15 deletions jobs/fastcgi.nomad
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
variable "test" {
type = bool
description = "Uses jobs for the test server. Without CSI"
default = false
}

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

group "fastcgi" {
# Init Task Lifecycle
# Reference: https://www.nomadproject.io/docs/job-specification/lifecycle#init-task-pattern
task "wait-for-backend" {
task "wait-for-mysql" {
lifecycle {
hook = "prestart"
sidecar = false
}

driver = "exec"
config {
command = "sh"
args = [
"-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"
),
]
}
}

task "wait-for-memcached" {
lifecycle {
hook = "prestart"
sidecar = false
Expand All @@ -15,10 +41,10 @@ job "fastcgi" {
command = "sh"
args = [
"-c",
join(";", [
"while ! ncat --send-only 127.0.0.1 3306 < /dev/null; do sleep 1; done",
"while ! ncat --send-only 127.0.0.1 11211 < /dev/null; do sleep 1; done"
])
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"
),
]
}
}
Expand Down Expand Up @@ -118,8 +144,7 @@ job "fastcgi" {
]

cpu_hard_limit = true

network_mode = "host"
network_mode = var.test ? "bridge" : "host"
}

resources {
Expand All @@ -128,12 +153,70 @@ job "fastcgi" {
memory_max = 800
}

env {
NOMAD_UPSTREAM_ADDR_http = "127.0.0.1:80"
NOMAD_UPSTREAM_ADDR_memcached = "127.0.0.1:11211"
MEDIAWIKI_SKIP_INSTALL = "1"
MEDIAWIKI_SKIP_IMPORT_SITES = "1"
MEDIAWIKI_SKIP_UPDATE = "1"
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 ? [] : [{}]
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_IMPORT_SITES = "1"
MEDIAWIKI_SKIP_UPDATE = var.test ? "0" : "1"
}
}
}

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

dynamic "service" {
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
}
}
}

sidecar_task {
config {
memory_hard_limit = 300
}
resources {
memory = 20
}
}
}
}
}
}
}
Expand All @@ -146,7 +229,10 @@ job "fastcgi" {
}

update {
auto_revert = true
auto_revert = true
auto_promote = var.test ? true : false
# canary count equal to the desired count allows a Nomad job to model blue/green deployments
canary = var.test ? 1 : 0
}
}

Expand Down Expand Up @@ -194,4 +280,3 @@ set -euo pipefail; IFS=$'\n\t'
EOF
}

Loading

0 comments on commit 34080ed

Please sign in to comment.