Skip to content

Commit

Permalink
Merge pull request #5 from samcrane8/master
Browse files Browse the repository at this point in the history
Pull from fork
  • Loading branch information
Tonewall committed Aug 30, 2019
2 parents acd611f + 0ca7615 commit 65c32b0
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 110 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ push_backend.sh
push_all.sh
*.env
.idea/
env/
env/
.vscode/
*.crt
*.key
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

16 changes: 0 additions & 16 deletions business-logic-server/create_superuser.py

This file was deleted.

2 changes: 2 additions & 0 deletions business-logic-server/entrypoint.prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ then
echo "PostgreSQL started"
fi

cd business-logic-server

exec "$@"
2 changes: 1 addition & 1 deletion business-logic-server/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fi
cd business-logic-server && python3.7 manage.py makemigrations icarus_backend
python3.7 manage.py migrate
echo "MIGRATED"
python3.7 create_superuser.py
python3.7 setup_user_and_department.py

exec "$@"
4 changes: 2 additions & 2 deletions business-logic-server/icarus_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
SECRET_KEY = 'zcr39#y7%e9a$r+n=72uw6@2k_o*fw-)so&fl&@_+1v0v+@in@'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG', 'enabled') == 'enabled'
DEBUG = os.environ.get('DJANGO_DEBUG', 'disabled') == 'enabled'

CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
Expand Down Expand Up @@ -175,7 +175,7 @@
AUTH_USER_MODEL = 'users.IcarusUser'

# REDIS related settings
REDIS_HOST = 'localhost'
REDIS_HOST = 'redis'
REDIS_PORT = '6379'
BROKER_URL = 'redis://' + REDIS_HOST + ':' + REDIS_PORT + '/0'
BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600}
Expand Down
43 changes: 26 additions & 17 deletions business-logic-server/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
# pull official base image
FROM python:3.6-alpine
FROM ubuntu:bionic

# set work directory
WORKDIR /usr/src/app

# set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DEBIAN_FRONTEND noninteractive

# install psycopg2
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add postgresql-dev \
&& pip install psycopg2 \
&& apk del build-deps
RUN apt-get update -qq && apt-get install -y -qq \
# std libs
unzip wget sudo less nano curl git gosu build-essential software-properties-common \
# python basic libs
python3.7 python3.7-dev gettext \
# geodjango
gdal-bin binutils libproj-dev libgdal-dev \
netcat \
# postgresql
libpq-dev postgresql-client && \
apt-get clean all && rm -rf /var/apt/lists/* && rm -rf /var/cache/apt/*

# install dependencies
RUN pip install --upgrade pip
RUN pip install pipenv
COPY ../Pipfile /usr/src/app/Pipfile
RUN pipenv install --skip-lock --system
# install pip
RUN wget https://bootstrap.pypa.io/get-pip.py && python3.7 get-pip.py && rm get-pip.py
RUN pip3 install --no-cache-dir setuptools wheel -U

ENV LANG=C.UTF-8

# copy entrypoint-prod.sh
COPY ./entrypoint.prod.sh /usr/src/app/entrypoint.prod.sh
# install dependencies
RUN pip3 install --upgrade pip
COPY requirements.txt /usr/src/app/requirements.txt
RUN pip3 install -r requirements.txt

# copy project
COPY .. /usr/src/app/
COPY . /usr/src/app/


# run entrypoint.prod.sh
ENTRYPOINT ["/usr/src/app/entrypoint.prod.sh"]
# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/business-logic-server/entrypoint.prod.sh"]
66 changes: 66 additions & 0 deletions business-logic-server/setup_user_and_department.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os
from icarus_backend.wsgi import *
from icarus_backend.pilot.PilotModel import Pilot
from users.models import IcarusUser as User
from oauth2_provider.models import Application
from icarus_backend.department.DepartmentModel import Department
from django.contrib.gis.geos import Polygon
from icarus_backend.drone.DroneModel import Drone


user = User.objects.filter(username=os.environ.get('SUPERUSER_USERNAME', 'admin')).first()
if not user:
user = User.objects.create_superuser(os.environ.get('SUPERUSER_USERNAME', 'admin'), os.environ.get('SUPERUSER_EMAIL', 'admin@password.com'), os.environ.get('SUPERUSER_PASSWORD', 'password'))

pilot = Pilot(
user=user,
remotePilotCertificateNumber='123',
mobilePhoneNumber='123-456-7890'
)
user.save()

airboss = User.objects.filter(id='1')

department = Department(
owner = user,
area = Polygon([
(33.781572902565564, -84.40757274627684),
(33.77668601962971, -84.40735816955566),
(33.774795398883406, -84.4064998626709),
(33.773118775767486, -84.4019079208374),
(33.77276204321162, -84.3975305557251),
(33.771477793711874, -84.39650058746338),
(33.77137077205131, -84.39229488372803),
(33.76844546156616, -84.39225196838379),
(33.7685168117906, -84.39066410064697),
(33.781572902565564, -84.39096450805664),
(33.781465893516334, -84.39478397369385),
(33.782892669846134, -84.3946123123169),
(33.783142353260104, -84.39701557159424),
(33.781572902565564, -84.39723014831543),
(33.781572902565564, -84.40757274627684)
]),
name = "Georgia Tech Police Department",
# airbosses = user
# create an airboss template
)
department.save()
department.airbosses.set(airboss)


drone = Drone(
id = "c0d59f57-ae0b-47ec-8ec6-a0434468d851",
owner = user,
description = "Test Drone Description",
name = "Test Drone",
manufacturer = "DJI",
type = "Rotor",
faa_registration_number = "123",
color = "White",
)

drone.save()
pilot.save()

application = Application(client_id='client_id', client_secret='client_secret', client_type='confidential', name='webapp', authorization_grant_type='password')
application.save()
30 changes: 22 additions & 8 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ services:
business-logic:
build:
context: business-logic-server
dockerfile: Dockerfile
command: python3.7 manage.py runserver 0.0.0.0:8000
dockerfile: prod.Dockerfile
command: gunicorn --bind 0.0.0.0:8000 icarus_backend.wsgi:application
environment:
- DJANGO_DEBUG=enabled
- DJANGO_DEBUG=disabled
- SQL_DATABASE=gis
- FLYRIGHT_BUILD=DEV
- SQL_HOST=db
Expand All @@ -29,7 +29,7 @@ services:
- SUPERUSER_USERNAME=admin
- SUPERUSER_PASSWORD=password
- SUPERUSER_EMAIL=admin@password.com
- SLACKBOT_ENABLED=disabled
- SLACKBOT_ENABLED=enabled
env_file: business-logic.env
volumes:
- .:/usr/src/app
Expand Down Expand Up @@ -58,15 +58,29 @@ services:
- 8080
nginx:
build: ./nginx
environment:
- WEBAPP_DOMAIN=flyright.police.gatech.edu
- API_DOMAIN=flyright-api.police.gatech.edu
ports:
- 80:80
- 443:443
depends_on:
- web
- business-logic
redis:
image: redis
container_name: cache
expose:
- 6379
ports:
- 6379:6379
celery-worker:
build:
context: business-logic-server
dockerfile: prod.Dockerfile
command: celery worker -A icarus_backend --loglevel=debug --concurrency=1
volumes:
- .:/usr/src/app
depends_on:
- redis
links:
- redis

volumes:
postgres_data:
4 changes: 3 additions & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM nginx:1.15.12-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
COPY nginx.conf /etc/nginx/nginx.conf

ENTRYPOINT ["entrypoint.sh"]
12 changes: 0 additions & 12 deletions nginx/flyright-nginx-site

This file was deleted.

49 changes: 0 additions & 49 deletions nginx/nginx.conf

This file was deleted.

0 comments on commit 65c32b0

Please sign in to comment.