README.md 8.14 KB
Newer Older
David Haynes's avatar
David Haynes committed
1
# Go
Jean Michel Rouly's avatar
Jean Michel Rouly committed
2

David Haynes's avatar
David Haynes committed
3
[![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)]()
Jean Michel Rouly's avatar
Jean Michel Rouly committed
4

5
A project of [GMU SRCT](https://srct.gmu.edu).
6

David Haynes's avatar
David Haynes committed
7 8 9
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.
David Haynes's avatar
David Haynes committed
10

David Haynes's avatar
David Haynes committed
11
Go is currently a `Python 3` (with backwards compatability for `Python 2.7` until
David Haynes's avatar
David Haynes committed
12
Django 2.0 in December 2017) project written in the `Django` web framework, with
David Haynes's avatar
David Haynes committed
13
`MySQL` as our backend database.
14

15
## Setup instructions for local development
16

David Haynes's avatar
David Haynes committed
17
Go currently supports developers on Linux, macOS and Windows platforms through
David Haynes's avatar
David Haynes committed
18
the Docker container platform. We have included instructions for manual setup as well. Here's our walk-through
David Haynes's avatar
David Haynes committed
19
of steps we will take:
20

David Haynes's avatar
David Haynes committed
21
1. Install `git` on your system.
22 23
1. Clone the Go codebase.
1. Get Go up and running with the method of your choice.
Zosman's avatar
Zosman committed
24

25
### 1) Install `git` on your system
Zosman's avatar
Zosman committed
26

David Haynes's avatar
David Haynes committed
27
`git` is the version control system used for SRCT projects.
Zosman's avatar
Zosman committed
28

29
#### On Linux Based Systems
Zosman's avatar
Zosman committed
30

David Haynes's avatar
David Haynes committed
31 32
**with apt:**

David Haynes's avatar
David Haynes committed
33
Open a terminal and run the following command:
mdsecurity's avatar
mdsecurity committed
34

David Haynes's avatar
David Haynes committed
35
    sudo apt update
Robert Hitt's avatar
Robert Hitt committed
36

David Haynes's avatar
David Haynes committed
37
This retrieves links to the most up-to-date and secure versions of your packages.
Robert Hitt's avatar
Robert Hitt committed
38

David Haynes's avatar
David Haynes committed
39
Next, with:
40

David Haynes's avatar
David Haynes committed
41
    sudo apt install git
David Haynes's avatar
David Haynes committed
42

David Haynes's avatar
David Haynes committed
43
you install `git` onto your system.
44

45
#### On macOS
Zosman's avatar
Zosman committed
46

David Haynes's avatar
David Haynes committed
47 48 49 50
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
could on a Linux based system. You could use another package manager (or not
use one at all), but Homebrew is highly reccomended.
51

David Haynes's avatar
David Haynes committed
52
To get homebrew, run the following command in a terminal:
David Haynes's avatar
David Haynes committed
53

David Haynes's avatar
David Haynes committed
54
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)
55

David Haynes's avatar
David Haynes committed
56 57
**Note**: You do NOT need to use `sudo` when running any Homebrew commands, and
it likely won't work if you do.
David Haynes's avatar
David Haynes committed
58

David Haynes's avatar
David Haynes committed
59
Next, to make sure Homebrew is up to date, run:
60

David Haynes's avatar
David Haynes committed
61
    brew update
Zosman's avatar
Zosman committed
62

David Haynes's avatar
David Haynes committed
63 64 65
Finally we can install git with:

    brew install git
Zosman's avatar
Zosman committed
66

67
#### On Windows
David Haynes's avatar
David Haynes committed
68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
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
contribute to the project. 

If you are not on Windows 10 or would rather prefer to not use the WSL you may download Git for
Windows here:

[https://git-scm.com/download/win](https://git-scm.com/download/win)

David Haynes's avatar
David Haynes committed
84
I have successfully ran the project with Docker, though you need access to
David Haynes's avatar
David Haynes committed
85
Hyper-V which is only available on "Professional" versions of Windows.
Zosman's avatar
Zosman committed
86

87
### 2) Clone the Go codebase
David Haynes's avatar
David Haynes committed
88

89
Now, we're going to clone down a copy of the Go codebase from [git.gmu.edu](https://git.gmu.edu/srct/go),
David Haynes's avatar
David Haynes committed
90 91 92
the SRCT code respository with SSH.

**a)** Configure your ssh keys by following the directions at:
93

94
[git.gmu.edu/help/ssh/README](https://git.gmu.edu/help/ssh/README).
David Haynes's avatar
David Haynes committed
95

David Haynes's avatar
David Haynes committed
96
**b)** Now, on your computer, navigate to the directory in which you want to download the project (ie. perhaps one called `development/SRCT`), and run
David Haynes's avatar
David Haynes committed
97

David Haynes's avatar
David Haynes committed
98
    git clone git@git.gmu.edu:srct/go.git
David Haynes's avatar
David Haynes committed
99

100
### 3) Get Go up and running with the method of your choice
101

David Haynes's avatar
David Haynes committed
102 103 104 105 106 107
Now that we have `git` setup and cloned down the code you can

    cd go/

and get to working on setting up a development environment!

108
#### Docker
David Haynes's avatar
David Haynes committed
109

David Haynes's avatar
David Haynes committed
110 111 112 113 114
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
David Haynes's avatar
David Haynes committed
115
processes to the OS.
David Haynes's avatar
David Haynes committed
116

David Haynes's avatar
David Haynes committed
117 118
Check out [docker.com](https://www.docker.com/what-docker) for more details.

David Haynes's avatar
David Haynes committed
119 120
Pros:

121 122
- Lightweight
  - Can be run on most machines without needing significant resources.
David Haynes's avatar
David Haynes committed
123
    - SRCT members report minimal battery impact on laptops.
124 125 126 127 128 129 130 131 132
- 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
David Haynes's avatar
David Haynes committed
133 134

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).
David Haynes's avatar
David Haynes committed
135

136
#### Manual Setup
David Haynes's avatar
David Haynes committed
137

David Haynes's avatar
David Haynes committed
138 139
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
David Haynes's avatar
David Haynes committed
140
doing that with Docker except it automates the steps that are laid out in this section.
David Haynes's avatar
David Haynes committed
141 142

Pros:
143 144

- Experience setting up a Django project for local development
David Haynes's avatar
David Haynes committed
145 146

Cons:
147 148 149

- Greater potential for things to go wrong
- Way more steps
David Haynes's avatar
David Haynes committed
150

David Haynes's avatar
David Haynes committed
151 152 153 154
Head to:

https://git.gmu.edu/srct/go/wikis/manual-setup

155
## Some words about contributing to Go
David Haynes's avatar
David Haynes committed
156

157
### Testing
158 159 160 161 162 163 164 165 166 167 168 169

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
a strong suggestion. It's good practice for corporate land and will also ensure
your code works. Additionally, there are quite a few example ones to look at in
the repo and on Google.

### Running Unit Tests

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:

170
### Docker
171 172 173 174

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.

175
### Manual Setup
176 177 178 179 180

Assuming you are within your virtualenv:

    python manage.py test

181
### CONTRIBUTING.md
David Haynes's avatar
David Haynes committed
182

183 184 185
This document goes into detail about how to contribute to the repo, plus some
opinions about using `git`.

186
### Opening issues
187 188 189 190

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.

191
### Authentication
David Haynes's avatar
David Haynes committed
192 193 194 195 196

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
in. By default, the Django superuser is set to `dhaynes3`.

197 198 199 200
In order to approve yourself to be an 'approved user' you must navigate to 127.0.0.1:8000/admin and log in.
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.

201
### Coding style
202

David Haynes's avatar
David Haynes committed
203 204 205
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.
206

207
### Getting Help
David Haynes's avatar
David Haynes committed
208

David Haynes's avatar
David Haynes committed
209 210
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.
David Haynes's avatar
David Haynes committed
211

212
## Some words about deploying Go.
David Haynes's avatar
David Haynes committed
213

214 215 216
Check out our admin guide:

https://git.gmu.edu/srct/go/wikis/administration-guide
217 218 219 220 221 222

In order to expire links, you need to set up a cron job to run the manage.py
expirelinks command regularly. A sample cron script is available in the
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.
David Haynes's avatar
David Haynes committed
223

David Haynes's avatar
David Haynes committed
224 225 226 227 228 229 230 231 232 233 234 235
## 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
```

David Haynes's avatar
David Haynes committed
236 237
---
**Note:**
David Haynes's avatar
David Haynes committed
238

239
Link by Viktor Vorobyev from the Noun Project.