diff --git a/.gitignore b/.gitignore index 30add79..930a153 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +# local_settings +local_settings.py + +# Ignore docker-compose +docker-compose.yml + # Virtualenv/Common /bin/ /build/ diff --git a/Dockerfile b/Dockerfile index 71c2187..58e7ac2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3 +FROM python:3.6 ENV PYTHONUNBUFFERED 1 WORKDIR /app @@ -6,8 +6,3 @@ COPY . /app RUN pip install pipenv RUN pipenv install --three --system - -RUN python3 manage.py collectstatic --noinput - -VOLUME /app/static/media - diff --git a/README.rst b/README.rst index c1e7f0c..540750d 100644 --- a/README.rst +++ b/README.rst @@ -49,15 +49,27 @@ Follow the steps below to install Pinry locally or on any server. This process installs the minimal requirements to run Pinry. For development requirements and procedures, see testing above. +Current docker configuration will just mount source code directory to +docker app directory and run any codes existed in current git branch, +you may also add "local_settings.py" to customize settings without +changing settings file in `pinry/settings`. + - Install the requirements: - Docker - Docker Compose - Set any custom configuration options you need and run:: + cp docker-compose.example.yml docker-compose.yml + # edit docker-compose.yml and change the secret-key, + # don't forget to backup this config file. docker-compose up -d -- Bootstrap the database:: +- If you want to run Pinry with current user in docker:: + + ./start_docker_with_current_user.sh [-d] + +- Bootstrap the database(optional):: docker-compose exec web python3 manage.py migrate --settings=pinry.settings.docker diff --git a/docker-compose.example.yml b/docker-compose.example.yml new file mode 100644 index 0000000..8a65d1f --- /dev/null +++ b/docker-compose.example.yml @@ -0,0 +1,18 @@ +version: '3' + +services: + web: + build: . + working_dir: /app + command: > + bash -c "python manage.py migrate + && python3 manage.py collectstatic --noinput + && gunicorn pinry.wsgi:application -b 0.0.0.0:8000 --timeout 30" + ports: + - "127.0.0.1:2048:8000" + environment: + - SECRET_KEY=CHANGE-ME + user: ${CURRENT_UID} + volumes: + - .:/app + restart: always diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index c7a7b27..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,19 +0,0 @@ -version: '3' - -services: - db: - image: postgres - web: - build: . - command: gunicorn pinry.wsgi:application -b 0.0.0.0:80 --timeout 30 --log-file - - ports: - - "80:80" - depends_on: - - db - environment: - - SECRET_KEY=CHANGE-ME - volumes: - - media:/app/static/media - -volumes: - media: diff --git a/pinry/settings/development.py b/pinry/settings/development.py index 38d7606..d029112 100644 --- a/pinry/settings/development.py +++ b/pinry/settings/development.py @@ -19,3 +19,8 @@ DATABASES = { 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } + +try: + from .local_settings import * +except ImportError: + pass diff --git a/pinry/settings/docker.py b/pinry/settings/docker.py index 0aff23c..54e56a1 100644 --- a/pinry/settings/docker.py +++ b/pinry/settings/docker.py @@ -22,3 +22,8 @@ DATABASES = { 'PORT': 5432, } } + +try: + from .local_settings import * +except ImportError: + pass diff --git a/start_docker_with_current_user.sh b/start_docker_with_current_user.sh new file mode 100755 index 0000000..8b15770 --- /dev/null +++ b/start_docker_with_current_user.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +_CURRENT_UID=$(id -u):$(id -g) +sudo CURRENT_UID=${_CURRENT_UID} docker-compose up ${@}