Skip to content

Commit

Permalink
Add test cluster
Browse files Browse the repository at this point in the history
- Connect test server to the db of main
  • Loading branch information
lens0021 committed Sep 29, 2024
1 parent c25c86c commit 5160cc0
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 26 deletions.
22 changes: 21 additions & 1 deletion jobs/fastcgi.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ variable "test" {
default = false
}

variable "main_nomad_addr" {
type = string
default = ""
}

variable "mysql_password_mediawiki" {
type = string
default = ""
}

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

Expand Down Expand Up @@ -95,7 +105,7 @@ job "fastcgi" {
}

template {
data = var.hotfix
data = var.test ? var.hotfix_test : var.hotfix
destination = "local/Hotfix.php"
change_mode = "noop"
}
Expand Down Expand Up @@ -286,6 +296,16 @@ $wgBlacklistSettings = [
EOF
}

variable "hotfix_test" {
type = string
default = <<EOF
<?php
$wgDBserver = '$${var.main_nomad_addr}';
$wgDBuser = 'mediawiki';
$wgDBpassword = '$${var.mysql_password_mediawiki}';
EOF
}

variable "postrun" {
type = string
default = <<EOF
Expand Down
2 changes: 0 additions & 2 deletions terraform/backupbot.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
resource "nomad_job" "backupbot" {
count = !var.test ? 1 : 0

depends_on = [nomad_job.mysql]

detach = false
Expand Down
13 changes: 13 additions & 0 deletions terraform/base.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ variable "nomad_token" {
sensitive = true
}

variable "test_nomad_token" {
type = string
sensitive = true
}

terraform {
required_version = "~> 1.0"

Expand Down Expand Up @@ -38,3 +43,11 @@ provider "nomad" {
# Should be specified explicitly because of the bug https://github.com/femiwiki/nomad/issues/99
region = "global"
}

provider "nomad" {
alias = "test"
address = data.terraform_remote_state.aws.outputs.test_nomad_addr
secret_id = var.test_nomad_token
# Should be specified explicitly because of the bug https://github.com/femiwiki/nomad/issues/99
region = "global"
}
76 changes: 57 additions & 19 deletions terraform/mediawiki.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
locals {
hcl_vals = {
test = var.test
}
}

resource "nomad_job" "mysql_without_ebs" {
count = var.test ? 1 : 0

jobspec = file("../jobs/mysql.nomad")
detach = false

hcl2 {
allow_fs = true
vars = local.hcl_vals
main_hcl_vals = {
test = false
}
}

resource "nomad_job" "mysql" {
count = !var.test ? 1 : 0

depends_on = [
data.nomad_plugin.ebs,
nomad_csi_volume_registration.mysql,
Expand All @@ -29,7 +15,7 @@ resource "nomad_job" "mysql" {

hcl2 {
allow_fs = true
vars = local.hcl_vals
vars = local.main_hcl_vals
}
}

Expand All @@ -39,6 +25,20 @@ resource "nomad_job" "memcached" {

hcl2 {
allow_fs = true
vars = local.main_hcl_vals
}
}

resource "nomad_job" "test_memcached" {
provider = nomad.test
jobspec = file("../jobs/memcached.nomad")
detach = false

hcl2 {
allow_fs = true
vars = {
test = true
}
}
}

Expand All @@ -53,7 +53,26 @@ resource "nomad_job" "fastcgi" {

hcl2 {
allow_fs = true
vars = local.hcl_vals
vars = local.main_hcl_vals
}
}

resource "nomad_job" "test_fastcgi" {
provider = nomad.test
depends_on = [
nomad_job.memcached,
]

jobspec = file("../jobs/fastcgi.nomad")
detach = false

hcl2 {
allow_fs = true
vars = {
test = true
main_nomad_addr = data.terraform_remote_state.aws.outputs.nomad_addr
mysql_password_mediawiki = var.mysql_password_mediawiki
}
}
}

Expand All @@ -68,6 +87,25 @@ resource "nomad_job" "http" {

hcl2 {
allow_fs = true
vars = local.hcl_vals
vars = local.main_hcl_vals
}
}

resource "nomad_job" "test_http" {
provider = nomad.test
depends_on = [
# TODO Replace with S3 CSI or something
# data.nomad_plugin.ebs,
# nomad_csi_volume_registration.caddycerts,
]

jobspec = file("../jobs/http.nomad")
detach = false

hcl2 {
allow_fs = true
vars = {
test = true
}
}
}
7 changes: 3 additions & 4 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
variable "test" {
type = bool
description = "Uses jobs for the test server. Without CSI, backup, certificates etc"
default = false
variable "mysql_password_mediawiki" {
type = string
sensitive = true
}

0 comments on commit 5160cc0

Please sign in to comment.