Browse Source

Базовые файлы для запуска Docker

develop
Golikov Ivan 4 years ago
parent
commit
a5db00e46f
7 changed files with 103 additions and 5 deletions
  1. +2
    -0
      .gitignore
  2. +5
    -5
      cross_journals/settings-dev.py
  3. +17
    -0
      docker/.env.dist
  4. +20
    -0
      docker/Makefile
  5. +47
    -0
      docker/docker-compose.yml
  6. +9
    -0
      docker/python/dev/Dockerfile
  7. +3
    -0
      docker/source/Dockerfile

+ 2
- 0
.gitignore View File

@@ -1,2 +1,4 @@
__pycache__/
cross_journals.sublime-workspace
.env


+ 5
- 5
cross_journals/settings-dev.py View File

@@ -15,7 +15,7 @@ import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = os.environ['DJANGO_CJ_SECRET_KEY']
SECRET_KEY = os.environ['SECRET_KEY']
DEBUG = True

ALLOWED_HOSTS = []
@@ -79,10 +79,10 @@ WSGI_APPLICATION = 'cross_journals.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['DJANGO_CJ_DB'],
'USER': os.environ['DJANGO_CJ_DB_USER'],
'PASSWORD': os.environ['DJANGO_CJ_DB_PASS'],
'HOST': os.environ['DJANGO_CJ_DB_HOST'],
'NAME': os.environ['DB_NAME'],
'USER': os.environ['DB_USER'],
'PASSWORD': os.environ['DB_PASS'],
'HOST': os.environ['DB_HOST'],
}
}



+ 17
- 0
docker/.env.dist View File

@@ -0,0 +1,17 @@
# Copy this file and rename to ".env"
# docker-compose use file ".env" in docker-compose.yml
# Docs here: https://docs.docker.com/compose/environment-variables/#/the-env-file
VIRTUAL_HOST_PORT=8000
VIRTUAL_HOST_STAGE_PORT=8001
VIRTUAL_HOST_LIVESERVER_PORT=8020-8030
VIRTUAL_HOST_EXPOSE_PORT=8000

DEPS_DIR=/usr/app/deps
SRC_DIR=/usr/app/src

DB_USER=postgres
DB_PASS=pass
DB_NAME=cr_db

DJANGO_SETTINGS_MODULE=cross_journals.settings-dev
SECRET_KEY=very-very-very-very-very-very-very-looong-secret-key

+ 20
- 0
docker/Makefile View File

@@ -0,0 +1,20 @@
dc=docker-compose

migrate:
$(dc) exec cr-python python manage.py migrate

build:
$(dc) build cr-python
$(dc) build

dev: build
$(dc) up -d cr-postgres
sleep 5
$(dc) up -d cr-python
sleep 5
$(dc) exec cr-python python manage.py migrate

restore:
mkdir -p /opt/database/cross_register/
cp ../cross_register_db.dump /opt/database/cross_register/
$(dc) exec cr-postgres pg_restore -cv -d cr_db -O -h localhost -U postgres /var/lib/postgresql/data/cross_register_db.dump

+ 47
- 0
docker/docker-compose.yml View File

@@ -0,0 +1,47 @@
version: '2'

services:

cr-source:
image: busybox
container_name: cr-source
volumes:
- ./../:$SRC_DIR

cr-python:
build:
context: ..
dockerfile: docker/python/dev/Dockerfile
image: ivnglkv/cr-python
container_name: cr-python
environment:
- DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
- DB_HOST=cr-postgres
- DB_NAME=$DB_NAME
- DB_USER=$DB_USER
- DB_PASS=$DB_PASS
- SECRET_KEY=$SECRET_KEY
depends_on:
- cr-postgres
networks:
- cr-backend
ports:
- '$VIRTUAL_HOST_EXPOSE_PORT:$VIRTUAL_HOST_PORT'
volumes_from:
- cr-source
command: python manage.py runserver 0.0.0.0:$VIRTUAL_HOST_PORT

cr-postgres:
image: postgres:9.6
restart: always
container_name: cr-postgres
environment:
POSTGRES_DB: $DB_NAME
POSTGRES_PASSWORD: $DB_PASS
networks:
- cr-backend
volumes:
- /opt/database/cross_register:/var/lib/postgresql/data

networks:
cr-backend:

+ 9
- 0
docker/python/dev/Dockerfile View File

@@ -0,0 +1,9 @@
FROM python:slim

RUN apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y build-essential

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

WORKDIR /usr/app/src/

+ 3
- 0
docker/source/Dockerfile View File

@@ -0,0 +1,3 @@
FROM busybox:latest

COPY . /usr/app/src/

Loading…
Cancel
Save