Skip to content

Commit 1ff0896

Browse files
authored
Merge branch 'main' into dev
2 parents fe93015 + 3caf4ce commit 1ff0896

6 files changed

Lines changed: 80 additions & 4 deletions

File tree

imageroot/actions/configure-module/10configure_environment_vars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ app_config = {
9393
"SEMAPHORE_TELEGRAM_TOKEN": SEMAPHORE_TELEGRAM_TOKEN
9494
}
9595

96-
agent.write_envfile("app.env", app_config)
96+
agent.write_envfile("app.env", app_config)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# Copyright (C) 2022 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
#
7+
8+
import json
9+
import sys
10+
import agent
11+
import secrets
12+
import base64
13+
import os
14+
15+
# Try to parse the stdin as JSON.
16+
# If parsing fails, output everything to stderr
17+
data = json.load(sys.stdin)
18+
19+
#This is specific to you module, so you need to change it accordingly.
20+
def generate_random_password(length):
21+
# Generate random bytes and convert them to a hexadecimal string
22+
random_bytes = os.urandom(length)
23+
password = random_bytes.hex()
24+
return password[:length]
25+
26+
MARIADB_ROOT_PASSWORD = generate_random_password(16)
27+
MARIADB_DATABASE = data.get("MARIADB_DATABASE", "semaphore")
28+
MARIADB_USER = data.get("MARIADB_USER", "semaphore")
29+
MARIADB_PASSWORD = generate_random_password(16)
30+
MARIADB_AUTO_UPGRADE = data.get("MARIADB_AUTO_UPGRADE", "1")
31+
32+
maria_db = {
33+
"MARIADB_ROOT_PASSWORD": MARIADB_ROOT_PASSWORD,
34+
"MARIADB_DATABASE": MARIADB_DATABASE,
35+
"MARIADB_USER": MARIADB_USER,
36+
"MARIADB_PASSWORD": MARIADB_PASSWORD,
37+
"MARIADB_AUTO_UPGRADE": MARIADB_AUTO_UPGRADE
38+
}
39+
agent.write_envfile("database.env", maria_db)
40+
41+
SECRET_KEY_BYTES = secrets.token_bytes(32)
42+
SECRET_KEY = base64.b64encode(SECRET_KEY_BYTES).decode('utf-8')
43+
44+
SEMAPHORE_DB_HOST = data.get("SEMAPHORE_DB_HOST", "mysql")
45+
46+
app_config = {
47+
"SEMAPHORE_DB_USER": MARIADB_USER,
48+
"SEMAPHORE_DB_PASS": MARIADB_PASSWORD,
49+
"SEMAPHORE_DB_HOST": "mariadb-app",
50+
"SEMAPHORE_DB_PORT": "3306",
51+
"SEMAPHORE_DB_DIALECT": "mysql",
52+
"SEMAPHORE_DB": MARIADB_DATABASE,
53+
"SEMAPHORE_ACCESS_KEY_ENCRYPTION": SECRET_KEY
54+
}
55+
56+
agent.write_envfile("app-db.env", app_config)
57+
58+
#agent.dump_env()

imageroot/actions/restore-module/40restore_database

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ podman run \
3838
--env MARIADB_USER=semaphoreui \
3939
--env MARIADB_PASSWORD=semaphoreui \
4040
--replace --name=restore_db \
41-
${MARIADB_IMAGE}
41+
${MARIADB_IMAGE}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (C) 2023 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
#
7+
set -e
8+
9+
# Redirect any output to the journal (stderr)
10+
exec 1>&2
11+
12+
# If the control reaches this step, the service can be enabled and started
13+
14+
touch smarthost.env
15+
16+
systemctl --user enable semaphoreui.service
17+
systemctl --user restart semaphoreui.service

imageroot/systemd/user/mariadb-app.service

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ After=semaphoreui.service
1111
[Service]
1212
Environment=PODMAN_SYSTEMD_UNIT=%n
1313
EnvironmentFile=%S/state/environment
14+
EnvironmentFile=%S/state/database.env
1415
# EnvironmentFile=%S/state/secrets/passwords.secret
1516
Restart=always
1617
TimeoutStopSec=70
@@ -22,7 +23,7 @@ ExecStart=/usr/bin/podman run --conmon-pidfile %t/mariadb-app.pid \
2223
--volume mysql-data:/var/lib/mysql/:Z \
2324
${MARIADB_IMAGE} \
2425
--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
25-
ExecStartPost=/usr/bin/podman exec mariadb-app /bin/bash -c 'printf "[client] \npassword=Nethesis,1234" > /root/.my.cnf'
26+
ExecStartPost=/usr/bin/podman exec mariadb-app /bin/bash -c 'printf "[client] \npassword=${MARIADB_ROOT_PASSWORD}" > /root/.my.cnf'
2627
ExecStartPost=/usr/bin/podman exec mariadb-app /bin/bash -c "while ! mysqladmin ping -h localhost -P 3306 -u root; do sleep 1; done"
2728
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/mariadb-app.ctr-id -t 10
2829
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/mariadb-app.ctr-id

imageroot/systemd/user/semaphoreui-app.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ PIDFile=%t/semaphoreui-app.pid
3434
Type=forking
3535

3636
[Install]
37-
WantedBy=default.target
37+
WantedBy=default.target

0 commit comments

Comments
 (0)