Browse Source

Remove Vagrant

develop
Sam Black 4 years ago
parent
commit
44d2931ed8
Signed by: samwwwblack GPG Key ID: 0FF0223994EA47D8
  1. 24
      Vagrantfile
  2. 125
      deployment/vagrant/bootstrap.sh
  3. 21
      deployment/vagrant/gunicorn.py
  4. 10
      deployment/vagrant/rq_settings.conf
  5. 20
      deployment/vagrant/systemd/cupola-api.service
  6. 17
      deployment/vagrant/systemd/cupola-rq_all@.service
  7. 17
      deployment/vagrant/systemd/cupola-rq_high@.service
  8. 20
      deployment/vagrant/systemd/cupola-runtime.service
  9. 8
      deployment/vagrant/systemd/cupola.slice
  10. 12
      run.py

24
Vagrantfile

@ -1,24 +0,0 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "fedora/23-cloud-base"
config.vm.network "forwarded_port", guest: 8008, host: 8008
config.vm.provider "libvirt" do |libvirt|
libvirt.driver = "kvm"
libvirt.memory = 1024
libvirt.cpus = 1
end
config.vm.provision :shell, path: "deployment/vagrant/bootstrap.sh", args: ENV["DNF_PROXY"]
config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".git/"
config.vm.synced_folder "./cupola", "/home/cupola/cupola/cupola",
type: "rsync", owner: "cupola", group: "nginx",
rsync__args: ["--verbose", "--rsync-path='sudo rsync'",
"--chown=cupola:nginx",
"--archive", "--delete", "-z"]
end

125
deployment/vagrant/bootstrap.sh

@ -1,125 +0,0 @@
#!/usr/bin/env bash
# coding=utf-8
#
# bootstrap.sh: Bootstrap Vagrant build of cupola.
# Copyright (C) 2015-2016 Sam Black <samwwwblack@lapwing.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Add a proxy
if [[ "$1" == "proxy" ]]; then
echo "Setting proxy for RPM/DNF caching"
proxy_url="http://192.168.121.1:3128"
echo "proxy=${proxy_url}" >> /etc/dnf/dnf.conf
for repo in "fedora" "fedora-updates"; do
sed -i 's/^metalink/#metalink/g' /etc/yum.repos.d/${repo}.repo
sed -i 's/^#baseurl/baseurl/g' /etc/yum.repos.d/${repo}.repo
sed -i 's|http://download\.fedoraproject\.org|http://www\.mirrorservice\.org/sites/dl\.fedoraproject\.org|g' /etc/yum.repos.d/${repo}.repo
done
else
proxy_url=""
fi
# Update
echo "Update base system"
dnf update -y
# Install requirements
# PostgreSQL
echo "Install postgresql"
dnf install -y postgresql-server python3-pyscopg2
# Redis
echo "Install redis"
dnf install -y redis hiredis
# python3 basics
# These are already compiled packages,
# so we don't need to keep gcc/*-devel files in the image
echo "Install python3 packages"
dnf install -y python3-greenlet python3-bson python3-markupsafe
dnf install -y python3-coverage
# virtualenv
echo "Install virtualenv"
dnf install -y python3-virtualenv
# We don't install nginx, but require the nginx group
echo "Adding users"
groupadd nginx || echo "nginx already added"
# Add cupola user and group
useradd -G nginx cupola
chown -R cupola:cupola /home/cupola
chown -R cupola:nginx /home/cupola/cupola
# Make up the cupola runtime directories
echo "Adding deployment configs"
install -v -d -g nginx -o cupola /home/cupola/cupola/deployment
install -v -g nginx -o cupola /vagrant/deployment/vagrant/gunicorn.py /home/cupola/cupola/deployment/gunicorn.py
install -v -g nginx -o cupola /vagrant/deployment/vagrant/rq_settings.conf /home/cupola/cupola/deployment/rq_settings.conf
echo "Linking cupola setup"
install -v -g nginx -o cupola /vagrant/run.py /home/cupola/cupola
# Install tmpfiles
echo "Installing tmpfiles.d config"
install -v -g root -o root /vagrant/deployment/tmpfiles.d/cupola-gunicorn.conf /etc/tmpfiles.d/cupola-gunicorn.conf
systemd-tmpfiles --create /etc/tmpfiles.d/cupola-gunicorn.conf
# Install systemd files
echo "Installing systemd files"
install -g root -o root /vagrant/deployment/vagrant/systemd/cupola.slice /etc/systemd/system/cupola.slice
for sdfile in "rq_all@" "runtime"; do
install -g root -o root "/vagrant/deployment/vagrant/systemd/cupola-${sdfile}.service" "/etc/systemd/system/cupola-${sdfile}.service"
done
echo "Reload systemd"
systemctl daemon-reload
echo "Creating postgresql database"
PGSETUP_INITDB_OPTIONS="--auth=trust --auth-local=trust" postgresql-setup --initdb
su -c "createuser -d -s cupola" postgres
echo "Starting DB services"
systemctl start mongod
systemctl start redis
# Create virtualenv
echo "Create virtualenv"
su -c "virtualenv-3.4 -p python3 --system-site-packages /home/cupola/venv" cupola
if [[ "${proxy_url}" != "" ]]; then
su -c "source /home/cupola/venv/bin/activate; pip install --proxy ${proxy_url} -r /vagrant/requirements.testing.txt" cupola
else
su -c "source /home/cupola/venv/bin/activate; pip install -r /vagrant/requirements.testing.txt" cupola
fi
# First run
echo "First run"
su -c "source /home/cupola/venv/bin/activate; cd /home/cupola/cupola/; python3 /home/cupola/cupola/run.py vagrant_init" cupola
# Start the services
echo "Enabling and starting cupola services"
for sdfile in "rq_all@1" "runtime"; do
systemctl enable "cupola-${sdfile}"
systemctl start "cupola-${sdfile}"
done
# We should be done now
echo "All done"
echo -e "=========================\n"
echo -e "\tLogin:\t\t admin@cupola.example.com"
echo -e "\tPassword:\t password\n"
echo "========================="

21
deployment/vagrant/gunicorn.py

@ -1,21 +0,0 @@
# coding=utf8
#
# gunicorn configuration file
# import multiprocessing
# Don't include the PID file path here
# as it is setup in the systemd file.
bind = "0.0.0.0:8008"
# Flask-SocketIO doesn't work with multiple workers
# workers = multiprocessing.cpu_count() * 2 + 1
workers = 1
worker_class = "eventlet"
daemon = False
chdir = "/home/cupola/cupola/"
# This is purely for debugging purposes
reload = True
loglevel = "info"
accesslog = "-"

10
deployment/vagrant/rq_settings.conf

@ -1,10 +0,0 @@
# coding=utf8
#
# Python-RQ settings file
# This is referenced in the systemd unit file,
# if you need local overrides,
# copy it to the instance directory
# and edit it there.
RQ_REDIS_URL="redis://localhost:6379/2"
SENTRY_DSN=""

20
deployment/vagrant/systemd/cupola-api.service

@ -1,20 +0,0 @@
[Unit]
Description=Cupola API gunicorn daemon
After=network.target postgresql.service redis.service cupola-rq_all@1.service
Requires=postgresql.service redis.service
[Service]
PIDFile=/run/gunicorn/api_pid
User=cupola
Group=nginx
WorkingDirectory=/home/cupola/cupola
# Define the PID here rather than the config file to keep it all neat.
ExecStart=/home/cupola/venv/bin/gunicorn --pid /run/gunicorn/api_pid -c /home/cupola/cupola/deployment/gunicorn_api.py cupola.api.wsgi:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
Slice=cupola.slice
CPUShares=1024
[Install]
WantedBy=multi-user.target

17
deployment/vagrant/systemd/cupola-rq_all@.service

@ -1,17 +0,0 @@
[Unit]
Description=Cupola RQ All queues worker
After=redis.service
Requires=redis.service
[Service]
User=cupola
Group=cupola
WorkingDirectory=/home/cupola/cupola
EnvironmentFile=/home/cupola/cupola/deployment/rq_settings.conf
EnvironmentFile=-/home/cupola/cupola/instance/rq_settings.conf
ExecStart=/home/cupola/venv/bin/rqworker -n all_%i high default low
PrivateTmp=true
Slice=cupola.slice
[Install]
WantedBy=multi-user.target

17
deployment/vagrant/systemd/cupola-rq_high@.service

@ -1,17 +0,0 @@
[Unit]
Description=Cupola RQ High queue worker
After=redis.service
Requires=redis.service
[Service]
User=cupola
Group=cupola
WorkingDirectory=/home/cupola/cupola
EnvironmentFile=/home/cupola/cupola/deployment/rq_settings.conf
EnvironmentFile=-/home/cupola/cupola/instance/rq_settings.conf
ExecStart=/home/cupola/venv/bin/rqworker -n high_%i high
PrivateTmp=true
Slice=cupola.slice
[Install]
WantedBy=multi-user.target

20
deployment/vagrant/systemd/cupola-runtime.service

@ -1,20 +0,0 @@
[Unit]
Description=Cupola runtime gunicorn daemon
After=network.target postgresql.service redis.service
Requires=postgresql.service redis.service
[Service]
PIDFile=/run/gunicorn/pid
User=cupola
Group=nginx
WorkingDirectory=/home/cupola/cupola
# Define the PID here rather than the config file to keep it all neat.
ExecStart=/home/cupola/venv/bin/gunicorn --pid /run/gunicorn/pid -c /home/cupola/cupola/deployment/gunicorn.py cupola.wsgi:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
Slice=cupola.slice
CPUShares=1024
[Install]
WantedBy=multi-user.target

8
deployment/vagrant/systemd/cupola.slice

@ -1,8 +0,0 @@
[Unit]
Description=Cupola subservices slice
DefaultDependencies=no
Before=slices.target
[Slice]
CPUShares=1024
MemoryLimit=256M

12
run.py

@ -210,17 +210,5 @@ def first_run():
print("Setup complete")
@manager.command
def vagrant_init():
"""
Create the database and setup a default account for Vagrant use.
"""
init_db()
add_user("admin@cupola.example.com", "password", ("Admin",), True)
print("Vagrant DB setup complete")
if __name__ == '__main__':
manager.run()

Loading…
Cancel
Save