From d6e5ed066d7d9756071f8876d6c12bc4ac5f6b2c Mon Sep 17 00:00:00 2001 From: winkidney Date: Sun, 19 Aug 2018 03:15:39 -0700 Subject: [PATCH 1/7] Feature: Use docker-compose example file instead of compose-file --- .gitignore | 3 +++ Dockerfile | 5 ----- docker-compose.example.yml | 18 ++++++++++++++++++ docker-compose.yml | 19 ------------------- start_docker_with_current_user.sh | 2 ++ 5 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 docker-compose.example.yml delete mode 100644 docker-compose.yml create mode 100755 start_docker_with_current_user.sh diff --git a/.gitignore b/.gitignore index 30add79..a9e1c0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Ignore docker-compose +docker-compose.yml + # Virtualenv/Common /bin/ /build/ diff --git a/Dockerfile b/Dockerfile index 71c2187..84f11d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/docker-compose.example.yml b/docker-compose.example.yml new file mode 100644 index 0000000..b1d2be7 --- /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 --log-file - " + 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/start_docker_with_current_user.sh b/start_docker_with_current_user.sh new file mode 100755 index 0000000..90dbfe5 --- /dev/null +++ b/start_docker_with_current_user.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +CURRENT_UID=$(id -u):$(id -g) sudo docker-compose up ${@} From 08fc46e66707bd04ce65d92b6f2b8a215a9ea5c1 Mon Sep 17 00:00:00 2001 From: winkidney Date: Sun, 19 Aug 2018 03:55:45 -0700 Subject: [PATCH 2/7] Fix: Fix non-effect env --- start_docker_with_current_user.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/start_docker_with_current_user.sh b/start_docker_with_current_user.sh index 90dbfe5..8b15770 100755 --- a/start_docker_with_current_user.sh +++ b/start_docker_with_current_user.sh @@ -1,2 +1,3 @@ #!/usr/bin/env bash -CURRENT_UID=$(id -u):$(id -g) sudo docker-compose up ${@} +_CURRENT_UID=$(id -u):$(id -g) +sudo CURRENT_UID=${_CURRENT_UID} docker-compose up ${@} From 8df82fb7c34eb31b74879cb8e5979e2d33668f6e Mon Sep 17 00:00:00 2001 From: winkidney Date: Sun, 19 Aug 2018 04:24:28 -0700 Subject: [PATCH 3/7] Refactor: Use stdout as the log-output --- docker-compose.example.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.example.yml b/docker-compose.example.yml index b1d2be7..8a65d1f 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -7,7 +7,7 @@ services: command: > bash -c "python manage.py migrate && python3 manage.py collectstatic --noinput - && gunicorn pinry.wsgi:application -b 0.0.0.0:8000 --timeout 30 --log-file - " + && gunicorn pinry.wsgi:application -b 0.0.0.0:8000 --timeout 30" ports: - "127.0.0.1:2048:8000" environment: From 2278d6a5529fc27571d2e8bd0c5dbf8b8007556b Mon Sep 17 00:00:00 2001 From: winkidney Date: Sun, 19 Aug 2018 04:33:14 -0700 Subject: [PATCH 4/7] Feature: Support local_settings as optional settings --- pinry/settings/development.py | 5 +++++ pinry/settings/docker.py | 5 +++++ 2 files changed, 10 insertions(+) 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 From 8187d90ef957e0df5c2d5143b783a1c2393ba141 Mon Sep 17 00:00:00 2001 From: winkidney Date: Sun, 19 Aug 2018 04:35:22 -0700 Subject: [PATCH 5/7] Feature: Ignore local_settings.py --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a9e1c0d..930a153 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ -# Ignore docker-compose +# local_settings +local_settings.py + +# Ignore docker-compose docker-compose.yml # Virtualenv/Common From d06aa6cb139f652ca164fc329013a08471943317 Mon Sep 17 00:00:00 2001 From: winkidney Date: Mon, 27 Aug 2018 01:00:23 -0700 Subject: [PATCH 6/7] Fix: python3 will install python 3.7 and cause a syntax error --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 84f11d8..58e7ac2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3 +FROM python:3.6 ENV PYTHONUNBUFFERED 1 WORKDIR /app From 491040e6e43a0d8d8d1ef3564b8dd8d9e26da09c Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 30 Aug 2018 15:35:46 +0800 Subject: [PATCH 7/7] Doc: Add description about local_settings support and docker-changes --- README.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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