diff --git a/deploy.py b/deploy.py index 20b13d9..6861453 100644 --- a/deploy.py +++ b/deploy.py @@ -37,7 +37,7 @@ if host.name != "@local": group="pyinfra", mode="644", # _doas=True, - # _sudo=True, +# _sudo=True, ) if host.name == "ararat.0x90.space": @@ -48,3 +48,6 @@ if host.name == "baixun.0x90.space": if host.name == "chat.heizhaus.org": local.include("matrix-synapse/deploy.py") + +if host.name == "www": + local.include("www/deploy.py") diff --git a/files/www/config.json b/files/www/config.json new file mode 100644 index 0000000..5599a4b --- /dev/null +++ b/files/www/config.json @@ -0,0 +1,35 @@ +{ + "default_server_config": { + "m.homeserver": { + "server_name": "Heizhaus", + "base_url": "https://matrix.0x90.space/" + } + }, + "brand": "Element", + "branding": { + "welcomeBackgroundUrl": "heizhaus.jpg", + "authHeaderLogoUrl": "heizhaus-logo.png", + "authFooterLinks": [ + { + "text": "Homepage", + "url": "https://heizhaus.org/" + }, + { + "text": "Wiki", + "url": "https://wiki.heizhaus.org/" + } + ] + }, + "defaultCountryCode": "DE", + "settingDefaults": { + "UIFeature.registration": false + }, + "disable_custom_urls": true, + "permalinkPrefix": "https://chat.heizhaus.org", + "showLabsSettings": true, + "roomDirectory": { + "servers": [ + "chat.heizhaus.org" + ] + } +} diff --git a/files/www/element.sha256 b/files/www/element.sha256 new file mode 100644 index 0000000..9326ee9 --- /dev/null +++ b/files/www/element.sha256 @@ -0,0 +1 @@ +sha256:1f309d7863f583fef7294aa34ae19413991fd82aebd4c5d8bc3ac72eab04f71a. \ No newline at end of file diff --git a/files/www/heizhaus-logo.png b/files/www/heizhaus-logo.png new file mode 100644 index 0000000..b97cd9e Binary files /dev/null and b/files/www/heizhaus-logo.png differ diff --git a/files/www/heizhaus.jpg b/files/www/heizhaus.jpg new file mode 100644 index 0000000..ac93a62 Binary files /dev/null and b/files/www/heizhaus.jpg differ diff --git a/files/www/httpd.conf b/files/www/httpd.conf new file mode 100644 index 0000000..ee5186c --- /dev/null +++ b/files/www/httpd.conf @@ -0,0 +1,49 @@ +server "0x90.space" { + listen on egress port 80 + log style forwarded + root "/0x90.space" + + tcp { backlog 128 } +} + +server "quellcode.0x90.space" { + listen on egress port 80 + log style forwarded + root "/quellcode.0x90.space" + + tcp { backlog 128 } +} + +server "chat.0x90.space" { + listen on egress port 80 + log style forwarded + root "/element" + + location "/.well-known/matrix/*" { + root "/matrix" + request strip 2 + default type application/json + } + + tcp { backlog 128 } +} + +server "chat.heizhaus.org" { + listen on egress port 80 + log style forwarded + root "/element" + + location "/.well-known/matrix/*" { + root "/matrix" + request strip 2 + default type application/json + } + + tcp { backlog 128 } +} + +# for php: +# directory index "index.php" +# location match ".*%.php" { +# fastcgi socket "/run/php-fpm.sock" +# } diff --git a/files/www/matrix_client.json b/files/www/matrix_client.json new file mode 100644 index 0000000..d05639f --- /dev/null +++ b/files/www/matrix_client.json @@ -0,0 +1,6 @@ +{ + "m.homeserver": { + "base_url": "https://matrix.0x90.space/" + } +} + diff --git a/files/www/matrix_server.json b/files/www/matrix_server.json new file mode 100644 index 0000000..00b017f --- /dev/null +++ b/files/www/matrix_server.json @@ -0,0 +1,4 @@ +{ + "m.server": "matrix.0x90.space:443" +} + diff --git a/inventory.py b/inventory.py index 824a26d..972abcf 100644 --- a/inventory.py +++ b/inventory.py @@ -4,4 +4,5 @@ targets = [ ("baixun.0x90.space", dict(ssh_port=42023)), # ("matrix.0x90.space", dict(ssh_port=42024)), ("chat.heizhaus.org", dict(ssh_port=22, ssh_allow_agent=True, ssh_key="~/.ssh/0x90/id_ed25519")), + ("www", dict(ssh_port=22, ssh_allow_agent=True, ssh_key="~/.ssh/0x90/id_ed25519")), ] diff --git a/www/deploy.py b/www/deploy.py new file mode 100644 index 0000000..f08eebd --- /dev/null +++ b/www/deploy.py @@ -0,0 +1,173 @@ +from pyinfra import host +from pyinfra.operations import apt, server, files +from pyinfra.facts.server import LinuxName + +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 part-1 + apt.packages( + name="get repository for php7.3 part-1", + packages=["lsb-release", + "apt-transport-https", + "ca-certificates", + "software-properties-common", + ], + ) + + ## create /etc/apt/source.list.d/ + source_list_d_path = "/etc/apt/source.list.d/" + files.directory( + name="create /etc/apt/source.list.d/", + path=source_list_d_path, + ) + + ## get repository for php7.3 part-2 + 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"], + ) + + ## install apache2 as replacenebt for httpd.service + apt.packages( + name="install apache2 as replacenebt 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 php8.2-fpm.service service +#service_name = "php73_fpm" +service_name = "php8.2-fpm.service" +server.service( + name="enable and restart php8.2-fpm.service", + 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 = "1f309d7863f583fef7294aa34ae19413991fd82aebd4c5d8bc3ac72eab04f71a." +checksum_path = "files/www/element.sha256" +files.download( + name="fetch element tarball", + src=url, + dest=dest, + sha256sum=sha256_checksum, +) + +## create /var/www/ +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 +## files.put() seams not to be compatible with directorys +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"], +) + +## copy element config.json +element_json_path = files_path +"config.json" +files.put( + name="copy element config.json", + src=element_json_path, + dest="/var/www/element/config.json", +) + +## copy heizhaus.jpg +heizhaus_jpg_path = files_path +"heizhaus.jpg" +files.put( + name="copy heizhaus.jpg", + src=heizhaus_jpg_path, + dest="/var/www/element/heizhaus.jpg", +) + +## heizhaus-logo.png +heizhaus_logo_path = files_path +"heizhaus-logo.png" +files.put( + name="heizhaus-logo.png", + src=heizhaus_logo_path, + dest="/var/www/element/heizhaus-logo.png", + ) + +## 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" +files.put( + name="copy matrix/client", + src=matrix_client_json_path, + dest="/var/www/matrix/client", +) + +## copy matrix/server +matrix_server_json_path = files_path +"matrix_server.json" +files.put( + name="copy matrix/server", + src=matrix_server_json_path, + dest="/var/www/matrix/server", +) + +## copy /etc/httpd.conf +httpd_conf_path = files_path +"httpd.conf" +files.put( + name="copy /etc/httpd.conf", + src=httpd_conf_path, + dest="/etc/httpd.conf", +) + +## start apache2 +service_name = "apache2" +server.service( + name="start apache2", + service=service_name, + running=True, +)