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 8761d8f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 24 deletions.
12 changes: 11 additions & 1 deletion jobs/fastcgi.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ job "fastcgi" {
}

template {
data = var.hotfix
data = var.test ? var.hotfixe_test : var.hotfix
destination = "local/Hotfix.php"
change_mode = "noop"
}
Expand Down Expand Up @@ -286,6 +286,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"
}
70 changes: 53 additions & 17 deletions terraform/mediawiki.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
locals {
hcl_vals = {
test = var.test
main_hcl_vals = {
test = false
}
}

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
test_hcl_vals = {
test = true
main_nomad_addr = data.terraform_remote_state.aws.outputs.nomad_addr
mysql_password_mediawiki = var.mysql_password_mediawiki
}
}

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

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

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

Expand All @@ -39,6 +31,18 @@ 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 = local.test_hcl_vals
}
}

Expand All @@ -53,7 +57,22 @@ 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 = local.test_hcl_vals
}
}

Expand All @@ -68,6 +87,23 @@ 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 = local.test_hcl_vals
}
}
12 changes: 8 additions & 4 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
variable "test" {
type = bool
description = "Uses jobs for the test server. Without CSI, backup, certificates etc"
default = false
variable "main_nomad_addr" {
type = string
default = ""
}

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

0 comments on commit 8761d8f

Please sign in to comment.