diff --git a/.elasticbeanstalk/config.yml b/.elasticbeanstalk/config.yml new file mode 100644 index 0000000000000000000000000000000000000000..cd558c9735f25e36cd220c7eea685b88c92b1996 --- /dev/null +++ b/.elasticbeanstalk/config.yml @@ -0,0 +1,12 @@ +branch-defaults: + $GIT_BRANCH: + environment: $EB_ENV +global: + application_name: $EB_APP + default_ec2_keyname: EastCoastBPKey + default_platform: 64bit Amazon Linux 2015.09 v2.0.8 running Docker 1.9.1 + default_region: us-east-1 + profile: null + sc: git +deploy: + artifact: deployment.zip diff --git a/.env.default b/.env.default new file mode 100644 index 0000000000000000000000000000000000000000..c6fe427a7cc62b79731d861895690d98250d3f57 --- /dev/null +++ b/.env.default @@ -0,0 +1,9 @@ +SECRET_KEY=$SECRET_KEY +DEBUG=$DEBUG +ALLOWED_HOSTS=$ALLOWED_HOSTS +STATIC_URL='/static/' +DB_NAME=$DB_NAME +DB_USER=$DB_USER +DB_PASSWORD=$DB_PASSWORD +DB_HOST=$DB_HOST +DB_PORT=$DB_PORT diff --git a/.gitignore b/.gitignore index 8310350f1b71b65fdaaf5a8b6d2d92a7ed48bf28..cf67637c987c0f4db080e390399788aacd64506a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ node_modules # misc .idea + +# static files +static + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d8d1b6b4511eae316d3a9e6b0b93179717526a6f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,78 @@ +# Dockerfile + +# FROM directive instructing base image to build upon +FROM ubuntu:16.10 + +ENV CODEROOT=/home/docker/code + +# Log enironment variables. +ENV NGINXERR=/var/log/nginx.err.log +ENV NGINXREQ=/var/log/nginx.req.log +ENV UWSGIERR=/var/log/uwsgi.err.log +ENV UWSGIREQ=/var/log/uwsgi.req.log + +# Custom environment variables. These change from project to project. +ARG DOMAIN +ENV DOMAIN=${DOMAIN} +ARG NUM_PROCESSES +ENV NUM_PROCESSES=${NUM_PROCESSES} +ARG NUM_THREADS +ENV NUM_THREADS=${NUM_THREADS} + +# Add the nginx reposoitory. We need 1.8 in order to support adding CORS headers to error responses. +RUN apt-get update +RUN apt-get install -y --no-install-recommends software-properties-common +RUN add-apt-repository ppa:nginx/stable + +# Install dependencies. +RUN apt-get update +RUN apt-get install -y --no-install-recommends python3 python3-software-properties python3-dev python3-setuptools python3-pip +RUN apt-get install -y --no-install-recommends nginx supervisor +RUN apt-get install -y --no-install-recommends build-essential git +RUN apt-get install -y --no-install-recommends libpq-dev +RUN apt-get install -y libpcre3 libpcre3-dev +RUN pip3 install uwsgi -I +RUN rm -rf /var/lib/apt/lists/* + +COPY ./requirements.txt $CODEROOT/requirements.txt + +# Install application requirements. +RUN pip3 install -r $CODEROOT/requirements.txt + +# Put the code somewhere. +ADD . $CODEROOT/ + +# Create the www user. +RUN useradd -ms /bin/bash www + +# Create the log files. +RUN \ + touch $NGINXERR && touch $NGINXREQ && \ + touch $UWSGIERR && touch $UWSGIREQ + +RUN \ + replace_vars() { \ + echo "Copying environment variables from $1 to $2."; \ + sed -e "s/\$DOMAIN/$DOMAIN/g" \ + -e "s@\$CODEROOT@$CODEROOT@g" \ + -e "s@\$NUM_PROCESSES@$NUM_PROCESSES@g" \ + -e "s@\$NUM_THREADS@$NUM_THREADS@g" \ + -e "s@\$NGINXERR@$NGINXERR@g" \ + -e "s@\$NGINXREQ@$NGINXREQ@g" \ + -e "s@\$UWSGIERR@$UWSGIERR@g" \ + -e "s@\$UWSGIREQ@$UWSGIREQ@g" $1 > $2; \ + }; \ + replace_vars $CODEROOT/config/nginx.conf /etc/nginx/nginx.conf && \ + replace_vars $CODEROOT/config/supervisor.conf /etc/supervisor/conf.d/supervisor.conf && \ + replace_vars $CODEROOT/config/uwsgi.ini $CODEROOT/uwsgi.ini + +# Make migrations +RUN cd $CODEROOT && python3 manage.py migrate --noinput + +# Collect static files +RUN cd $CODEROOT && python3 manage.py collectstatic --noinput + +# EXPOSE port 80 to allow communication to/from server +EXPOSE 80 + +CMD ["supervisord", "-n"] diff --git a/Dockerrun.aws.json b/Dockerrun.aws.json new file mode 100644 index 0000000000000000000000000000000000000000..d334d795f3e285cefe8e903ea2479d5cdad07ab5 --- /dev/null +++ b/Dockerrun.aws.json @@ -0,0 +1,16 @@ +{ + "AWSEBDockerrunVersion": "1", + "Authentication": { + "Bucket": "dockerauth.blocpower.org", + "Key": "$DOCKER_REPO.json" + }, + "Image": { + "Name": "blocp/$DOCKER_REPO" + }, + "Ports": [ + { + "HostPort": "80", + "ContainerPort": "80" + } + ] +} diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..cdf6e0e33b0e337ba219eb10dbaea1ec786bce26 --- /dev/null +++ b/config/nginx.conf @@ -0,0 +1,34 @@ +daemon off; +user www; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + gzip on; + charset utf-8; + client_max_body_size 10M; + + access_log $NGINXREQ; + error_log $NGINXERR; + + server { + listen 80; + listen [::]:80; + server_name $DOMAIN; + + location / { + include uwsgi_params; + uwsgi_pass unix:$CODEROOT/uwsgi.sock; + } + location /static/ { + autoindex on; + root $CODEROOT; + } + } +} diff --git a/config/supervisor.conf b/config/supervisor.conf new file mode 100644 index 0000000000000000000000000000000000000000..477f24b2c5f97b6cbcedb1ad3830bb0630b0bb2d --- /dev/null +++ b/config/supervisor.conf @@ -0,0 +1,5 @@ +[program:uwsgi] +command = /usr/local/bin/uwsgi --ini $CODEROOT/uwsgi.ini -O 2 + +[program:nginx] +command = /usr/sbin/nginx diff --git a/config/uwsgi.ini b/config/uwsgi.ini new file mode 100644 index 0000000000000000000000000000000000000000..e42dab433b21237d481ce7c45cb0f1747ecfb737 --- /dev/null +++ b/config/uwsgi.ini @@ -0,0 +1,22 @@ +[uwsgi] +# This is used if no configuration is specified. +ini = :base + +socket = $CODEROOT/uwsgi.sock +# Nginx should be able to find this socket. +chmod-socket = 666 + +master = true +# Number of processes and workers should be determined at build time +# Should be based on the type of instance that it is running on +processes = $NUM_PROCESSES +threads = $NUM_THREADS + +# Set loggers. +req-logger = file:$UWSGIREQ +logger = file:$UWSGIERR + +[base] +# cd into the app directory +chdir = $CODEROOT/ +module = lms.wsgi:application diff --git a/env.default b/env.default deleted file mode 100644 index f898f9e28bf51d755888e4458ffb7909c12af646..0000000000000000000000000000000000000000 --- a/env.default +++ /dev/null @@ -1,9 +0,0 @@ -SECRET_KEY= -DEBUG=True -ALLOWED_HOSTS=127.0.0.1,localhost -STATIC_URL='/static/' -DB_NAME=lms -DB_USER= -DB_PASSWORD= -DB_HOST=localhost -DB_PORT=5432 diff --git a/lms/settings.py b/lms/settings.py index 44ad0f4a1e41d6648d31ea20938950156218ad9d..98f7fa7acaffac8c5d434bd767f7a73ee3ea62b6 100644 --- a/lms/settings.py +++ b/lms/settings.py @@ -123,7 +123,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.10/howto/static-files/ STATIC_URL = config('STATIC_URL') -STATICFILES_DIRS = [ - os.path.join(BASE_DIR, 'lms/static'), -] -STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') +# STATICFILES_DIRS = [ +# os.path.join(BASE_DIR, 'lms/static'), +# ] +STATIC_ROOT = os.path.join(BASE_DIR, 'static')