-
-
Save RuubixO/1e5308748dc2eb0e5997b76c32203bf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data/nginx/app.conf | |
upstream app { | |
server app:8000; | |
} | |
server { | |
listen 80; | |
server_name localhost; # your-domain.com; | |
# uncomment this next block if you want only HTTPS connections | |
# this will require more work, though, as you'll need | |
# valid SSL certificates | |
# location / { | |
# return 301 https://$host$request_uri; | |
# } | |
location / { | |
proxy_pass http://app; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data/postgres/database_env | |
POSTGRES_USER=database_role | |
POSTGRES_PASSWORD=database_password | |
POSTGRES_DB=project_database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
nginx: # nginx is a web server, we use this for static assets and redirects | |
image: nginx:1.15-alpine | |
ports: | |
- "80:80" # this will actually make your site available on `localhost` with no port | |
- "443:443" # only used for HTTPS | |
volumes: | |
- ./data/nginx:/etc/nginx/conf.d | |
command: '/bin/sh -c ''while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"''' | |
networks: | |
- frontend | |
depends_on: | |
- app # make sure the app container is started | |
database: | |
image: postgres:10 | |
ports: | |
- "5432:5432" # you likely don't need this if you don't use a local postgres gui | |
volumes: | |
- pg_data:/var/lib/postgresql/data | |
- pg_backups:/pg_backups | |
env_file: | |
- data/postgres/database_env # this sets up passwords and such | |
networks: | |
- backend # so django can talk to the database | |
app: # this is our Django app | |
build: . # our Dockerfile is in the current dir and should be used to create this container | |
restart: always | |
ports: | |
- "8000:8000" # expose runserver's port | |
depends_on: | |
- database # gotta have a database | |
networks: | |
- frontend # so nginx can talk to django | |
- backend # so django can talk to the database | |
volumes: | |
- ./app:/opt/app # put our local "app" directory into the container at /opt/app | |
manage: # this is just for convenience | |
build: . | |
command: shell # run the `shell` management command by default | |
entrypoint: /usr/local/bin/python3 /opt/app/manage.py # append the command to this path | |
networks: | |
- backend # so django can talk to the database | |
volumes: | |
- ./app:/opt/app # we need the same code available as `app`, so put it in the same place | |
depends_on: | |
- database # needs the database to be able to run migrations and such | |
volumes: | |
pg_data: {} | |
pg_backups: {} | |
networks: | |
frontend: | |
driver: bridge | |
backend: | |
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.7 | |
RUN apt-get update && \ | |
apt-get install -y && \ | |
pip3 install uwsgi | |
COPY ./app /opt/app | |
RUN python -m pip install --upgrade pip | |
RUN pip3 install -r /opt/app/requirements.txt | |
ENV DJANGO_ENV=prod | |
ENV PYTHONUNBUFFERED 1 | |
EXPOSE 8000 | |
CMD ["uwsgi", "--ini", "/opt/app/uwsgi.ini"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[uwsgi] | |
http-socket = :8000 | |
chdir = /opt/app | |
module = app.wsgi | |
master = 1 | |
processes = 2 | |
threads = 2 | |
py-autoreload = 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment