add www/deploy.py

This commit is contained in:
2e20 2024-10-07 02:50:27 +02:00
parent 48be71f4dd
commit 61111796ba

229
www/deploy.py Normal file
View file

@ -0,0 +1,229 @@
from pyinfra import host
from pyinfra.operations import apt, server, files
from pyinfra.facts.server import LinuxName
#import os
files_path = "files/www/"
## check on which Distribution the script is executed
if host.get_fact(LinuxName) == "Debian":
## update apt repositories
apt.update(
name="update apt repositories",
# _doas=True,
# _doas_user="pyinfra",
# _sudo=True,
# _sudo_user="pyinfra",
)
## get repository for php7.3
apt.packages(
name="get repository for php7.3 part-1",
packages=["lsb-release",
"apt-transport-https",
"ca-certificates",
"software-properties-common",
],
)
source_list_d_path = "/etc/apt/source.list.d/"
files.directory(
name="create /etc/apt/source.list.d/",
path=source_list_d_path,
)
server.shell(
name="get repository for php7.3 part-2",
commands=["wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg",
"sh -c 'echo \"deb https://packages.sury.org/php/ $(lsb_release -sc) main\" > /etc/apt/source.list.d/php.list'",
"apt update",
],
)
## insrall php7.3
apt.packages(
name="install php7.3 and php-fpm",
packages=["php7.3", "php-fpm"],
)
apt.packages(
name="install apache2 for httpd.service",
packages=["apache2"],
)
# elif host.get_fact(LinuxName) == "":
else:
print("www deploy.py don't support: \"" + host.get_fact(LinuxName) + "\" yet")
exit("exit from www/deploy.py")
## start the php73_fpm service
#service_name = "php73_fpm"
service_name = "php8.2-fpm.service"
server.service(
# name="enable and restart php73_fpm",
name="enable and restart php8.2-fpm.service",
# service="synapse",
service=service_name,
enabled=True,
running=True,
)
# ? when: phpinstall.changed
## fetch element tarball
url = "https://github.com/vector-im/element-web/releases/download/v1.11.52/element-v1.11.52.tar.gz"
dest = "/tmp/element.tar.gz"
#sha256_checksum = "sha256:1f309d7863f583fef7294aa34ae19413991fd82aebd4c5d8bc3ac72eab04f71a."
sha256_checksum = "1f309d7863f583fef7294aa34ae19413991fd82aebd4c5d8bc3ac72eab04f71a."
checksum_path = "files/www/element.sha256"
files.download(
name="fetch element tarball",
src=url,
dest=dest,
sha256sum=sha256_checksum,
)
'''
server.shell(
name="fetch element tarball",
commands=["wget " +url +" -O " +dest,
"sha256sum --check --quiet " +checksum_path,
],
)
'''
files.directory(
name="create /var/www/",
path="/var/www/",
)
## extract element tarball
server.shell(
name="extract element tarball",
commands=["tar xzf /tmp/element.tar.gz -C /var/www/"],
)
## rm -rf /var/www/element
server.shell(
name="rm -rf /var/www/element",
commands=["rm -rf /var/www/element"],
)
## cp -r /var/www/element-v1.11.52 /var/www/element
element_vers = "element-v1.11.52/"
element_path = "/var/www/" +element_vers
server.shell(
name="cp -r " +element_path +" /var/www/element",
commands=["cp -r " +element_path +" /var/www/element"],
)
#exi = os.path.exists(element_path)
#if exi == True:
'''
files.put(
name="cp -r /var/www/" +element_vers +" /var/www/element",
src=element_path,
dest="/var/www/element/",
)
'''
#else:
# print("file: \"" +element_path +"\" dosn't exists")
## copy element config.json
element_json_path = files_path +"config.json"
#exi = os.path.exists(element_path)
#if exi == True:
files.put(
name="copy element config.json",
src=element_json_path,
dest="/var/www/element/config.json",
)
#else:
# print("file: \"" +element_json_path +"\" dosn't exists")
## copy heizhaus.jpg
heizhaus_jpg_path = files_path +"heizhaus.jpg"
#exi = os.path.exists(heizhaus_jpg_path)
#if exi == True:
files.put(
name="copy heizhaus.jpg",
src=heizhaus_jpg_path,
dest="/var/www/element/heizhaus.jpg",
)
#else:
# print("file: \"" +heizhaus_jpg_path +"\" dosn't exists")
## heizhaus-logo.png
heizhaus_logo_path = files_path +"heizhaus-logo.png"
#exi = os.path.exists(heizhaus_logo_path)
#if exi == True:
files.put(
name="heizhaus-logo.png",
src=heizhaus_logo_path,
dest="/var/www/element/heizhaus-logo.png",
)
#else:
# print("file: \"" +heizhaus_logo_path +"\" dosn't exists")
## mkdir /var/www/matrix
files.directory(
name="mkdir /var/www/matrix",
path="/var/www/matrix",
)
## copy matrix/client
matrix_client_json_path = files_path +"matrix_client.json"
#exi = os.path.exists(matrix_client_json_path)
#if exi == True:
files.put(
name="copy matrix/client",
src=matrix_client_json_path,
dest="/var/www/matrix/client",
)
#else:
# print("file: \"" +matrix_client_json_path +"\" dosn't exists")
## copy matrix/server
matrix_server_json_path = files_path +"matrix_server.json"
#exi = os.path.exists(matrix_server_json_path)
#if exi == True:
files.put(
name="copy matrix/server",
src=matrix_server_json_path,
dest="/var/www/matrix/server",
)
#else:
# print("file: \"" +matrix_server_json_path +"\" dosn't exists")
## copy /etc/httpd.conf
httpd_conf_path = files_path +"httpd.conf"
#exi = os.path.exists(httpd_conf_path)
#if exi == True:
files.put(
name="copy /etc/httpd.conf",
src=httpd_conf_path,
dest="/etc/httpd.conf",
)
#else:
# print("file: \"" +httpd_conf_path +"\" dosn't exists")
## start apache2
server.service(
name="start apache2",
service="apache2",
running=True,
)
'''
server.shell(
name="start apache2",
commands=["/etc/init.d/apache2 start"]
)
'''
## enable and reload httpd
server.service(
name="enable and reload httpd",
service="httpd",
enabled=True,
reloaded=True,
)