WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit b53419b

Browse files
committed
feat: azure changed to mariadb
1 parent 1dc6e5b commit b53419b

File tree

3 files changed

+62
-60
lines changed

3 files changed

+62
-60
lines changed

Caddyfile.azure

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Handle WebSocket paths without WAF
1313
handle /ws/* {
14-
reverse_proxy minio:9001 {
14+
reverse_proxy localhost:9001 {
1515
header_up Host {http.request.host}
1616
header_up X-Real-IP {remote}
1717
header_up X-Forwarded-For {remote}
@@ -38,7 +38,7 @@
3838
`
3939
}
4040

41-
reverse_proxy minio:9001 {
41+
reverse_proxy localhost:9001 {
4242
header_up Host {http.request.host}
4343
header_up X-Real-IP {remote}
4444
header_up X-Forwarded-For {remote}
@@ -62,14 +62,10 @@
6262
}
6363

6464
# --- Keycloak Proxy HTTP (port 8082) ---
65-
# Azure App Gateway handles TLS termination, so internal traffic uses HTTP
6665
:8082 {
67-
reverse_proxy localhost:8080 {
66+
reverse_proxy localhost:8083 {
6867
header_up Host {http.request.header.X-Forwarded-Host}
6968
header_up X-Real-IP {http.request.header.X-Forwarded-For}
70-
header_up X-Forwarded-Proto https
71-
header_up X-Forwarded-Host {http.request.header.X-Forwarded-Host}
72-
header_up X-Forwarded-Port 8444
7369
}
7470

7571
log {
@@ -97,7 +93,7 @@
9793
`
9894
}
9995

100-
reverse_proxy minio:9000 {
96+
reverse_proxy localhost:9000 {
10197
header_up Connection {http.request.header.connection}
10298
header_up Upgrade {http.request.header.upgrade}
10399
}

main.tf

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ resource "random_string" "storage_suffix" {
44
upper = false
55
}
66

7+
resource "random_password" "mariadb_password" {
8+
length = 16
9+
special = true
10+
override_special = "!#$%&*()-_=+[]{}<>:?"
11+
}
12+
713
resource "azurerm_virtual_network" "minio_vnet" {
814
name = "minio-vnet"
915
address_space = ["10.10.0.0/16"]
@@ -71,8 +77,8 @@ resource "azurerm_storage_share" "minio_share" {
7177
quota = var.storage_share_size
7278
}
7379

74-
resource "azurerm_storage_share" "postgres_share" {
75-
name = "postgresstorageshare"
80+
resource "azurerm_storage_share" "mariadb_share" {
81+
name = "mariadbstorageshare"
7682
storage_account_id = azurerm_storage_account.minio_storage_account.id
7783
quota = 10
7884
}
@@ -465,35 +471,40 @@ resource "azurerm_container_group" "minio_aci_container_group" {
465471
}
466472

467473
container {
468-
name = "postgres"
469-
image = "postgres:16-alpine"
474+
name = "mariadb"
475+
image = "mariadb:11"
470476
cpu = "0.5"
471477
memory = "1.0"
472478
cpu_limit = 1.0
473479
memory_limit = 1.5
474480

475481
environment_variables = {
476-
POSTGRES_DB = var.postgres_db
477-
POSTGRES_USER = var.postgres_user
478-
POSTGRES_PASSWORD = var.postgres_password
482+
MARIADB_USER = var.mariadb_user
483+
MARIADB_PASSWORD = random_password.mariadb_password.result
484+
MARIADB_DATABASE = var.mariadb_database
485+
MARIADB_ROOT_PASSWORD = random_password.mariadb_password.result
479486
}
480487

481488
ports {
482-
port = 5432
489+
port = 3306
483490
protocol = "TCP"
484491
}
485492

486493
volume {
487-
name = "postgres-data"
488-
mount_path = "/var/lib/postgresql/data"
494+
name = "mariadb-data"
495+
mount_path = "/var/lib/mysql"
489496
read_only = false
490497
storage_account_name = azurerm_storage_account.minio_storage_account.name
491498
storage_account_key = azurerm_storage_account.minio_storage_account.primary_access_key
492-
share_name = azurerm_storage_share.postgres_share.name
499+
share_name = azurerm_storage_share.mariadb_share.name
500+
}
501+
502+
security {
503+
privilege_enabled = true
493504
}
494505

495506
liveness_probe {
496-
exec = ["pg_isready", "-U", var.postgres_user, "-d", var.postgres_db]
507+
exec = ["/bin/sh", "-c", "mariadb -u root -p$MARIADB_ROOT_PASSWORD -e 'SELECT 1'"]
497508

498509
initial_delay_seconds = 30
499510
period_seconds = 10
@@ -517,14 +528,16 @@ resource "azurerm_container_group" "minio_aci_container_group" {
517528
KC_HOSTNAME_STRICT = "false"
518529
KC_PROXY_HEADERS = "xforwarded"
519530
KEYCLOAK_IMPORT = "/opt/keycloak/data/import/realm-config.json"
520-
KC_DB = "postgres"
521-
KC_DB_URL = "jdbc:postgresql://localhost/${var.postgres_db}"
522-
KC_DB_USERNAME = var.postgres_user
523-
KC_DB_PASSWORD = var.postgres_password
531+
KC_DB = "mariadb"
532+
KC_DB_URL = "jdbc:mariadb://localhost:3306/${var.mariadb_database}"
533+
KC_DB_USERNAME = var.mariadb_user
534+
KC_DB_PASSWORD = random_password.mariadb_password.result
535+
KC_HTTP_PORT = "8083"
536+
KC_HOSTNAME = "localhost"
524537
}
525538

526539
ports {
527-
port = 8080
540+
port = 8083
528541
protocol = "TCP"
529542
}
530543

@@ -540,22 +553,26 @@ resource "azurerm_container_group" "minio_aci_container_group" {
540553

541554
volume {
542555
name = "keycloak-data"
543-
mount_path = "/opt/keycloak/data/h2"
556+
mount_path = "/opt/keycloak/data"
544557
read_only = false
545558
storage_account_name = azurerm_storage_account.minio_storage_account.name
546559
storage_account_key = azurerm_storage_account.minio_storage_account.primary_access_key
547560
share_name = azurerm_storage_share.keycloak_share.name
548561
}
549562

550-
commands = ["start", "--import-realm"]
563+
commands = [
564+
"/bin/bash",
565+
"-c",
566+
"until timeout 1 bash -c 'cat < /dev/null > /dev/tcp/localhost/3306' 2>/dev/null; do echo 'Waiting for MariaDB...'; sleep 2; done && /opt/keycloak/bin/kc.sh start --import-realm"
567+
]
551568

552569
liveness_probe {
553570
http_get {
554571
path = "/health/live"
555-
port = 8080
572+
port = 8083
556573
scheme = "http"
557574
}
558-
initial_delay_seconds = 120
575+
initial_delay_seconds = 400
559576
period_seconds = 30
560577
timeout_seconds = 10
561578
failure_threshold = 3
@@ -564,10 +581,10 @@ resource "azurerm_container_group" "minio_aci_container_group" {
564581
readiness_probe {
565582
http_get {
566583
path = "/health/ready"
567-
port = 8080
584+
port = 8083
568585
scheme = "http"
569586
}
570-
initial_delay_seconds = 60
587+
initial_delay_seconds = 400
571588
period_seconds = 10
572589
timeout_seconds = 5
573590
failure_threshold = 3
@@ -593,7 +610,7 @@ resource "azurerm_container_group" "minio_aci_container_group" {
593610
MINIO_ROOT_USER = var.minio_root_user
594611
MINIO_ROOT_PASSWORD = var.minio_root_password
595612
MINIO_BROWSER_REDIRECT_URL = "https://${azurerm_public_ip.agw_pip.fqdn}"
596-
MINIO_IDENTITY_OPENID_CONFIG_URL = "http://localhost:8082/realms/minio_realm/.well-known/openid-configuration"
613+
MINIO_IDENTITY_OPENID_CONFIG_URL = "http://localhost:8083/realms/minio_realm/.well-known/openid-configuration"
597614
MINIO_IDENTITY_OPENID_CLIENT_ID = "minio-client"
598615
MINIO_IDENTITY_OPENID_CLIENT_SECRET = var.keycloak_client_secret
599616
MINIO_IDENTITY_OPENID_CLAIM_NAME = "policy"
@@ -631,7 +648,7 @@ resource "azurerm_container_group" "minio_aci_container_group" {
631648
name = "coraza-waf"
632649
image = var.coraza_waf_image
633650
cpu = "1.0"
634-
memory = "1.0"
651+
memory = "2.0"
635652
cpu_limit = 1.0
636653
memory_limit = 2.0
637654
ports {
@@ -667,16 +684,16 @@ resource "azurerm_container_group" "minio_aci_container_group" {
667684
}
668685
# The Caddyfile is included as part of the container build.
669686
# If you are testing or want to use a different configuration, you can provide your own
670-
# volume {
671-
# name = "caddyfile"
672-
# mount_path = "/etc/caddy"
673-
# read_only = true
674-
675-
# secret = {
676-
# "Caddyfile" = base64encode(templatefile("${path.module}/Caddyfile.working.tpl", {
677-
# }))
678-
# }
679-
# }
687+
volume {
688+
name = "caddyfile"
689+
mount_path = "/etc/caddy"
690+
read_only = true
691+
692+
secret = {
693+
"Caddyfile" = base64encode(templatefile("${path.module}/Caddyfile.azure", {
694+
}))
695+
}
696+
}
680697

681698
}
682699
}

variables.tf

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,16 @@ variable "allowed_ip_addresses" {
8787
}
8888
}
8989

90-
variable "postgres_db" {
90+
variable "mariadb_database" {
9191
type = string
92-
default = "keycloakdb"
93-
description = "PostgreSQL database name for Keycloak"
92+
default = "mariadb"
93+
description = "MariaDB database name for Keycloak"
9494
}
9595

96-
variable "postgres_user" {
96+
variable "mariadb_user" {
9797
type = string
98-
default = "psuser"
99-
description = "PostgreSQL username"
100-
}
101-
102-
variable "postgres_password" {
103-
type = string
104-
sensitive = true
105-
nullable = false
106-
description = "PostgreSQL password"
107-
validation {
108-
condition = length(var.postgres_password) > 0
109-
error_message = "PostgreSQL password cannot be empty."
110-
}
98+
default = "keycloak"
99+
description = "MariaDB username"
111100
}
112101

113102
variable "keycloak_admin_user" {

0 commit comments

Comments
 (0)