Skip to content

Commit

Permalink
Merge pull request #7 from ronnyrules/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
pratyush-pankaj authored Oct 10, 2020
2 parents 07c7ec5 + 0989ff0 commit 8f84e36
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@ RUN apk add --update --no-cache --virtual .tmp-build-deps \
ENV PYTHONUNBUFFERED 1
RUN export PYTHONPATH="$PYTHONPATH:/app"

ENV PATH="/scripts:${PATH}"

COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt

RUN mkdir /app
WORKDIR /app
COPY ./app /app
COPY ./scripts /scripts

RUN chmod +x /scripts/*

RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/

RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user

CMD ["entrypoint.sh"]

EXPOSE 8000
13 changes: 10 additions & 3 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')
SECRET_KEY = os.environ.get('SECRET_KEY', 'changeme')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = bool(int(os.environ.get('DEBUG', 0)))

ALLOWED_HOSTS = []
ALLOWED_HOSTS_ENV = os.environ.get('ALLOWED_HOSTS')
if ALLOWED_HOSTS_ENV:
ALLOWED_HOSTS.extend(ALLOWED_HOSTS_ENV.split(','))


# Application definition
Expand Down Expand Up @@ -122,4 +125,8 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = '/static/static/'
MEDIA_URL = '/static/media/'

STATIC_ROOT = '/vol/web/static'
MEDIA_ROOT = '/vol/web/media'
47 changes: 47 additions & 0 deletions docker-compose-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: "3"

services:
app:
build:
context: .
volumes:
- static_data:/vol/web
env_file:
- .env
environment:
- SECRET_KEY=samplesecretkey123
- ALLOWED_HOSTS=127.0.0.1,localhost

proxy:
build:
context: ./proxy
volumes:
- static_data:/vol/static
ports:
- "9090:9090"
depends_on:
- app

db:
image: mysql:latest
ports:
- '${SQL_PORT}:3306'
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}

phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '${PHPMYADMIN_PORT}:80'
environment:
PMA_HOST: db

volumes:
static_data:
11 changes: 11 additions & 0 deletions proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nginxinc/nginx-unprivileged:1-alpine

COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./uwsgi_params /etc/nginx/uwsgi_params

USER root

RUN mkdir -p /vol/static
RUN chmod 755 /vol/static

USER nginx
12 changes: 12 additions & 0 deletions proxy/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
server {
listen 9090;

location /static {
alias /vol/static;
}

location / {
uwsgi_pass app:8000;
include /etc/nginx/uwsgi_params;
}
}
13 changes: 13 additions & 0 deletions proxy/uwsgi_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_ADDR $server_addr;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Django>=3.0.8,<3.1.0
# mysql-connector-python>=8.0.21,<8.1.0
# MySQL-python
mysqlclient

uWSGI>=2.0.18,<2.1
7 changes: 7 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -e

python manage.py collectstatic --noinput

uwsgi --socket :8000 --master --enable-threads --module app.wsgi

0 comments on commit 8f84e36

Please sign in to comment.