From 3f2465f45accf6db5c66edb94588b60bd04a77c1 Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Sun, 26 Apr 2020 18:14:26 +0100 Subject: [PATCH] #7 remove parts related to deployment these are in https://github.com/Subscribie/subscribie-deployer --- .env.example | 13 -- app.skel | 13 -- config.ini.example | 15 -- main.py | 163 ---------------------- mass-apache-jamla.conf.example | 91 ------------ migrations/0-create-table-onboard_item.py | 42 ------ migrations/1-create-table-site.py | 41 ------ migrations/3-create-table-onboard_item.py | 42 ------ 8 files changed, 420 deletions(-) delete mode 100644 .env.example delete mode 100644 app.skel delete mode 100644 config.ini.example delete mode 100644 main.py delete mode 100644 mass-apache-jamla.conf.example delete mode 100755 migrations/0-create-table-onboard_item.py delete mode 100755 migrations/1-create-table-site.py delete mode 100755 migrations/3-create-table-onboard_item.py diff --git a/.env.example b/.env.example deleted file mode 100644 index 5a79bce..0000000 --- a/.env.example +++ /dev/null @@ -1,13 +0,0 @@ -APACHE_CONF_FILE="/path/subscription-website-deployer/mass-apache.conf" -SUBSCRIBIE_DOMAIN="subscriby.shop" -SITES_DIRECTORY="/path/subscription-website-deployer/sites/" -APACHE_USER="apacheuser" -DEPLOY_EMAIL_HOST="mail.example.com" -DEPLOY_GOCARDLESS_CLIENT_ID="abc123" -DEPLOY_GOCARDLESS_CLIENT_SECRET="abc123" -EMAIL_LOGIN_FROM="noreply@example.com" -MAIL_SERVER="email.example.com" -MAIL_USERNAME="noreply@example.com" -MAIL_PASSWORD="password" -MAIL_USE_TLS="True" -MAIL_PORT="25" diff --git a/app.skel b/app.skel deleted file mode 100644 index 6af6fb3..0000000 --- a/app.skel +++ /dev/null @@ -1,13 +0,0 @@ -[uwsgi] -strict = true -# %d absolute path of the directory containing the configuration file -chdir = %d/subscribie -virtualenv = %d/subscribie/venv -wsgi-file = %d/subscribie/subscribie.wsgi -master = true -vacuum = true -# %n the filename without extension -# NOTE filename must be uniqe (socket must be -# uniq per app so we use the .ini -socket = /tmp/sockets/%n.sock -#subscribe-to = /tmp/sock2:three.example.com diff --git a/config.ini.example b/config.ini.example deleted file mode 100644 index 1773abc..0000000 --- a/config.ini.example +++ /dev/null @@ -1,15 +0,0 @@ -[uwsgi] -# Example uwsgi emperor config -# run with: uwsgi --ini config.ini -strict = true -protocol = uwsgi -master = true -pidfile = uwsgi.pid -emperor = ./sites/*/*.ini -#fastrouter = /tmp/sock1 -fastrouter = 127.0.0.1:8001 -chown-socket = www-data:www-data -chmod = 777 -fastrouter-subscription-server = /tmp/sock2 -vacuum = true - diff --git a/main.py b/main.py deleted file mode 100644 index 66e6ec1..0000000 --- a/main.py +++ /dev/null @@ -1,163 +0,0 @@ -import os, errno, shutil -from urllib.request import urlopen -import subprocess -from flask import Flask, request, redirect, url_for -from werkzeug.utils import secure_filename -import git -import yaml -import sqlite3 -import datetime -from base64 import b64encode, urlsafe_b64encode -import random -from pathlib import Path -from flask_migrate import upgrade -from flask_sqlalchemy import SQLAlchemy -from flask_migrate import Migrate - - -app = Flask(__name__) - -db = SQLAlchemy() -db.init_app(app) -Migrate(app, db) - -# Load .env settings -curDir = os.path.dirname(os.path.realpath(__file__)) -app.config.from_pyfile('/'.join([curDir, '.env'])) - -@app.route('/', methods=['GET', 'POST']) -@app.route('/deploy', methods=['GET', 'POST']) -def deploy(): - if 'file' not in request.files: - return 'No file part.' - file = request.files['file'] - # if user does not select file, browser also - # submit a empty part without filename - if file.filename == '': - return 'No selected file' - if file: - # Store submitted jamla file in its site folder - filename = secure_filename(file.filename) - filename = filename.split('.')[0] - webaddress = filename.lower() + '.' + app.config['SUBSCRIBIE_DOMAIN'] - # Create directory for site - try: - dstDir = app.config['SITES_DIRECTORY'] + webaddress + '/' - if Path(dstDir).exists(): - print("Site {} already exists. Exiting...".format(webaddress)) - exit() - os.mkdir(dstDir) - file.save(os.path.join(dstDir, filename + '.yaml')) - # Rename to jamla.yaml - shutil.move(os.path.join(dstDir, filename + '.yaml'), dstDir + 'jamla.yaml') - except OSError as e: - if e.errno != errno.EEXIST: - raise - # Clone subscribie repo & set-up .env files - try: - git.Git(dstDir).clone("https://github.com/Subscribie/subscribie") - # Generate config.py file - response = urlopen('https://raw.githubusercontent.com/Subscribie/subscribie/master/subscribie/config.py.example') - configfile = response.read() - with open(dstDir + 'subscribie' + '/instance/config.py', 'wb') as fh: - fh.write(configfile) - - except Exception as e: - print("Did not clone subscribie for some reason") - print(e.message, e.args) - pass - # Clone Subscriber Matching Service - try: - git.Git(dstDir).clone('https://github.com/Subscribie/subscription-management-software') - except Exception as e: - print("Didn't clone subscriber matching service") - print(e.message, e.args) - # Create virtualenv & install subscribie requirements to it - print("Creating virtualenv") - call = subprocess.call('export LC_ALL=C.UTF-8; export LANG=C.UTF-8; virtualenv -p python3 venv', cwd= ''.join([dstDir, 'subscribie']), shell=True) - # Activate virtualenv and install requirements - call = subprocess.call('export LC_ALL=C.UTF-8; export LANG=C.UTF-8; . venv/bin/activate;pip install -r requirements.txt', cwd= ''.join([dstDir, 'subscribie']), shell=True) - - # Run subscribie_cli init - call = subprocess.call('export LC_ALL=C.UTF-8; export LANG=C.UTF-8; subscribie init', cwd= ''.join([dstDir, 'subscribie']), shell=True) - print(call) - - shutil.move(''.join([dstDir, 'subscribie/', 'data.db']), dstDir) - - # Migrate the database - app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + dstDir + 'data.db' - upgrade(directory=dstDir + 'subscribie/migrations') - - # Seed users table with site owners email address so they can login - fp = open(dstDir + 'jamla.yaml', 'r') - jamla = yaml.load(fp) - for email in jamla['users']: - con = sqlite3.connect(dstDir + 'data.db') - con.text_factory = str - cur = con.cursor() - now = datetime.datetime.now() - login_token = str(urlsafe_b64encode(os.urandom(24))) - cur.execute("INSERT INTO user (email, created_at, active, login_token) VALUES (?,?,?,?)", (email, now, 1, login_token,)) - con.commit() - con.close() - - # Set JAMLA path, STATIC_FOLDER, and TEMPLATE_FOLDER - jamlaPath = dstDir + 'jamla.yaml' - cliWorkingDir = ''.join([dstDir, 'subscribie']) - theme_folder = ''.join([dstDir, 'subscribie', '/themes/']) - static_folder = ''.join([theme_folder, 'theme-jesmond/static/']) - - settings = ' '.join([ - '--JAMLA_PATH', jamlaPath, - '--TEMPLATE_FOLDER', theme_folder, - '--STATIC_FOLDER', static_folder, - '--UPLOADED_IMAGES_DEST', dstDir + 'static/', - '--DB_FULL_PATH', dstDir + 'data.db', - '--SUCCESS_REDIRECT_URL', 'https://' + webaddress + '/complete_mandate', - '--THANKYOU_URL', 'https://' + webaddress + '/thankyou', - '--MAIL_SERVER', app.config['MAIL_SERVER'], - '--MAIL_PORT', "25", - '--MAIL_DEFAULT_SENDER', app.config['EMAIL_LOGIN_FROM'], - '--MAIL_USERNAME', app.config['MAIL_USERNAME'], - '--MAIL_PASSWORD', ''.join(['"', app.config['MAIL_PASSWORD'], '"']), - '--MAIL_USE_TLS' , app.config['MAIL_USE_TLS'], - '--EMAIL_LOGIN_FROM', app.config['EMAIL_LOGIN_FROM'], - '--GOCARDLESS_CLIENT_ID', app.config['DEPLOY_GOCARDLESS_CLIENT_ID'], - '--GOCARDLESS_CLIENT_SECRET', app.config['DEPLOY_GOCARDLESS_CLIENT_SECRET'], - ]) - subprocess.call('export LC_ALL=C.UTF-8; export LANG=C.UTF-8; subscribie setconfig ' + settings, cwd = cliWorkingDir\ - , shell=True) - - fp.close() - - fp = open(dstDir + 'jamla.yaml', 'w+') - jamla['modules_path'] = [ dstDir + 'subscription-management-software' ] - output = yaml.dump(jamla) - fp.write(output) - fp.close() - # Store submitted icons in sites staic folder - if 'icons' in request.files: - for icon in request.files.getlist('icons'): - iconFilename = secure_filename(icon.filename) - icon.save(os.path.join(static_folder, iconFilename)) - - # Begin uwsgi vassal config creation - # Open application skeleton (app.skel) file and append - # "subscribe-to = " config entry for the new - # sites webaddress so that uwsgi's fastrouter can route the hostname. - curDir = os.path.dirname(os.path.realpath(__file__)) - with open(curDir + '/' + 'app.skel') as f: - contents = f.read() - # Append uwsgi's subscribe-to line with hostname of new site: - contents += "\nsubscribe-to = /tmp/sock2:" + webaddress + "\n" - # Writeout .ini config to file. uwsgi watches for .ini files - # uwsgi will automatically detect this .ini file and start - # routing requests to the site - with open(dstDir + '/' + webaddress + '.ini', 'w') as f: - f.write(contents) - - login_url = ''.join(['https://', webaddress, '/login/', login_token]) - - return login_url - -application = app diff --git a/mass-apache-jamla.conf.example b/mass-apache-jamla.conf.example deleted file mode 100644 index 60d5d76..0000000 --- a/mass-apache-jamla.conf.example +++ /dev/null @@ -1,91 +0,0 @@ -# Created by Christopher Simpson 04/14/2018 -# Based on mass hosting config for lamp stacks 10/05/2016 21:01 -# Documentation Reference: https://httpd.apache.org/docs/current/vhosts/mass.html - -# get the server name from the Host: header -UseCanonicalName Off - -# this log format cab be split per-virtual-host based on the first field -# using the split-logfile utility. -LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon -CustomLog "/var/log/apache2/access_log" vcommon - - - - - - ServerName $host - ServerAlias www.$host - DocumentRoot $dir - RewriteEngine On - - # Public document root - - Order allow,deny - Allow from all - Require all granted - - - # Crab instant payments - Alias "/up-front-payment" "$dir/Crab" - - # Hedgehog subscription service - - Order allow,deny - Allow from all - Require all granted - - - WSGIScriptAlias / $dir/hedgehog/shortly/Hedgehog.py - WSGIDaemonProcess $host user=$uid group=$uid processes=2 socket-user=$uid python-path=$dir/hedgehog/shortly display-name=$host - WSGIProcessGroup $host - ErrorLog /var/log/apache2/subscriber$host.log - - - - - - - ServerName $host - ServerAlias www.$host - DocumentRoot "$dir" - - # Public document root - - Order allow,deny - Allow from all - Require all granted - - # Crab instant payments - Alias "/up-front-payment" "$dir/Crab" - - - AssignUserId $uid $uid - - - - Order allow,deny - Allow from all - Require all granted - - - WSGIScriptAlias / $dir/hedgehog/shortly/Hedgehog.py - WSGIDaemonProcess $host-ssl user=$uid group=$uid processes=1 socket-user=$uid python-path=$dir/hedgehog/shortly display-name=$host - WSGIProcessGroup $host - ErrorLog /var/log/apache2/subscriber$host.log - - SSLEngine On - SSLProtocol All -SSLv2 -SSLv3 -TLSv1 - SSLHonorCipherOrder On - SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA - SSLCertificateFile /home/subwebbuild/.acme.sh/*.subscriby.shop/*.subscriby.shop.cer - SSLCertificateKeyFile /home/subwebbuild/.acme.sh/*.subscriby.shop/*.subscriby.shop.key - SSLCertificateChainFile /home/subwebbuild/.acme.sh/*.subscriby.shop/fullchain.cer - - - -WSGISocketPrefix /var/run/wsgi -# Example host. Add another line to add another host. mod_macro will loop over each site. -# Use VHost subdomain.example.com username /path/to/sites/subdomain.example.com/ -# Use SSL subdomain.example.com username 443 userbane /path/to/sites/subdomain.example.com/ - diff --git a/migrations/0-create-table-onboard_item.py b/migrations/0-create-table-onboard_item.py deleted file mode 100755 index ee7f1d3..0000000 --- a/migrations/0-create-table-onboard_item.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -import sqlite3 -import argparse - - -def up(): - con = sqlite3.connect(args.db) - - cur = con.cursor() - cur.executescript(''' - CREATE TABLE IF NOT EXISTS onboard_item - ( - name text, - complete boolean default 0 - ); - INSERT INTO onboard_item (name) VALUES("has_connected_stripe"); - INSERT INTO onboard_item (name) VALUES("has_connected_gocardless"); - ''') - con.commit() - -def down(): - con = sqlite3.connect(args.db) - cur = con.cursor() - cur.execute(''' - DROP TABLE onboard_item - ''') - con.commit() - -parser = argparse.ArgumentParser() -parser.add_argument("-db", "-database", default="../../../data.db", help="Path to the sqlite database") -group = parser.add_mutually_exclusive_group() -group.add_argument("-up", action="store_true", help="Run the 'up' migration.") -group.add_argument("-down", action="store_true", help="Run the 'down' migration.") - -args = parser.parse_args() - -if args.up: - print("Running 'up' migration.") - up() -elif args.down: - print("Running 'down' migration.") - down() diff --git a/migrations/1-create-table-site.py b/migrations/1-create-table-site.py deleted file mode 100755 index 85b3035..0000000 --- a/migrations/1-create-table-site.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python -import sqlite3 -import argparse - - -def up(): - con = sqlite3.connect(args.db) - - cur = con.cursor() - cur.execute(''' - CREATE TABLE IF NOT EXISTS site ( - site_id int PRIMARY KEY, - site_path text, - created_at timestamp, - active boolean - ) - ''') - con.commit() - -def down(): - con = sqlite3.connect(args.db) - cur = con.cursor() - cur.execute(''' - DROP TABLE site - ''') - con.commit() - -parser = argparse.ArgumentParser() -parser.add_argument("-db", "-database", default="../../../data.db", help="Path to the sqlite database") -group = parser.add_mutually_exclusive_group() -group.add_argument("-up", action="store_true", help="Run the 'up' migration.") -group.add_argument("-down", action="store_true", help="Run the 'down' migration.") - -args = parser.parse_args() - -if args.up: - print("Running 'up' migration.") - up() -elif args.down: - print("Running 'down' migration.") - down() diff --git a/migrations/3-create-table-onboard_item.py b/migrations/3-create-table-onboard_item.py deleted file mode 100755 index ee7f1d3..0000000 --- a/migrations/3-create-table-onboard_item.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -import sqlite3 -import argparse - - -def up(): - con = sqlite3.connect(args.db) - - cur = con.cursor() - cur.executescript(''' - CREATE TABLE IF NOT EXISTS onboard_item - ( - name text, - complete boolean default 0 - ); - INSERT INTO onboard_item (name) VALUES("has_connected_stripe"); - INSERT INTO onboard_item (name) VALUES("has_connected_gocardless"); - ''') - con.commit() - -def down(): - con = sqlite3.connect(args.db) - cur = con.cursor() - cur.execute(''' - DROP TABLE onboard_item - ''') - con.commit() - -parser = argparse.ArgumentParser() -parser.add_argument("-db", "-database", default="../../../data.db", help="Path to the sqlite database") -group = parser.add_mutually_exclusive_group() -group.add_argument("-up", action="store_true", help="Run the 'up' migration.") -group.add_argument("-down", action="store_true", help="Run the 'down' migration.") - -args = parser.parse_args() - -if args.up: - print("Running 'up' migration.") - up() -elif args.down: - print("Running 'down' migration.") - down()