This repository has been archived on 2025-02-14. You can view files and clone it, but cannot push or open issues or pull requests.
pyinfra-uptime-kuma/deploy.py

111 lines
2.3 KiB
Python
Raw Permalink Normal View History

2021-09-12 16:35:36 +09:00
from pyinfra import host
from pyinfra.operations import apt, server, files, systemd
2025-02-15 01:22:52 +09:00
from pyinfra.facts.files import File, Directory
2021-09-12 16:35:36 +09:00
SUDO = True
server.user(
name='Add user benpro',
user='benpro',
groups=['sudo'],
public_keys='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFs7yO0auvwFL8HTLMUq6lET6DMYLhqhd32rqFfZUsjL openpgp:0xA32E99AD',
shell='/bin/bash',
present=True,
)
2025-02-15 01:22:52 +09:00
#apt.update(
# name='Update apt repositories',
#)
#
#apt.upgrade(
# name='Upgrade apt packages',
#)
2021-09-12 16:35:36 +09:00
# Disabled because need to deal with Oracle pre-set rules =_=
#apt.packages(
# name='Install ufw',
# packages=['ufw'],
# update=False,
#)
#
#files.line(
# name='Set port 28 for SSH',
# path='/etc/ssh/sshd_config',
# line=r'Port .*',
# replace='Port 28',
#)
#
#systemd.service(
# name='Reload sshd',
# service='ssh.service',
# reloaded=True,
#)
#
#server.shell(
# name='Add ufw rules',
# commands=['ufw limit 28'],
#)
#
#server.shell(
# name='Enable ufw',
# commands=['yes | ufw enable'],
#)
apt.packages(
name='Install skopeo',
packages=['skopeo'],
update=False,
)
files.download(
name='Download undocker',
src='https://git.sr.ht/~motiejus/undocker/refs/download/v1.0.2/undocker-linux-amd64-v1.0.2',
dest='/usr/local/bin/undocker',
user='root',
group='root',
mode='755',
cache_time=604800,
)
2025-02-15 01:22:52 +09:00
if not host.get_fact(File, '/tmp/uptime-kuma.tar'):
2021-09-12 16:35:36 +09:00
server.shell(
name='Download uptime-kuma',
chdir='/tmp',
commands=['skopeo copy docker://docker.io/louislam/uptime-kuma:latest docker-archive:uptime-kuma.tar'],
)
files.directory(
name='Ensure /opt/uptime-kuma exists',
path='/opt/uptime-kuma',
user='root',
group='root',
mode=755
)
2025-02-15 01:22:52 +09:00
if not host.get_fact(Directory,'/opt/uptime-kuma/app'):
2021-09-12 16:35:36 +09:00
server.shell(
name='Undocker the app',
chdir='/opt/uptime-kuma',
commands=['undocker /tmp/uptime-kuma.tar - | tar -xv'],
)
files.put(
name='Update systemd service file',
src='files/uptime-kuma.service',
dest='/etc/systemd/system/uptime-kuma.service',
mode='644',
)
systemd.daemon_reload(
name='Reload systemd',
user_mode=False,
)
systemd.service(
name='Restart and enable uptime-kuma service',
service='uptime-kuma.service',
running=True,
restarted=True,
enabled=True,
)