Unverified Commit 292f43c3 authored by David Haynes's avatar David Haynes 🙆
Browse files

feat: Docker support for mysql



- Docker now will use a mysql image
- base.py now loads mysql as the default database
with configuration env vars
- Also remove postgres remnants
Signed-off-by: David Haynes's avatarDavid Haynes <dhaynes3@gmu.edu>
parent 8d64c384
Pipeline #1209 failed with stage
in 20 seconds
...@@ -2,72 +2,16 @@ ...@@ -2,72 +2,16 @@
# Dockerfile to build What's Open Django App # Dockerfile to build What's Open Django App
############################################################ ############################################################
# Instructions:
#
# Note: You need to edit the empty string on the line that
# says "ENV SECRET_KEY" to be a secure random value.
#
# Any initialized data that needs to be imported should be
# placed in a directory called "fixtures" in the context
# of the build.
# (https://docs.djangoproject.com/en/dev/howto/initial-data/)
#
# Build Command: sudo docker build -t whats_open .
# Run Command: sudo docker run -p 8000:80 -i -t -d whats_open
#
# (You'll need to reverse proxy port 8000 via nginx)
# Set the base image to Ubuntu # Set the base image to Ubuntu
FROM python:3.6 FROM python:3.6
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
# File Author / Maintainer
# MAINTAINER Student-Run Computing and Technology - GMU
# Update the sources list # Update the sources list
RUN apt-get update RUN apt-get update
RUN apt-get install netcat -y
RUN mkdir /whats_open RUN mkdir /whats_open
WORKDIR /whats_open WORKDIR /whats_open
ADD /requirements/ /whats_open/ ADD /requirements/ /whats_open/
RUN pip install -r base.txt RUN pip install -r base.txt
ADD . /whats_open/ ADD . /whats_open/
# Install basic applications
# RUN apt-get install -y tar git curl nano wget dialog net-tools build-essential
# # Install Python and Basic Python Tools
# RUN apt-get install -y python python-dev python-distribute python-pip
# # Clone down SRCT-Web
# RUN git clone https://github.com/srct/whats-open.git whats-open
# # Get pip to download and install requirements:
# RUN pip install -r /whats-open/requirements.txt
# # Set this to a unique, secure value before building
# # (http://www.miniwebtool.com/django-secret-key-generator/)
# ENV SECRET_KEY ""
# # Set the default directory where CMD will execute
# WORKDIR /whats-open/whats_open
# # Setup database
# RUN python manage.py syncdb --noinput
# RUN python manage.py migrate website --noinput
# # Generate static files in the STATIC_ROOT location
# # (https://docs.djangoproject.com/en/dev/howto/static-files/deployment/)
# RUN python manage.py collectstatic --noinput
# # Add any inital data fixtures
# # (https://docs.djangoproject.com/en/dev/howto/initial-data/)
# ADD fixtures /whats-open/whats_open/
# # Import the loaded fixtures
# RUN python manage.py loaddata users schedules
# # Expose ports
# EXPOSE 80
# # Use Gunicorn to server the application
# CMD gunicorn whats_open.wsgi:application -b 0.0.0.0:80
version: '2' version: '2'
services: services:
web: wopen_web:
build: . build: .
restart: always restart: always
ports: ports:
- '8000:8000' - '8000:8000'
command: /bin/bash ./startup.sh -python whats_open/manage.py runserver 0.0.0.0:8000 command: /bin/bash ./startup.sh
volumes: volumes:
- .:/whats_open - .:/whats_open
environment: depends_on:
- superuser=admin - wopen_db
- email_domain=@masonlive.gmu.edu environment:
\ No newline at end of file - WOPEN_EMAIL_DOMAIN=@masonlive.gmu.edu
- WOPEN_DB_NAME=wopen
- WOPEN_DB_USER=wopen
- WOPEN_DB_PASSWORD=wopen
- WOPEN_DB_HOST=wopen_db
- WOPEN_DB_PORT=3306
- WOPEN_SUPERUSER=admin
wopen_db:
image: mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_DATABASE: wopen
MYSQL_USER: wopen
MYSQL_PASSWORD: wopen
\ No newline at end of file
...@@ -2,4 +2,5 @@ Django>1.10, <1.11 ...@@ -2,4 +2,5 @@ Django>1.10, <1.11
django-autoslug==1.9.3 django-autoslug==1.9.3
django-cas-client==1.2.0 django-cas-client==1.2.0
djangorestframework==3.6.2 djangorestframework==3.6.2
django-model-utils==2.6.1 django-model-utils==2.6.1
\ No newline at end of file mysqlclient==1.3.10
\ No newline at end of file
until nc -z wopen_db 3306; do
echo "waiting for database to start..."
sleep 1
done
export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
python whats_open/manage.py flush --no-input python whats_open/manage.py flush --no-input
python whats_open/manage.py makemigrations python whats_open/manage.py makemigrations
python whats_open/manage.py makemigrations website python whats_open/manage.py makemigrations website
python whats_open/manage.py migrate python whats_open/manage.py migrate
echo "from django.contrib.auth.models import User; User.objects.filter(email='$superuser$email_domain').delete(); User.objects.create_superuser('$superuser$email_domain', '$superuser', 'admin')" | python whats_open/manage.py shell echo "from django.contrib.auth.models import User; User.objects.filter(email='$WOPEN_SUPERUSER$WOPEN_EMAIL_DOMAIN').delete(); User.objects.create_superuser('$WOPEN_SUPERUSER$WOPEN_EMAIL_DOMAIN', '$WOPEN_SUPERUSER', 'admin')" | python whats_open/manage.py shell
python whats_open/manage.py runserver 0.0.0.0:8000 python whats_open/manage.py runserver 0.0.0.0:8000
...@@ -31,22 +31,6 @@ ADMINS = ( ...@@ -31,22 +31,6 @@ ADMINS = (
MANAGERS = ADMINS MANAGERS = ADMINS
########## END MANAGER CONFIGURATION ########## END MANAGER CONFIGURATION
########## DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': normpath(join(DJANGO_ROOT, 'database/database.db')),
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
########## END DATABASE CONFIGURATION
########## GENERAL CONFIGURATION ########## GENERAL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone # See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
...@@ -140,6 +124,19 @@ FIXTURE_DIRS = ( ...@@ -140,6 +124,19 @@ FIXTURE_DIRS = (
) )
########## END FIXTURE CONFIGURATION ########## END FIXTURE CONFIGURATION
########## DATABASE CONFIGURATION
# Use the same DB everywhere.
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ['WOPEN_DB_NAME'],
'USER': os.environ['WOPEN_DB_USER'],
'PASSWORD': os.environ['WOPEN_DB_PASSWORD'],
'HOST': os.environ['WOPEN_DB_HOST'],
'PORT': os.environ['WOPEN_DB_PORT'],
}
}
########## TEMPLATE CONFIGURATION ########## TEMPLATE CONFIGURATION
TEMPLATES = [ TEMPLATES = [
......
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