Python script version

This commit is contained in:
Max Fowler 2020-11-10 16:03:45 +01:00
parent f6acbc4c02
commit 9ae0c66f73
11 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,8 @@
Origin: PeachCloud
Label: PeachCloud
Codename: buster
Architectures: amd64
Components: main
Description: Apt repository for PeachCloud debian packages
SignWith: {{gpg_key_id}}
DebOverride: override.buster

View File

@ -0,0 +1,3 @@
verbose
basedir {{debian_rep_dir}}
ask-passphrase

View File

@ -0,0 +1,4 @@
{% for service in services %}
{{service}} Priority optional
{{service}} Section net
{% endfor %}

View File

@ -0,0 +1,13 @@
#!/bin/bash
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to build directory..."
git --work-tree={{src_dir}}/devdocs_build --git-dir={{src_dir}}/devdocs_bare checkout -f
echo "Building docs and deploying to production..."
/root/.cargo/bin/mdbook build {{src_dir}}/devdocs_build --dest-dir {{web_dir}}/docs:peachcloud:org/html
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done

View File

@ -0,0 +1,31 @@
user www-data;
worker_processes 1;
worker_rlimit_nofile 8192;
events {
worker_connections 3000;
}
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

View File

@ -0,0 +1,10 @@
server {
listen 80;
server_name 159.89.5.141;
location / {
root {{web_dir}}/docs:peachcloud:org/html;
index index.html;
try_files $uri $uri/ /index.html;
}
}

View File

View File

@ -0,0 +1,39 @@
from peach_vps_scripts.utils import render_template, cargo_install
from peach_vps_scripts.vars import VARS
import subprocess
import os
print("[ UPDATING OPERATING SYSTEM ]")
subprocess.call(["apt-get", "update", "-y"])
subprocess.call(["apt-get", "upgrade", "-y"])
print("[ INSTALLING SYSTEM REQUIREMENTS ]")
subprocess.call(["apt-get", "install", "git", "nginx", "curl", "build-essential", "mosh"])
print("[ CREATING SYSTEM GROUPS ]")
subprocess.call(["/usr/sbin/groupadd", "peach"])
print("[ ADDING SYSTEM USER ]")
users = ["notplants", "glyph"]
for user in users:
subprocess.call(["/usr/sbin/adduser", user])
subprocess.call(["usermod", "-aG", "sudo", user])
subprocess.call(["/usr/sbin/usermod", "-a", "-G", user, "peach"])
print("[ CREATING DIRECTORIES ]")
folders = [VARS["src_dir"], VARS["www_dir"], VARS["debian_repo_dir"]]
for folder in folders:
if not os.path.exists(folder):
os.makedirs(folder)
print("[ INSTALLING RUST ]")
subprocess.call(["curl", "https://sh.rustup.rs", "-sSf", "|", "sh", "-s", "--", "-y"])
print("[ INSTALLING CARGO PACKAGES ]")
cargo_install("cargo-deb")
render_template(src='nginx/nginx.conf', dest='/etc/nginx/nginx.conf')

View File

@ -0,0 +1,32 @@
from peach_vps_scripts.vars import VARS
import os
import jinja2
import subprocess
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
template_path = os.path.join(PROJECT_PATH, 'templates')
template_loader = jinja2.FileSystemLoader(searchpath=template_path)
template_env = jinja2.Environment(loader=template_loader)
def render_template(src, dest, template_vars=None):
"""
:param src: relative string path to jinja template file
:param dest: absolute string path of output destination file
:param template_vars: variables to render template with
:return: None
"""
template = template_env.get_template(src)
template_vars.update(VARS)
output_text = template.render(template_vars=template_vars)
if os.path.exists(dest):
os.remove(dest)
with open(dest, 'w') as f:
f.write(output_text)
def cargo_install(package):
subprocess.call(['/root/.cargo/bin/cargo', 'install', package])

11
peach_vps_scripts/vars.py Normal file
View File

@ -0,0 +1,11 @@
VARS = {
'log_dir': '/srv/log',
'src_dir': '/srv/src',
'web_dir': 'srv/www',
'debian_rep_dir': '/srv/www/repos/apt/debian',
'gpg_key_id': 'E62CD13A85763FCEC3EDBA8EA98440817F1A3CE5',
'services': [
{'name': 'peach-oled', 'repo_url': 'https://github.com/peachcloud/peach-oled.git'},
{'name': 'peach-oled', 'repo_url': 'https://github.com/peachcloud/peach-oled.git'}
]
}

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
Jinja2==2.11.2