MetaTrader5-Docker-Goldex/main.tf
bast 3f649fca21
Some checks failed
MT5 Stack Deploy / deploy (push) Failing after 4s
Deploy per Terraform/SSH
2026-11-07 06:31:49 +01:00

72 lines
2 KiB
HCL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Deployt DIESEN Stack per SSH auf den Server – unabhängig von anderen Apps.
# Ablauf: Sperre prüfen -> sauberes Bundle (git archive) in den Stack-Ordner
# kopieren -> scripts/deploy-local.sh (docker compose up -d --build + Check).
# config/, trader-data/, .env und bots.env auf dem Server bleiben unberührt,
# weil sie nicht im Repo (und damit nicht im Bundle) sind.
terraform {
backend "consul" {
address = "consul:8500"
path = "terraform/states/mt5_goldex" # pro Repo eindeutig
}
}
variable "ssh_host" {
type = string
default = "BITMT503"
}
variable "ssh_user" {
type = string
default = "bast"
}
variable "ssh_private_key" {
type = string
sensitive = true
}
variable "stack_dir" {
type = string
default = "/home/bast/build/MetaTrader5-Docker-Goldex"
}
# Wird vom Workflow per "git archive HEAD" erzeugt – nur versionierte Dateien
variable "bundle_dir" {
type = string
default = ".deploy-bundle"
}
resource "terraform_data" "stack" {
# Neu deployen nur, wenn sich eine versionierte Datei geändert hat
triggers_replace = sha1(join("", [
for f in sort(fileset(var.bundle_dir, "**")) : "${f}:${filesha1("${var.bundle_dir}/${f}")}"
]))
connection {
type = "ssh"
host = var.ssh_host
user = var.ssh_user
private_key = var.ssh_private_key
}
# 1. Sperre mit dem Script, das schon auf dem Server liegt (beim ersten Mal fehlt es)
provisioner "remote-exec" {
inline = [
"cd '${var.stack_dir}' && if [ -x scripts/deploy-local.sh ]; then scripts/deploy-local.sh --check-flat; else echo 'Erster Deploy – keine Sperre'; fi",
]
}
# 2. Versionierte Dateien in den Stack-Ordner kopieren
provisioner "file" {
source = "${var.bundle_dir}/"
destination = var.stack_dir
}
# 3. Bauen, starten, auf gesunden Stack warten
provisioner "remote-exec" {
inline = [
"cd '${var.stack_dir}' && chmod +x scripts/*.sh && scripts/deploy-local.sh",
]
}
}