Verified Commit 9ba9ca02 authored by David Haynes's avatar David Haynes 🙆

Merge branch '2.3-dev' into secret-refactor

parents 4867e7bf aaaaa9ef
go/settings/settings.py
go/settings/secret.py
docker-compose.yml
**/*.pyc
Dockerfile
Vagrantfile
.dockerignore
\ No newline at end of file
......@@ -17,6 +17,7 @@ before_script:
- cd go/
- export GO_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
- export GO_DB_NAME="go"
- export GO_ENV="production"
- export GO_DB_USER="root"
- export GO_DB_PASSWORD="root"
- export GO_DB_HOST="mysql"
......@@ -35,12 +36,6 @@ before_script:
- python manage.py migrate
- echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('root', 'root@srct.gmu.edu', 'root') " | python manage.py shell
Go-py2.7:
image: library/python:2.7
stage: test
script:
- python manage.py test
Go-py3.4:
image: library/python:3.4
stage: test
......@@ -53,17 +48,16 @@ Go-py3.5:
script:
- python manage.py test
#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
# - 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;}'
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
- 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;}'
Go-flake8:
image: library/python:3.5
stage: lint
script:
- pip install flake8
- flake8 go/ --statistics --exit-zero
\ No newline at end of file
- flake8 go/ --statistics --exit-zero
......@@ -5,7 +5,7 @@ about the current issue. Maybe a picture? Some details that could best help some
especially someone new, understand the goal of the issue and how they should best
approach the problem.
# Helpful Links
## Helpful Links
Here you should include a bullet point list of links to documentation, stack overflow,
whatever, that could help guide someone on what it is they are trying to do.
......
......@@ -17,15 +17,16 @@ add, modify, or remove features/bugs from Go. Our list of tasks can be found on
the issues page.
If you decide to take on an issue for Go you will need to work in a branch off
of the current development branch (ie. `2.2-dev` with 2.2 being the version in
development).
of the current development branch (ie. `2.3-dev` with 2.3 being the version in
development).
This can be done with the following chain of `git` commands within `go/`:
git pull
git checkout 2.2-dev
git checkout -B ##-shortdescription
```sh
git pull
git checkout 2.3-dev
git checkout -B ##-shortdescription
```
**Note:**
......@@ -35,9 +36,11 @@ does.
**Example:**
git pull
git checkout 2.2-dev
git checkout -B 102-readmeUpdates
```sh
git pull
git checkout 2.3-dev
git checkout -B 102-readmeUpdates
```
If you are working on something that does not have an issue please open a new
issue before creating your branch.
......
# Build on top of the python image and install any external packages
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN apt-get update
RUN apt-get install netcat -y
RUN mkdir /go
WORKDIR /go
ADD /requirements/ /go/
RUN pip install -r base.txt
# Set enviornment variables
ENV PYTHONUNBUFFERED 1
# Copy over all project files into /go/
RUN mkdir /go/
WORKDIR /go/
ADD . /go/
# Install pip dependecies
RUN pip install -r /go/requirements/dev.txt
Copyright 2017 George Mason Student-Run Computing and Technology
Copyright 2018 George Mason Student-Run Computing and Technology
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......
......@@ -2,32 +2,31 @@
[![build status](https://git.gmu.edu/srct/go/badges/master/build.svg)](https://git.gmu.edu/srct/go/commits/master) [![coverage report](https://git.gmu.edu/srct/go/badges/master/coverage.svg)](https://git.gmu.edu/srct/go/commits/master) [![python version](https://img.shields.io/badge/python-2.7,3.4+-blue.svg)]() [![Django version](https://img.shields.io/badge/Django-1.11-brightgreen.svg)]() [![SemVer version](https://img.shields.io/badge/SemVer Version-2.2.3-yellowgreen.svg)]()
#### A project of [GMU SRCT](https://srct.gmu.edu).
A project of [GMU SRCT](https://srct.gmu.edu).
Go is a drop-in URL shortening service. This project aims to provide an easy to use
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
## 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.
2. Clone the Go codebase.
3. Get Go up and running with the method of your choice.
1. Clone the Go codebase.
1. Get Go up and running with the method of your choice.
## 1) Install `git` on your system.
### 1) Install `git` on your system
`git` is the version control system used for SRCT projects.
### On Linux Based Systems
#### On Linux Based Systems
**with apt:**
......@@ -43,7 +42,7 @@ Next, with:
you install `git` onto your system.
### On macOS
#### On macOS
We recommend that you use the third party Homebrew package manager for macOS,
which allows you to install packages from your terminal just as easily as you
......@@ -65,14 +64,13 @@ Finally we can install git with:
brew install git
### On Windows
#### On Windows
We recommend that if you are on Windows 10 AE (Anniversary Edition) or above to make use of the
Windows Subsystem for Linux (WSL). The following link should get you up and running:
[https://msdn.microsoft.com/en-us/commandline/wsl/install_guide](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide)
#### Contributing with Windows
After that is setup, you should be able to follow the Linux instructions for _manual setup_ to
......@@ -83,13 +81,10 @@ 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.
### 2) Clone the Go codebase
Now, we're going to clone down a copy of the Go codebase from [git.gmu.edu](https://git.gmu.edu/srct/go),
the SRCT code respository with SSH.
......@@ -102,7 +97,7 @@ the SRCT code respository with SSH.
git clone git@git.gmu.edu:srct/go.git
## 3) Get Go up and running with the method of your choice.
### 3) Get Go up and running with the method of your choice
Now that we have `git` setup and cloned down the code you can
......@@ -110,94 +105,56 @@ Now that we have `git` setup and cloned down the code you can
and get to working on setting up a development environment!
### Docker
#### Docker
Docker is an emerging containerization platform written in Google's Go
language.
Instead of running a full VM that runs Go, we package up all the
various bits that make up Go and run that as a container (two
containers: one for Go and the other for mysql) that act as normal
processes to the OS.
processes to the OS.
Check out [docker.com](https://www.docker.com/what-docker) for more details.
Pros:
- Lightweight
- Can be run on most machines without needing significant resources.
- Lightweight
- 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.
- Minimal setup
- You run one command. Really easy to get up and running once you install
Docker.
- Good cross platform support
- Runs smoothly on macOS, Linux, and Windows
- Great docs to help if you get stuck.
- Can easily destroy and rebuild the docker images
- Loads in changes to code on the fly
Cons:
- Challenging to debug problems
- Cannot interact with attached images and as a result, you cannot really
interact with the database.
- Fast
- 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.
- Good cross platform support
- Runs smoothly on macOS, Linux, and Windows
- Great docs to help if you get stuck.
- Can easily destroy and rebuild the docker images
- Loads in changes to code on the fly
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
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
- Experience setting up a Django project for local development
Cons:
- Greater potential for things to go wrong
- Way more steps
- Greater potential for things to go wrong
- Way more steps
Head to:
https://git.gmu.edu/srct/go/wikis/manual-setup
## Some words about contributing to Go
# Some words about contributing to Go.
## Testing
### Testing
You are _very strongly_ encouraged to write test cases where applicible for
code that you contribute to the repo. This is not a rule at the moment but rather
......@@ -210,38 +167,28 @@ the repo and on Google.
Unit tests are run on every commit sent to gitlab though that can be a pain to
rely on. Here's how to run them locally:
#### Docker
### Docker
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
### Manual Setup
Assuming you are within your virtualenv:
python manage.py test
## CONTRIBUTING.md
### CONTRIBUTING.md
This document goes into detail about how to contribute to the repo, plus some
opinions about using `git`.
## Opening issues
### Opening issues
There is a template for issue descriptions located on the new issue page. I will
close issues with poor descriptions or who do not follow the standard.
## Authentication
### Authentication
The authentication service used for Go is CAS. In local development however we
utilize a test server. You can log in with just your CAS username to simulate logging
......@@ -251,18 +198,18 @@ In order to approve yourself to be an 'approved user' you must navigate to 127.0
Once in the admin page go to "registered users", and create a new registered user in the top right. Be sure to
use the same username and Full Name as your main account and select "approved" in the bottom row.
## Coding style
### Coding style
You should adhere to the style of the repo code. Consistancy is key! PEP8 guidelines
are strongly reccomended but not enforced at the time. Please comment your code,
I will not accept commits that contain uncommented code.
You should adhere to the style of the repo code. Consistency is key! PEP8 guidelines
are strongly recommended but not enforced at the time. Please comment your code,
I will not accept commits that contain undocumented code.
## Getting Help
### Getting Help
I encourage you to join the [#go channel](https://srct.slack.com/messages/go/details/) in SRCT's [Slack Group](https://srct.slack.com)
if you have any questions on setup or would like to contribute.
# Some words about deploying Go.
## Some words about deploying Go.
Check out our admin guide:
......@@ -274,6 +221,18 @@ repository and is named go-cleanlinks.cron. Drop this in cron.hourly and
change the paths so that they point to the virtualenv activate script and
manage.py.
## Production cron job
```sh
#!/bin/bash
# Cron job to automatically expire outdated links, put this in cron.hourly
ACTIVATE_PATH=/path/to/virtualenv/activate
MANAGE_PATH=/path/to/go/manage.py
source ${ACTIVATE_PATH}
python ${MANAGE_PATH} expirelinks
```
---
**Note:**
......
# -*- 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
version: '2'
version: "3"
services:
db:
image: mysql
deploy:
replicas: 1
restart_policy:
condition: on-failure
networks:
- go
ports:
- "3306:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_DATABASE: go
MYSQL_USER: go
MYSQL_PASSWORD: go
web:
build: .
restart: always
image: go_web
deploy:
replicas: 1
restart_policy:
condition: on-failure
networks:
- go
ports:
- '8000:8000'
command: /bin/bash ./startup.sh -python go/manage.py runserver 0.0.0.0:8000
command: ./startup.sh
volumes:
- .:/go
depends_on:
- db
environment:
- GO_ENV=dev
- GO_ALLOWED_HOSTS=*
- GO_EMAIL_DOMAIN=@masonlive.gmu.edu
- GO_CAS_URL=https://cas.srct.gmu.edu/
- GO_DB_NAME=go
- GO_DB_USER=go
- GO_DB_PASSWORD=go
......@@ -25,12 +46,7 @@ services:
- GO_EMAIL_HOST_PASSWORD=
- GO_EMAIL_FROM=
- GO_EMAIL_TO=
- superuser=dhaynes3
- SUPERUSER=dhaynes3
db:
image: mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_DATABASE: go
MYSQL_USER: go
MYSQL_PASSWORD: go
networks:
go:
#!/bin/bash
# Cron job to automatically expire outdated links, put this in cron.hourly
ACTIVATE_PATH=/path/to/virtualenv/activate
MANAGE_PATH=/path/to/go/manage.py
source ${ACTIVATE_PATH}
python ${MANAGE_PATH} expirelinks