Verified Commit a3592b73 authored by David Haynes's avatar David Haynes 🙆
Browse files

Migrate back to docker-compose for local dev

- clean and rename the startup script
parent 6520581f
# Go # Go 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)]() [![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)]()
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 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 use URL branding service for institutions that wish to widely disseminate
without unnecessarily outsourcing branding. information without unnecessarily outsourcing branding.
Go is currently a `Python 3` (with backwards compatability for `Python 2.7` until Go is currently a `Python 3` (with backwards compatability for `Python 2.7`
Django 2.0 in December 2017) project written in the `Django` web framework, with until Django 2.0 in December 2017) project written in the `Django` web
`MySQL` as our backend database. 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 Go currently supports developers on Linux, macOS and Windows platforms through
the Docker container platform. 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
of steps we will take: as well. Here's our walk-through of steps we will take:
1. Install `git` on your system. 1. Install `git` on your system.
1. Clone the Go codebase. 1. Clone the Go codebase.
1. Get Go up and running with the method of your choice. 1. Get Go up and running with the method of your choice.
### 1) Install `git` on your system ### 1) Install `git` on your system
...@@ -34,7 +37,8 @@ Open a terminal and run the following command: ...@@ -34,7 +37,8 @@ Open a terminal and run the following command:
sudo apt update sudo apt update
This retrieves links to the most up-to-date and secure versions of your packages. This retrieves links to the most up-to-date and secure versions of your
packages.
Next, with: Next, with:
...@@ -66,18 +70,19 @@ Finally we can install git with: ...@@ -66,18 +70,19 @@ Finally we can install git with:
#### On Windows #### On Windows
We recommend that if you are on Windows 10 AE (Anniversary Edition) or above to make use of the We recommend that if you are on Windows 10 AE (Anniversary Edition) or above to
Windows Subsystem for Linux (WSL). The following link should get you up and running: 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) [https://msdn.microsoft.com/en-us/commandline/wsl/install_guide](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide)
#### Contributing with Windows #### Contributing with Windows
After that is setup, you should be able to follow the Linux instructions for _manual setup_ to After that is setup, you should be able to follow the Linux instructions for
contribute to the project. _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 If you are not on Windows 10 or would rather prefer to not use the WSL you may
Windows here: download Git for Windows here:
[https://git-scm.com/download/win](https://git-scm.com/download/win) [https://git-scm.com/download/win](https://git-scm.com/download/win)
...@@ -86,14 +91,15 @@ Hyper-V which is only available on "Professional" versions of Windows. ...@@ -86,14 +91,15 @@ 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), Now, we're going to clone down a copy of the Go codebase from
the SRCT code respository with SSH. [git.gmu.edu](https://git.gmu.edu/srct/go), the SRCT code respository with SSH.
**a)** Configure your ssh keys by following the directions at: **a)** Configure your ssh keys by following the directions at:
[git.gmu.edu/help/ssh/README](https://git.gmu.edu/help/ssh/README). [git.gmu.edu/help/ssh/README](https://git.gmu.edu/help/ssh/README).
**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 **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
git clone git@git.gmu.edu:srct/go.git git clone git@git.gmu.edu:srct/go.git
...@@ -108,45 +114,47 @@ and get to working on setting up a development environment! ...@@ -108,45 +114,47 @@ and get to working on setting up a development environment!
#### Docker #### Docker
Docker is an emerging containerization platform written in Google's Go Docker is an emerging containerization platform written in Google's Go
language. language. Instead of running a full VM that runs Go, we package up all the
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
various bits that make up Go and run that as a container (two for Go and the other for mysql) that act as normal processes to the OS.
containers: one for Go and the other for mysql) that act as normal
processes to the OS.
Check out [docker.com](https://www.docker.com/what-docker) for more details. Check out [docker.com](https://www.docker.com/what-docker) for more details.
Pros: Pros:
- Lightweight * Lightweight
- Can be run on most machines without needing significant resources. * Can be run on most machines without needing significant resources.
- SRCT members report minimal battery impact on laptops. * SRCT members report minimal battery impact on laptops.
- Fast * Fast
- Compared to other methods, Docker is comparatively faster to setup than manual setup. * Compared to other methods, Docker is comparatively faster to setup than
- Minimal setup manual setup.
- You run one command. Really easy to get up and running once you install Docker. * Minimal setup
- Good cross platform support * You run one command. Really easy to get up and running once you install
- Runs smoothly on macOS, Linux, and Windows Docker.
- Great docs to help if you get stuck. * Good cross platform support
- Can easily destroy and rebuild the docker images * Runs smoothly on macOS, Linux, and Windows
- Loads in changes to code on the fly * Great docs to help if you get stuck.
* Can easily destroy and rebuild the docker images
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). * 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).
#### Manual Setup #### Manual Setup
Manual setup (or: the old fashioned way) is where you install all dependecies on Manual setup (or: the old fashioned way) is where you install all dependecies
your system and run Go as a local server with Django. Granted you are technically on your system and run Go as a local server with Django. Granted you are
doing that with Docker except it automates the steps that are laid out in this section. technically doing that with Docker except it automates the steps that are laid
out in this section.
Pros: Pros:
- Experience setting up a Django project for local development * Experience setting up a Django project for local development
Cons: Cons:
- Greater potential for things to go wrong * Greater potential for things to go wrong
- Way more steps * Way more steps
Head to: Head to:
...@@ -157,10 +165,10 @@ https://git.gmu.edu/srct/go/wikis/manual-setup ...@@ -157,10 +165,10 @@ https://git.gmu.edu/srct/go/wikis/manual-setup
### Testing ### Testing
You are _very strongly_ encouraged to write test cases where applicible for 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 code that you contribute to the repo. This is not a rule at the moment but
a strong suggestion. It's good practice for corporate land and will also ensure rather a strong suggestion. It's good practice for corporate land and will also
your code works. Additionally, there are quite a few example ones to look at in ensure your code works. Additionally, there are quite a few example ones to
the repo and on Google. look at in the repo and on Google.
### Running Unit Tests ### Running Unit Tests
...@@ -185,29 +193,33 @@ opinions about using `git`. ...@@ -185,29 +193,33 @@ opinions about using `git`.
### Opening issues ### Opening issues
There is a template for issue descriptions located on the new issue page. I will There is a template for issue descriptions located on the new issue page. I
close issues with poor descriptions or who do not follow the standard. 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 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 utilize a test server. You can log in with just your CAS username to simulate
in. By default, the Django superuser is set to `dhaynes3`. logging in. By default, the Django superuser is set to `dhaynes3`.
In order to approve yourself to be an 'approved user' you must navigate to 127.0.0.1:8000/admin and log in. In order to approve yourself to be an 'approved user' you must navigate to
Once in the admin page go to "registered users", and create a new registered user in the top right. Be sure to 127.0.0.1:8000/admin and log in. Once in the admin page go to "registered
use the same username and Full Name as your main account and select "approved" in the bottom row. 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. Consistency is key! PEP8 guidelines You should adhere to the style of the repo code. Consistency is key! PEP8
are strongly recommended but not enforced at the time. Please comment your code, guidelines are strongly recommended but not enforced at the time. Please
I will not accept commits that contain undocumented code. 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) I encourage you to join the
if you have any questions on setup or would like to contribute. [#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.
...@@ -217,9 +229,8 @@ https://git.gmu.edu/srct/go/wikis/administration-guide ...@@ -217,9 +229,8 @@ https://git.gmu.edu/srct/go/wikis/administration-guide
In order to expire links, you need to set up a cron job to run the manage.py 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 expirelinks command regularly. A sample cron script is available in the
repository and is named go-cleanlinks.cron. Drop this in cron.hourly and repository and is named go-cleanlinks.cron. Drop this in cron.hourly and change
change the paths so that they point to the virtualenv activate script and the paths so that they point to the virtualenv activate script and manage.py.
manage.py.
## Production cron job ## Production cron job
...@@ -232,8 +243,3 @@ MANAGE_PATH=/path/to/go/manage.py ...@@ -232,8 +243,3 @@ MANAGE_PATH=/path/to/go/manage.py
source ${ACTIVATE_PATH} source ${ACTIVATE_PATH}
python ${MANAGE_PATH} expirelinks python ${MANAGE_PATH} expirelinks
``` ```
---
**Note:**
Link by Viktor Vorobyev from the Noun Project.
version: "3" version: "3"
services: services:
db: db:
image: mysql image: mysql
deploy:
replicas: 1
restart_policy:
condition: on-failure
networks:
- go
ports: ports:
- "3306:3306" - "3306:3306"
environment: environment:
...@@ -18,15 +13,9 @@ services: ...@@ -18,15 +13,9 @@ services:
web: web:
image: go_web image: go_web
deploy:
replicas: 1
restart_policy:
condition: on-failure
networks:
- go
ports: ports:
- '8000:8000' - '8000:8000'
command: ./startup.sh command: ./docker-startup.sh
volumes: volumes:
- .:/go - .:/go
depends_on: depends_on:
...@@ -47,6 +36,3 @@ services: ...@@ -47,6 +36,3 @@ services:
- GO_EMAIL_FROM= - GO_EMAIL_FROM=
- GO_EMAIL_TO= - GO_EMAIL_TO=
- SUPERUSER=dhaynes3 - SUPERUSER=dhaynes3
networks:
go:
#! /bin/bash #! /bin/bash
until nc -z db 3306; do
echo "waiting for database to start..."
sleep 1
done
export GO_SECRET_KEY export GO_SECRET_KEY
export GO_CREATE_SUPERUSER
GO_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null) GO_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
GO_CREATE_SUPERUSER="from django.contrib.auth import get_user_model; User = get_user_model(); me = User.objects.get(username='$SUPERUSER'); me.first_name = 'David'; me.last_name = 'Haynes'; me.save(); "
python go/manage.py makemigrations python go/manage.py makemigrations
python go/manage.py makemigrations go python go/manage.py makemigrations go
python go/manage.py migrate python go/manage.py migrate
python go/manage.py createsuperuser --noinput --username=$SUPERUSER --email=$SUPERUSER$GO_EMAIL_DOMAIN python go/manage.py createsuperuser --noinput --username="$SUPERUSER" --email="$SUPERUSER$GO_EMAIL_DOMAIN"
echo "from django.contrib.auth import get_user_model; User = get_user_model(); me = User.objects.get(username='$SUPERUSER'); me.first_name = 'David'; me.last_name = 'Haynes'; me.save(); " | python go/manage.py shell echo "$GO_CREATE_SUPERUSER" | python go/manage.py shell
python go/manage.py runserver 0.0.0.0:8000 python go/manage.py runserver 0.0.0.0:8000
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