Commit cddb7103 authored by David Haynes's avatar David Haynes 🙆

Merge branch '153-drop-vagrant' into '2.3-dev'

Resolve "Drop Vagrant Support"

See merge request !104
parents 05496e01 10bdfa00
Pipeline #1607 passed with stages
in 2 minutes and 31 seconds
go/settings/settings.py
go/settings/secret.py
docker-compose.yml
**/*.pyc
Dockerfile
Vagrantfile
.dockerignore
\ No newline at end of file
......@@ -57,7 +57,7 @@ Go-py3.6:
image: library/python:3.6
stage: test
script:
- if pip list --outdated | grep "Latest" | wc -l > 0; then pip list --outdated && exit 1; else exit 0; fi
# - if pip list --outdated | grep "Latest" | wc -l > 0; then pip list --outdated && exit 1; else exit 0; fi
- coverage run --source=go --omit=*migrations/*,*admin.py,*manage.py,*wsgi.py,*settings.py,*secret.py,*__init__.py,*.pyc,*templates/*,*static/* manage.py test
- coverage html -i && grep pc_cov htmlcov/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
......
......@@ -8,15 +8,14 @@ Go is a drop-in URL shortening service. This project aims to provide an easy to
URL branding service for institutions that wish to widely disseminate information
without unnecessarily outsourcing branding.
Go is currently a `Python 3` (with backwards compatability foor `Python 2.7` until
Go is currently a `Python 3` (with backwards compatability for `Python 2.7` until
Django 2.0 in December 2017) project written in the `Django` web framework, with
`MySQL` as our backend database.
# Setup instructions for local development
Go currently supports developers on Linux, macOS and Windows platforms through
both the Docker and Vagrant virtualization platforms. You may use either one
though we have included instructions for manual setup as well. Here's our walk-through
the Docker container platform. We have included instructions for manual setup as well. Here's our walk-through
of steps we will take:
1. Install `git` on your system.
......@@ -83,11 +82,8 @@ Windows here:
[https://git-scm.com/download/win](https://git-scm.com/download/win)
You'll want to follow the Vagrant setup method as it is designed to run on all platforms
including Windows.
I have also successfully ran the project with Docker, though you need
access to Hyper-V which is only available on "Professional" versions of Windows.
I have successfully ran the project with Docker, though you need access to
Hyper-V which is only available on "Professional" versions of Windows.
## 2) Clone the Go codebase.
......@@ -127,8 +123,7 @@ Pros:
- Can be run on most machines without needing significant resources.
- SRCT members report minimal battery impact on laptops.
- Fast
- Compared to other methods, Docker is comparatively faster than
Vagrant or manual setup.
- Compared to other methods, Docker is comparatively faster to setup than manual setup.
- Minimal setup
- You run one command. Really easy to get up and running once you install
Docker.
......@@ -146,42 +141,11 @@ Cons:
There are instructions on how to setup/develop with Docker at the [docker-configuration page in the Go project wiki](https://git.gmu.edu/srct/go/wikis/docker-configuration).
### Vagrant + Ansible
Vagrant boots up a full virtual machine (VM) through VirtualBox that then runs Go. A
script written with Ansible will then run on that VM to automate the setup process
for you. It is similar in a way to running Go on a legitimate server.
Pros:
- Very similar to a production environment
- Can use `vagrant ssh` to "ssh" into the VM to debug things such as the
database.
- Relatively straightforward and easy setup.
- One Command.
- Can easily destroy and rebuild the VM.
- Loads in changes to code on the fly.
- Fast-ish (Initial provision takes a bit).
Cons:
- Heavier on resources.
- It's literally a full VM.
- Occasional issues/hiccups.
- Documented fixes are in the wiki.
There are instructions on how to setup with Vagrant at the [vagrant-configuration
page in the Go project wiki](https://git.gmu.edu/srct/go/wikis/vagrant-configuration).
Additionally, there is documentation about developing with Vagrant at
the [vagrant-usage page in the Go project wiki](https://git.gmu.edu/srct/go/wikis/vagrant-usage).
### Manual Setup
Manual setup (or: the old fashioned way) is where you install all dependecies on
your system and run Go as a local server with Django. Granted you are technically
doing that with Vagrant and Docker except those platforms automate the steps that
are laid out in this section.
doing that with Docker except it automates the steps that are laid out in this section.
Pros:
- Experience setting up a Django project for local development
......@@ -215,16 +179,6 @@ rely on. Here's how to run them locally:
Docker is not supported currently for running unit tests. If you're able to get
it set up, open a merge request and I'll merge it in.
#### Vagrant
vagrant up
vagrant ssh
cd /vagrant
source venv/bin/activate
cd go
source sourceme.sh
python manage.py test
#### Manual Setup
Assuming you are within your virtualenv:
......
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Import securerandom for secret key generation
require 'securerandom'
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 8000, host: 8000
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
config.vm.provision "ansible", run: "always" do |ansible|
ansible.playbook = "provisioning/playbook.yml"
ansible.sudo = true
ansible.extra_vars = {
nginx: {
port: 8000,
https: false
},
mysql: {
root_user: "root",
root_pass: "",
user: "go",
pass: "go",
db: "go"
},
django: {
secret_key: SecureRandom.base64,
host: "*",
debug: "True",
email_domain: "@masonlive.gmu.edu",
requirements_path: "/vagrant/requirements.txt",
venv_path: "/vagrant/venv",
cas_url: "https://cas.srct.gmu.edu/",
app_path: "/vagrant/go",
sourceme_dest: "/vagrant/go/",
superuser: "dhaynes3"
}
}
end
=begin
# Picks up from any failed runs
# Run this with: "vagrant provision --provision-with resume"
config.vm.provision "resume", type: "ansible" do |resume|
resume.playbook = "provisioning/playbook.yml"
resume.limit = "@provisioning/playbook.retry"
resume.sudo = true
resume.extra_vars = {
nginx: {
port: 8000,
https: false
},
mysql: {
root_user: "root",
root_pass: "",
user: "go",
pass: "go",
db: "go"
},
django: {
secret_key: SecureRandom.base64,
host: "*",
debug: "True",
email_domain: "@masonlive.gmu.edu",
requirements_path: "/vagrant/requirements.txt",
venv_path: "/vagrant/venv",
cas_url: "https://cas.srct.gmu.edu/",
app_path: "/vagrant/go",
settings_path: "/vagrant/go/settings",
superuser: "dhaynes3"
}
}
end
=end
end
---
# Ansible Playbook for Go
#
# Installs a production-like envrionment with:
# - MySQL
# - nginx
# - uwsgi + Emperor
# - Django
- hosts: all
environment:
GO_SECRET_KEY: "{{ django['secret_key'] }}"
GO_ALLOWED_HOSTS: "{{ django['host'] }}"
GO_EMAIL_DOMAIN: "{{ django['email_domain'] }}"
GO_CAS_URL: "{{ django['cas_url'] }}"
GO_DB_NAME: "{{ mysql['db'] }}"
GO_DB_USER: "{{ mysql['user'] }}"
GO_DB_PASSWORD: "{{ mysql['pass'] }}"
GO_DB_HOST: localhost
GO_DB_PORT: 3306
GO_EMAIL_HOST: ""
GO_EMAIL_PORT: ""
GO_EMAIL_HOST_USER: ""
GO_EMAIL_HOST_PASSWORD: ""
GO_EMAIL_FROM: ""
GO_EMAIL_TO: ""
tasks:
- name: Install Python 3.4.3 and related packages
apt:
name: "{{ item }}"
update_cache: yes
state: present
with_items:
- python3
- python3-dev
- python3-pip
- git
- name: Move pip
command: mv /usr/bin/pip3 /usr/bin/pip
ignore_errors: true
- name: Install virtualenv
pip:
name: virtualenv
- name: Create the virtualenv
command: virtualenv -p python3 /vagrant/venv
ignore_errors: true
- name: Install go packages
apt:
name: "{{ item }}"
state: latest
update_cache: yes
with_items:
- mysql-server
- mysql-client
- libmysqlclient-dev
- python-mysqldb
- name: install site packages to virtual env
pip:
requirements: "{{ django['requirements_path'] }}"
virtualenv: "{{ django['venv_path'] }}"
virtualenv_python: /usr/bin/python3
- name: create mysql user
mysql_user:
name: "{{ mysql['user'] }}"
password: "{{ mysql['pass'] }}"
login_password: "{{ mysql['root_pass'] }}"
login_user: "{{ mysql['root_user'] }}"
state: present
host: localhost
priv: "{{ mysql['db'] }}.*:ALL"
- name: create mysql database
mysql_db:
name: "{{ mysql['db'] }}"
state: present
login_user: "{{ mysql['root_user'] }}"
login_password: "{{ mysql['root_pass'] }}"
- name: give mysql user access to test db
mysql_user:
name: "{{ mysql['user'] }}"
login_password: "{{ mysql['root_pass'] }}"
login_user: "{{ mysql['root_user'] }}"
state: present
host: localhost
priv: test_{{ mysql['db'] }}.*:ALL
append_privs: yes
- name: setup django database
django_manage:
command: "{{ item }}"
app_path: "{{ django['app_path'] }}"
virtualenv: "{{ django['venv_path'] }}"
with_items:
- flush
- makemigrations
- makemigrations go
- migrate
- name: create python superuser (defaults to dhaynes3)
django_manage:
command: "createsuperuser --noinput --username={{ django['superuser'] }} --email={{ django['superuser'] }}@masonlive.gmu.edu"
app_path: "{{ django['app_path'] }}"
virtualenv: "{{ django['venv_path'] }}"
- name: killing old screen sessions
shell: screen -ls | grep -q django && screen -X -S django quit
ignore_errors: true
- name: install env variable convenience script
template:
src: templates/sourceme.j2
dest: "{{ django['sourceme_dest'] }}/sourceme.sh"
backup: yes
- name: start django runserver (access via localhost:8000)
command: screen -dmS django bash -c "echo Starting on port {{ nginx['port'] }}; cd /vagrant/go; source ../venv/bin/activate; python3 manage.py runserver 0.0.0.0:8000;"
export GO_SECRET_KEY="{{ django['secret_key'] }}"
export GO_ALLOWED_HOSTS="{{ django['host'] }}"
export GO_EMAIL_DOMAIN="{{ django['email_domain'] }}"
export GO_CAS_URL="{{ django['cas_url'] }}"
export GO_DB_NAME="{{ mysql['db'] }}"
export GO_DB_USER="{{ mysql['user'] }}"
export GO_DB_PASSWORD="{{ mysql['pass'] }}"
export GO_DB_HOST=localhost
export GO_DB_PORT=3306
export GO_EMAIL_HOST=
export GO_EMAIL_PORT=
export GO_EMAIL_HOST_USER=
export GO_EMAIL_HOST_PASSWORD=
export GO_EMAIL_FROM=
export GO_EMAIL_TO=
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment