add gateway automatic template and fefan vm
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
ACT_RUNNER_VERSION=0.2.13
|
||||
ACT_RUNNER_LOCATION=/usr/local/bin
|
||||
ACT_RUNNER_USER=act_runner
|
||||
ENV_FILE_LOCATION=/opt/bookshelf/secrets/bookshelf.env
|
||||
ENV_FILE_LOCATION=/opt/bookshelf/bookshelf.env
|
||||
GITEA_INSTANCE_URL=https://gitea.aldon.fr
|
||||
GITEA_RUNNER_REGISTRATION_TOKEN=<gitea-repository-runner-token>
|
||||
GITEA_BOOKSHELF_APPLICATION_TOKEN=<gitea-auth-token>
|
||||
|
||||
@@ -26,16 +26,15 @@ packages:
|
||||
- curl
|
||||
- jq
|
||||
|
||||
mounts:
|
||||
- [ "192.168.1.12:/main/backups", "/backups", "nfs", "defaults,_netdev,x-systemd.requires=network-online.target", "0", "0" ]
|
||||
|
||||
write_files:
|
||||
- path: /etc/fstab
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${proxmox_host_ip}:/main/backups /backups nfs defaults,_netdev,x-systemd.requires=network-online.target 0 0
|
||||
- path: /opt/bookshelf/env.sh
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${environment-setup-script}
|
||||
- path: /opt/bookshelf/secrets/bookshelf.env
|
||||
- path: /opt/bookshelf/bookshelf.env
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${env-file-content}
|
||||
@@ -51,11 +50,11 @@ write_files:
|
||||
permissions: "0755"
|
||||
content: |
|
||||
${create-backup-script}
|
||||
- path: /etc/systemd/system/weekly-backup.timer
|
||||
- path: /etc/systemd/system/create-backup.timer
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${create-backup-timer}
|
||||
- path: /etc/systemd/system/weekly-backup.service
|
||||
- path: /etc/systemd/system/create-backup.service
|
||||
permissions: "0644"
|
||||
content: |
|
||||
${create-backup-service}
|
||||
@@ -76,7 +75,7 @@ runcmd:
|
||||
# Backup setup
|
||||
- mkdir -p /backups
|
||||
- mount -t nfs ${proxmox_host_ip}:/main/backups /backups
|
||||
- systemctl enable --now weekly-backup.timer
|
||||
- systemctl enable --now create-backup.timer
|
||||
# Docker setup
|
||||
- systemctl enable docker
|
||||
- systemctl start docker
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
source /opt/bookshelf/env.sh
|
||||
|
||||
TIMESTAMP=$(date +'%Y-%m-%d_%H%M%S')
|
||||
docker exec bookshelf-database-1 mariadb-dump --all-database -u root -p"$MARIADB_ROOT_PASSWORD" > $BOOKSHELF_BACKUPS_DIR/bookshelf-dump-$TIMESTAMP.sql
|
||||
docker exec bookshelf-database-1 mariadb-dump --all-databases -u root -p"$MARIADB_ROOT_PASSWORD" > $BOOKSHELF_BACKUPS_DIR/bookshelf-dump-$TIMESTAMP.sql
|
||||
|
||||
ls -1dt $BOOKSHELF_BACKUPS_DIR/$BOOKSHELF_BACKUP_PREFIX-*.zip | tail -n +5 | xargs -r rm -f
|
||||
ls -1dt $BOOKSHELF_BACKUPS_DIR/$BOOKSHELF_BACKUP_PREFIX-*.sql | tail -n +5 | xargs -r rm -f
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
set -a
|
||||
[ -f /opt/bookshelf/secrets/bookshelf.env ] && source /opt/bookshelf/secrets/bookshelf.env
|
||||
[ -f /opt/bookshelf/bookshelf.env ] && source /opt/bookshelf/bookshelf.env
|
||||
set +a
|
||||
@@ -31,6 +31,17 @@ done
|
||||
|
||||
if [ "$CONCLUSION" = "success" ]; then
|
||||
echo "Launching command..."
|
||||
|
||||
while [ "$(docker inspect -f '{{.State.Running}}' bookshelf-database-1 2>/dev/null)" != "true" ]; do
|
||||
echo "Waiting database container status"
|
||||
sleep 5
|
||||
done
|
||||
|
||||
until docker exec bookshelf-database-1 sh -c "mariadb -u root -p$MARIADB_ROOT_PASSWORD -e 'SELECT 1;' >/dev/null 2>&1"; do
|
||||
echo "Waitin mariadb to accept connections"
|
||||
sleep 5
|
||||
done
|
||||
echo "Restoring backup"
|
||||
systemctl start restore-backup.service
|
||||
else
|
||||
echo "Workflow failed or was cancelled, aborting."
|
||||
|
||||
@@ -2,6 +2,16 @@
|
||||
|
||||
source /opt/bookshelf/env.sh
|
||||
|
||||
## .env should define
|
||||
# ACT_RUNNER_USER: act_runner username (act_runner)
|
||||
# ACT_RUNNER_LOCATION: act_runner binary location (/usr/local/bin)
|
||||
# ACT_RUNNER_VERSION: act_runner version (0.2.13)
|
||||
# ENV_FILE_LOCATION: .env file location on vm (/opt/bookshelf/bookshelf.env)
|
||||
# GITEA_INSTANCE_URL: url of the gitea instance (https://gitea.aldon.fr)
|
||||
# GITEA_RUNNER_REGISTRATION_TOKEN: registration token for gitea runner (repository scope)
|
||||
# USERNAME: username of the vm (bookshelf)
|
||||
# REPOSITORY: repository on which service code is hosted (mop/bookshelf)
|
||||
|
||||
if ! id -u $ACT_RUNNER_USER >/dev/null 2>&1; then
|
||||
adduser \
|
||||
--system \
|
||||
@@ -30,9 +40,9 @@ runner:
|
||||
fetch_interval: 2s
|
||||
github_mirror: ''
|
||||
labels:
|
||||
- "ubuntu-latest:docker://docker.gitea.com/runner-images:ubuntu-latest"
|
||||
- "ubuntu-22.04:docker://docker.gitea.com/runner-images:ubuntu-22.04"
|
||||
- "ubuntu-20.04:docker://docker.gitea.com/runner-images:ubuntu-20.04"
|
||||
- 'ubuntu-latest:docker://docker.gitea.com/runner-images:ubuntu-latest'
|
||||
- 'ubuntu-22.04:docker://docker.gitea.com/runner-images:ubuntu-22.04'
|
||||
- 'ubuntu-20.04:docker://docker.gitea.com/runner-images:ubuntu-20.04'
|
||||
cache:
|
||||
enabled: true
|
||||
dir: ""
|
||||
@@ -55,5 +65,5 @@ host:
|
||||
EOF
|
||||
|
||||
cd /home/act_runner
|
||||
sudo -u $ACT_RUNNER_USER act_runner register --no-interactive --instance $GITEA_INSTANCE_URL --token $GITEA_RUNNER_REGISTRATION_TOKEN --name $USERNAME --labels $USERNAME $REPOSITORY
|
||||
sudo -u $ACT_RUNNER_USER act_runner register --no-interactive --instance $GITEA_INSTANCE_URL --token $GITEA_RUNNER_REGISTRATION_TOKEN --name $USERNAME --labels $USERNAME
|
||||
chown -R $ACT_RUNNER_USER:docker /home/$ACT_RUNNER_USER
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Backup Service
|
||||
Wants=network.target
|
||||
After=network.target docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/backup.sh
|
||||
@@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=Run Bookshelf backup weekly
|
||||
Description=Run backup weekly
|
||||
|
||||
[Timer]
|
||||
OnCalendar=Sun *-*-* 01:00:00
|
||||
@@ -1,11 +1,9 @@
|
||||
[Unit]
|
||||
Description=Restore latest Bookshelf backup
|
||||
Description=Restore latest backup
|
||||
After=network.target
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/restore-backup.sh
|
||||
WorkingDirectory=/home/bookshelf
|
||||
TimeoutStartSec=600
|
||||
ExecStart=/usr/local/bin/restore-backup.sh
|
||||
@@ -1,10 +0,0 @@
|
||||
[Unit]
|
||||
Description=Weekly Bookshelf Backup
|
||||
Wants=network.target
|
||||
After=network.target docker.service
|
||||
Before=shutdown.target reboot.target halt.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/backup.sh
|
||||
@@ -5,7 +5,7 @@ module "vm" {
|
||||
domain = var.domain
|
||||
vm_id = var.vm_id
|
||||
node_name = var.node_name
|
||||
vm_ip_address = "192.168.1.91"
|
||||
vm_ip_address = var.vm_ip_address
|
||||
|
||||
template_id = var.template_id
|
||||
|
||||
@@ -26,8 +26,8 @@ module "vm" {
|
||||
restore-backup-script = indent(6, file("${path.module}/lib/scripts/restore-backup.sh"))
|
||||
restore-backup-service = indent(6, file("${path.module}/lib/services/restore-backup.service"))
|
||||
create-backup-script = indent(6, file("${path.module}/lib/scripts/create-backup.sh"))
|
||||
create-backup-service = indent(6, file("${path.module}/lib/services/weekly-backup.service"))
|
||||
create-backup-timer = indent(6, file("${path.module}/lib/services/weekly-backup.timer"))
|
||||
create-backup-service = indent(6, file("${path.module}/lib/services/create-backup.service"))
|
||||
create-backup-timer = indent(6, file("${path.module}/lib/services/create-backup.timer"))
|
||||
act_runner-service = indent(6, file("${path.module}/lib/services/act_runner.service"))
|
||||
act_runner-install-script = indent(6, file("${path.module}/lib/scripts/install-runner.sh"))
|
||||
bookshelf-install-script = indent(6, file("${path.module}/lib/scripts/install-bookshelf.sh"))
|
||||
|
||||
9
modules/apps/bookshelf/output.tf
Normal file
9
modules/apps/bookshelf/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
|
||||
}]
|
||||
}
|
||||
@@ -21,6 +21,12 @@ variable "memory" {
|
||||
default = 2048
|
||||
}
|
||||
|
||||
variable "balloon" {
|
||||
description = "Minimum vm memory, using ballooning devide to reach Proxmox node memory target."
|
||||
type = number
|
||||
default = 1024
|
||||
}
|
||||
|
||||
variable "template_id" {
|
||||
type = number
|
||||
}
|
||||
@@ -49,4 +55,8 @@ variable "disk_size" {
|
||||
|
||||
variable "proxmox_host_ip" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_ip_address" {
|
||||
type = string
|
||||
}
|
||||
Reference in New Issue
Block a user