Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.66 KB | None | 0 0
  1. # Dockerfile
  2.  
  3. #!/bin/bash
  4.  
  5. FROM python:3.6-alpine
  6. ENV PYTHONDONTWRITEBYTECODE 1
  7. ENV PYTHONUNBUFFERED 1
  8. RUN mkdir /usr/src/app
  9. WORKDIR /usr/src/app
  10. RUN apk update \
  11.     && apk add --virtual build-deps gcc python3-dev musl-dev libc-dev \
  12.     && apk add postgresql-dev \
  13.     && pip install psycopg2 \
  14.     && apk del build-deps
  15. RUN pip install --upgrade pip
  16. RUN pip install pipenv
  17. COPY ./Pipfile /usr/src/app
  18. RUN pipenv install --skip-lock --system --dev
  19. COPY ./entrypoint.sh /usr/src/app
  20. RUN chmod +x /usr/src/app/entrypoint.sh
  21. COPY . /usr/src/app
  22. ENTRYPOINT [ "/usr/src/app/entrypoint.sh" ]
  23.  
  24. # **** docker-compose.yml *******
  25.  
  26. version: '3'
  27. services:
  28.   web:
  29.     build: .
  30.     command: python manage.py runserver 0.0.0.0:8000
  31.     volumes:
  32.       - .:/code
  33.       - static_volume:/code/staticfiles
  34.     expose:
  35.       - 8000
  36.     environment:
  37.       - SQL_ENGINE=django.db.backends.postgresql
  38.       - SQL_DATABASE=postgres
  39.       - SQL_USER=postgres
  40.       - SQL_PASSWORD=postgres
  41.       - SQL_HOST=db
  42.       - SQL_PORT=5432
  43.       - DATABASE=postgres
  44.     depends_on:
  45.       - db
  46.   db:
  47.     image: postgres:10.5-alpine
  48.   nginx:
  49.     build: ./nginx
  50.     volumes:
  51.       - static_volume:/usr/src/app/staticfiles
  52.     ports:
  53.       - 1337:80
  54.     depends_on:
  55.       - web
  56.  
  57. volumes:
  58.     static_volume:
  59.  
  60.  
  61. # ********** entrypoint.sh **********
  62.  
  63. #!/bin/sh
  64. if [ "$DATABASE" = "postgres" ]
  65. then
  66.     echo "Esperando por postgres..."
  67.     while ! nc -z $SQL_HOST $SQL_PORT; do
  68.         sleep 0.1
  69.     done
  70.  
  71.     echo "PostgreSQL started"
  72. fi
  73.  
  74. python manage.py flush --noinput
  75. python manage.py makemigrations
  76. python manage.py migrate
  77. python manage.py collectstatic --noinput
  78.  
  79. exec "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement