Add(module): add girasol module
Add(module): add amap module Add(module): add common lib and services Add(module): add base structure for keycloak Add(module): add base structure for rocket Add(module): add n8n and windmill modules Add(docker): add install docker script in common module Add(template): add root for aldon.fr and mathieu.wiki in traefik.service template
This commit is contained in:
36
modules/apps/amap/.env.example
Normal file
36
modules/apps/amap/.env.example
Normal file
@@ -0,0 +1,36 @@
|
||||
# Environment files
|
||||
ENV_FILE_LOCATION=/opt/environment/.env
|
||||
|
||||
# gitea act_runner
|
||||
ACT_RUNNER_VERSION=0.2.13
|
||||
ACT_RUNNER_LOCATION=/usr/local/bin
|
||||
ACT_RUNNER_USER=act_runner
|
||||
GITEA_RUNNER_REGISTRATION_TOKEN=<gitea-repository-runner-token>
|
||||
USERNAME=amap
|
||||
|
||||
# gitea instance
|
||||
GITEA_INSTANCE_URL=https://gitea.aldon.fr
|
||||
GITEA_SERVICE_APPLICATION_TOKEN=<gitea-auth-token>
|
||||
GITEA_SERVICE_REPOSITORY=mop/amap
|
||||
GITEA_WORKFLOW_NAME=deploy.yaml
|
||||
|
||||
# Applicaiton specifics
|
||||
DB_USER=postgres
|
||||
DB_PASS=
|
||||
DB_NAME=amap
|
||||
DB_HOST=localhost
|
||||
ORIGINS=https://amap.aldon.fr
|
||||
SECRET_KEY=
|
||||
VITE_API_URL=https://amap.aldon.fr/api
|
||||
KEYCLOAK_SERVER=https://keycloak.aldon.fr
|
||||
KEYCLOAK_REALM=aldon.fr
|
||||
KEYCLOAK_CLIENT_ID=
|
||||
KEYCLOAK_CLIENT_SECRET=
|
||||
KEYCLOAK_REDIRECT_URI=https://amap.aldon.fr/api/auth/callback
|
||||
MAX_AGE=3600
|
||||
DEBUG=True
|
||||
|
||||
# Backup specifics
|
||||
SERVICE_BACKUPS_DIR=/backups/amap
|
||||
SERVICE_BACKUPS_PREFIX=amap-dump
|
||||
SERVICE_BACKUPS_EXTENSION=sql
|
||||
90
modules/apps/amap/cloud-init/service.yaml
Normal file
90
modules/apps/amap/cloud-init/service.yaml
Normal file
@@ -0,0 +1,90 @@
|
||||
#cloud-config
|
||||
hostname: ${hostname}
|
||||
local-hostname: ${hostname}
|
||||
fqdn: ${hostname}.${domain}
|
||||
manage_etc_hosts: true
|
||||
|
||||
users:
|
||||
- default
|
||||
- name: ${hostname}
|
||||
groups: sudo
|
||||
shell: /bin/bash
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
ssh_authorized_keys:
|
||||
- ${ssh_key}
|
||||
|
||||
disable_root: true
|
||||
|
||||
package_update: true
|
||||
package_upgrade: false
|
||||
|
||||
packages:
|
||||
- git
|
||||
- nfs-common
|
||||
- curl
|
||||
- jq
|
||||
- postgresql-client
|
||||
|
||||
mounts:
|
||||
- [ "192.168.1.12:/main/backups", "/backups", "nfs", "defaults,_netdev,x-systemd.requires=network-online.target", "0", "0" ]
|
||||
|
||||
write_files:
|
||||
- path: /opt/environment/.env
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${env-file-content}
|
||||
- path: /opt/${hostname}/install-docker.sh
|
||||
permissions: "0755"
|
||||
content: |
|
||||
${install-docker-script}
|
||||
- path: /usr/local/bin/restore-backup.sh
|
||||
permissions: "0755"
|
||||
content: |
|
||||
${restore-backup-script}
|
||||
- path: /etc/systemd/system/restore-backup.service
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${restore-backup-service}
|
||||
- path: /usr/local/bin/backup.sh
|
||||
permissions: "0755"
|
||||
content: |
|
||||
${create-backup-script}
|
||||
- path: /etc/systemd/system/create-backup.timer
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${create-backup-timer}
|
||||
- path: /etc/systemd/system/create-backup.service
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${create-backup-service}
|
||||
- path: /etc/systemd/system/act_runner.service
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${act_runner-service}
|
||||
- path: /opt/${hostname}/install-runner.sh
|
||||
permissions: "0755"
|
||||
content: |
|
||||
${act_runner-install-script}
|
||||
- path: /opt/${hostname}/install-service.sh
|
||||
permissions: "0755"
|
||||
content: |
|
||||
${service-install-script}
|
||||
|
||||
runcmd:
|
||||
# Backup setup
|
||||
- mkdir -p /backups
|
||||
- mount -t nfs ${proxmox_host_ip}:/main/backups /backups
|
||||
- systemctl enable --now create-backup.timer
|
||||
# Docker setup
|
||||
- /opt/${hostname}/install-docker.sh
|
||||
# Act_runner install
|
||||
- /opt/${hostname}/install-runner.sh
|
||||
- systemctl daemon-reload
|
||||
- systemctl enable act_runner.service
|
||||
- systemctl start act_runner.service
|
||||
# ${hostname} install
|
||||
- /opt/${hostname}/install-service.sh
|
||||
|
||||
|
||||
final_message: |
|
||||
Base system ready for ${hostname}
|
||||
10
modules/apps/amap/lib/scripts/create-backup.sh
Normal file
10
modules/apps/amap/lib/scripts/create-backup.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
source /opt/environment/.env
|
||||
|
||||
TIMESTAMP=$(date +'%Y-%m-%d_%H%M%S')
|
||||
|
||||
sudo -u $USERNAME docker exec -i amap-database-1 pg_dump -F c -U $DB_USER -d $DB_NAME > $SERVICE_BACKUPS_DIR/$SERVICE_BACKUPS_PREFIX-$TIMESTAMP.$SERVICE_BACKUPS_EXTENSION
|
||||
|
||||
ls -1dt $SERVICE_BACKUPS_DIR/$SERVICE_BACKUPS_PREFIX-*.$SERVICE_BACKUPS_EXTENSION | tail -n +5 | xargs -r rm -f
|
||||
10
modules/apps/amap/lib/scripts/restore-backup.sh
Normal file
10
modules/apps/amap/lib/scripts/restore-backup.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
source /opt/environment/.env
|
||||
|
||||
LATEST_BACKUP=$(ls -1 $SERVICE_BACKUPS_DIR/$SERVICE_BACKUPS_PREFIX-*.$SERVICE_BACKUPS_EXTENSION 2>/dev/null | sort | tail -n1)
|
||||
|
||||
if [ -n "$LATEST_BACKUP" ] && [ -f "$LATEST_BACKUP" ]; then
|
||||
sudo -u $USERNAME docker exec -i amap-database-1 pg_restore --clean --if-exists -U "$DB_USER" -v -d "$DB_NAME" < $LATEST_BACKUP
|
||||
fi
|
||||
0
modules/apps/amap/lib/services/.gitkeep
Normal file
0
modules/apps/amap/lib/services/.gitkeep
Normal file
41
modules/apps/amap/main.tf
Normal file
41
modules/apps/amap/main.tf
Normal file
@@ -0,0 +1,41 @@
|
||||
module "vm" {
|
||||
source = "../../vm"
|
||||
name = var.name
|
||||
hostname = var.hostname
|
||||
domain = var.domain
|
||||
vm_id = var.vm_id
|
||||
node_name = var.node_name
|
||||
vm_ip_address = var.vm_ip_address
|
||||
|
||||
template_id = var.template_id
|
||||
|
||||
cores = var.cores
|
||||
memory = var.memory
|
||||
disk_size = var.disk_size
|
||||
|
||||
ssh_public_key = var.ssh_public_key
|
||||
proxmox_host_ip = var.proxmox_host_ip
|
||||
|
||||
cloudinit_config = templatefile(
|
||||
"${path.module}/cloud-init/service.yaml",
|
||||
{
|
||||
hostname = var.hostname
|
||||
domain = var.domain
|
||||
ssh_key = var.ssh_public_key
|
||||
proxmox_host_ip = var.proxmox_host_ip
|
||||
restore-backup-script = indent(6, file("${path.module}/lib/scripts/restore-backup.sh"))
|
||||
restore-backup-service = indent(6, file("${path.module}/../common/services/docker/restore-backup.service"))
|
||||
create-backup-script = indent(6, file("${path.module}/lib/scripts/create-backup.sh"))
|
||||
create-backup-service = indent(6, file("${path.module}}/../common/services/docker/create-backup.service"))
|
||||
create-backup-timer = indent(6, file("${path.module}/../common/services/create-backup.timer"))
|
||||
|
||||
act_runner-service = indent(6, file("${path.module}/../common/services/act_runner.service"))
|
||||
act_runner-install-script = indent(6, file("${path.module}/../common/scripts/install-runner.sh"))
|
||||
|
||||
service-install-script = indent(6, file("${path.module}/../common/scripts/install-service-ci.sh"))
|
||||
install-docker-script = indent(6, file("${path.module}/../common/scripts/install-docker.sh"))
|
||||
|
||||
env-file-content = indent(6, file("${path.module}/.env"))
|
||||
}
|
||||
)
|
||||
}
|
||||
9
modules/apps/amap/output.tf
Normal file
9
modules/apps/amap/output.tf
Normal file
@@ -0,0 +1,9 @@
|
||||
output "traefik_service" {
|
||||
value = [{
|
||||
domain = var.domain
|
||||
name = var.name
|
||||
host = "${var.hostname}"
|
||||
ip = var.vm_ip_address
|
||||
port = 80
|
||||
}]
|
||||
}
|
||||
71
modules/apps/amap/variables.tf
Normal file
71
modules/apps/amap/variables.tf
Normal file
@@ -0,0 +1,71 @@
|
||||
variable "name" {
|
||||
description = "Virtual Machine name"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_id" {
|
||||
description = "Virtual Machine id"
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "node_name" {
|
||||
description = "Proxmox node name"
|
||||
type = string
|
||||
default = "mop"
|
||||
}
|
||||
|
||||
variable "cores" {
|
||||
description = "Number of CPU cores for this virtual machine"
|
||||
type = number
|
||||
default = 2
|
||||
}
|
||||
|
||||
variable "memory" {
|
||||
description = "Memory RAM for this virtual machine"
|
||||
type = number
|
||||
default = 2048
|
||||
}
|
||||
|
||||
variable "balloon" {
|
||||
description = "Minimum vm memory, using ballooning devide to reach Proxmox node memory target."
|
||||
type = number
|
||||
default = 1024
|
||||
}
|
||||
|
||||
variable "template_id" {
|
||||
description = "Virtual machine template ID"
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "ssh_public_key" {
|
||||
description = "Public SSH key for cloud-init user"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "hostname" {
|
||||
description = "Virtual Machine hostname (<service-name>)"
|
||||
type = string
|
||||
default = "test"
|
||||
}
|
||||
|
||||
variable "domain" {
|
||||
description = "Virtual Machine domain (example.fr)"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "disk_size" {
|
||||
description = "Disk size for the virtual machine"
|
||||
type = number
|
||||
default = 10
|
||||
}
|
||||
|
||||
variable "proxmox_host_ip" {
|
||||
description = "Proxmox host base ip"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_ip_address" {
|
||||
description = "Virtual machine ip"
|
||||
type = string
|
||||
}
|
||||
Reference in New Issue
Block a user