Skip to content

Commit

Permalink
Revert "Get rid of Consul and Nomad Connect"
Browse files Browse the repository at this point in the history
This reverts commit 1e79b45.
  • Loading branch information
lens0021 committed Aug 3, 2024
1 parent 449ed13 commit 115c739
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 27 deletions.
19 changes: 19 additions & 0 deletions consul/consul.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
datacenter = "dc1"
data_dir = "/opt/consul"

server = true
node_name = "femiwiki"
bind_addr = "{{GetInterfaceIP \"eth0\"}}"
bootstrap = true
bootstrap_expect = 1
# Cloud Auto-join, but disabled because we have only one node now.
# https://www.consul.io/docs/install/cloud-auto-join#amazon-ec2
# retry_join = ["provider=aws tag_key=Name tag_value=femiwiki"]

ports {
grpc = 8502
}

connect {
enabled = true
}
5 changes: 5 additions & 0 deletions jobs/backupbot.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ job "backupbot" {
}
}

network {
# todo change to host or add an upstream to connect to database
mode = "bridge"
}

reschedule {
attempts = 1
interval = "24h"
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
}
}
}
}
}
}
60 changes: 51 additions & 9 deletions jobs/fastcgi.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ job "fastcgi" {
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"
"while ! ncat --send-only ${NOMAD_UPSTREAM_IP_mysql} ${NOMAD_UPSTREAM_PORT_mysql} < /dev/null; do sleep 1; done",
"while ! ncat --send-only ${NOMAD_UPSTREAM_IP_memcached} ${NOMAD_UPSTREAM_PORT_memcached} < /dev/null; do sleep 1; done"
])
]
}
Expand Down Expand Up @@ -116,10 +116,16 @@ job "fastcgi" {
readonly = false
},
]
<<<<<<< HEAD
cpu_hard_limit = true
network_mode = "host"
||||||| parent of 381fc14 (Revert "Get rid of Consul and Nomad Connect")
network_mode = "host"
=======
>>>>>>> 381fc14 (Revert "Get rid of Consul and Nomad Connect")
}
resources {
Expand All @@ -129,11 +135,43 @@ job "fastcgi" {
}
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"
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 = 20
}
}
}
}
}
Expand All @@ -146,7 +184,12 @@ job "fastcgi" {
}
update {
auto_revert = true
max_parallel = 1
health_check = "checks"
auto_revert = true
auto_promote = true
# canary count equal to the desired count allows a Nomad job to model blue/green deployments
canary = 1
}
}
Expand Down Expand Up @@ -194,4 +237,3 @@ set -euo pipefail; IFS=$'\n\t'
EOF
}

39 changes: 38 additions & 1 deletion jobs/http.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,44 @@ job "http" {

env {
CADDYPATH = "/etc/caddycerts"
FASTCGI_ADDR = "127.0.0.1:9000"
FASTCGI_ADDR = NOMAD_UPSTREAM_ADDR_fastcgi
}
}

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 = 20
}
}
}
}

Expand Down
25 changes: 22 additions & 3 deletions jobs/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 = 20
}
}
}
}
}
Expand All @@ -31,6 +45,11 @@ job "memcached" {
}

update {
auto_revert = true
max_parallel = 1
health_check = "checks"
auto_revert = true
auto_promote = true
# canary count equal to the desired count allows a Nomad job to model blue/green deployments
canary = 1
}
}
Loading

0 comments on commit 115c739

Please sign in to comment.