From 2a2f65c43720a2a3233705cffb61c926b9eda1da Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 15:40:25 +0800 Subject: [PATCH 01/14] Feature: Move local_settings.py --- docker/docker-compose.example.yml | 16 ---------------- .../settings}/local_settings.example.py | 0 2 files changed, 16 deletions(-) delete mode 100644 docker/docker-compose.example.yml rename {docker/pinry => pinry/settings}/local_settings.example.py (100%) diff --git a/docker/docker-compose.example.yml b/docker/docker-compose.example.yml deleted file mode 100644 index 61abd05..0000000 --- a/docker/docker-compose.example.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: '3' - -services: - web: - build: . - command: > - bash -c "/scripts/start.sh" - ports: -# if you use "127.0.0.1", no one except you can visit it from within -# - "127.0.0.1:10000:8000" - - "80:80" - volumes: - # overwrite local_settings, you can always modify your local_settings file - - ./pinry/local_settings.py:/srv/www/pinry/pinry/settings/local_settings.py - - ./data/:/data/ - restart: always diff --git a/docker/pinry/local_settings.example.py b/pinry/settings/local_settings.example.py similarity index 100% rename from docker/pinry/local_settings.example.py rename to pinry/settings/local_settings.example.py From 77fca13edfc0b27dde3509bda31525c79b763d4f Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 16:10:14 +0800 Subject: [PATCH 02/14] Reafactor: Docker auto-build should be a out-of-the-box image without any extra config --- Dockerfile.autobuild | 33 +++++++------------ docker/bootstrap.sh | 51 ------------------------------ docker/nginx/sites-enabled/default | 10 ++---- docker/pinry/.gitignore | 2 -- docker/scripts/bootstrap.sh | 29 +++++++++++++++++ docker/scripts/gen_key.sh | 22 +++++++------ docker/scripts/start.sh | 8 ++--- 7 files changed, 59 insertions(+), 96 deletions(-) delete mode 100755 docker/bootstrap.sh delete mode 100644 docker/pinry/.gitignore create mode 100755 docker/scripts/bootstrap.sh diff --git a/Dockerfile.autobuild b/Dockerfile.autobuild index 625f867..1b35896 100644 --- a/Dockerfile.autobuild +++ b/Dockerfile.autobuild @@ -10,7 +10,6 @@ # Require: Docker (http://www.docker.io/) # ----------------------------------------------------------------------------- - # Base system is the LTS version of Ubuntu. FROM python:3.7-stretch @@ -20,28 +19,26 @@ RUN groupadd -g 2300 tmpgroup \ && groupadd -g 1000 www-data \ && usermod -g www-data www-data \ && usermod -u 1000 www-data \ - && groupdel tmpgroup \ -# - && mkdir -p /srv/www/pinry/logs \ -# - && mkdir /data \ - && chown -R www-data:www-data /data \ -# - && mkdir -p /var/log/gunicorn \ - && apt-get update \ + && groupdel tmpgroup + +RUN mkdir /data +RUN mkdir -p /data/logs +RUN chown -R www-data:www-data /data + +RUN apt-get update \ && apt-get -y install nginx nginx-extras pwgen \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && apt-get autoclean RUN pip --no-cache-dir install pipenv gunicorn mysqlclient psycopg2 cx-Oracle -COPY Pipfile* /srv/www/pinry/ +# COPY and start installation +COPY . /srv/www/pinry/ RUN cd /srv/www/pinry \ && pipenv install --three --system --clear -COPY . /srv/www/pinry/ - -# config nodejs and build frontend +# config nodejs RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n || exit RUN bash n 10 RUN npm -g install yarn @@ -49,12 +46,6 @@ RUN npm -g install yarn # build frontend RUN cd /srv/www/pinry/pinry-spa/ && yarn install && yarn build -# Fix permissions -RUN chown -R www-data:www-data /srv/www \ - && cd /srv/www/pinry \ - && python manage.py collectstatic --noinput --settings=pinry.settings.docker - - # Load in all of our config files. ADD docker/nginx/nginx.conf /etc/nginx/nginx.conf ADD docker/nginx/sites-enabled/default /etc/nginx/sites-enabled/default diff --git a/docker/bootstrap.sh b/docker/bootstrap.sh deleted file mode 100755 index 62d5c84..0000000 --- a/docker/bootstrap.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -script_dir="$( dirname "${0}" )" -# Force users to login before seeing any pins. -if [ "${ALLOW_NEW_REGISTRATIONS}" = "" ]; then - ALLOW_NEW_REGISTRATIONS=true -fi - -if [[ "$(docker images -q pinry/pinry 2> /dev/null)" == "" ]]; then - echo "No docker image found, building..." && "${script_dir}/build_docker.sh" -fi - -echo "==================================================================================" -echo "Note: Please copy this key and keep it in a secure place." -echo "Then you should manually edit your pinry/local_settings.py" -echo "and replace SECRET_KEY with new secret-key if you had previously generated a" -echo "pinry/local_settings.py." -echo "If no previous pinry/local_settings.py generated, you can have a look and edit it." -echo "If you want to use docker-compose, just edit docker-compose.yml and use 'docker-compose up'" - -SECRET_KEY=$(sudo docker run pinry/pinry /scripts/gen_key.sh) - -echo "" -echo "Your secret-key is(also saved/overwritten your docker's /data/production_secret_key.txt):" -echo "" -echo ${SECRET_KEY} -echo "==================================================================================" - -local_settings_file="${script_dir}/pinry/local_settings.py" -# Create local_settings.py -if [ ! -f "${local_settings_file}" ]; -then - cp "${script_dir}/pinry/local_settings.example.py" "${local_settings_file}" - sed -i "s/secret\_key\_place\_holder/${SECRET_KEY}/" "${local_settings_file}" - - # Force users to login before seeing any pins. - if [ "${PRIVATE}" = "true" ]; then - sed -i "s/PUBLIC = True/PUBLIC = False/" "${local_settings_file}" - fi - - # Enable people from creating new accounts. - if [ "${ALLOW_NEW_REGISTRATIONS}" = "true" ]; then - sed -i "s/ALLOW_NEW_REGISTRATIONS = False/ALLOW_NEW_REGISTRATIONS = True/" "${local_settings_file}" - fi -fi - -# Copy to docker-compose.yml -if [ ! -f "${script_dir}/docker-compose.yml" ]; -then - cp "${script_dir}/docker-compose.example.yml" "${script_dir}/docker-compose.yml" -fi diff --git a/docker/nginx/sites-enabled/default b/docker/nginx/sites-enabled/default index a098d16..904bcd6 100644 --- a/docker/nginx/sites-enabled/default +++ b/docker/nginx/sites-enabled/default @@ -2,14 +2,10 @@ server { listen 80 default; server_name _; - access_log /srv/www/pinry/logs/access.log; - error_log /srv/www/pinry/logs/error.log; + access_log /data/logs/access.log; + error_log /data/logs/error.log; - location /media { - alias /data/static/media; - expires max; - access_log off; - } + root /srv/www/pinry/pinry-spa/dist/; location /static { alias /data/static; diff --git a/docker/pinry/.gitignore b/docker/pinry/.gitignore deleted file mode 100644 index 49ce140..0000000 --- a/docker/pinry/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -local_settings.py -production_secret_key.txt \ No newline at end of file diff --git a/docker/scripts/bootstrap.sh b/docker/scripts/bootstrap.sh new file mode 100755 index 0000000..12302cc --- /dev/null +++ b/docker/scripts/bootstrap.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +gen_key() { + echo "==================================================================================" + echo "Note: Please copy this key and keep it in a secure place." + echo "Then you should manually edit your pinry/local_settings.py" + echo "and replace SECRET_KEY with new secret-key if you had previously generated a" + echo "pinry/local_settings.py." + echo "If no previous pinry/local_settings.py generated, you can have a look and edit it." + echo "If you want to use docker-compose, just edit docker-compose.yml and use 'docker-compose up'" + + SECRET_KEY=$(bash /scripts/gen_key.sh) + + echo "" + echo "Your secret-key is(also saved/overwritten your docker's /data/production_secret_key.txt):" + echo "" + echo ${SECRET_KEY} + echo "==================================================================================" +} + +local_settings_file="/data/local_settings.py" +# Create local_settings.py +if [ ! -f "${local_settings_file}" ]; +then + cp "/srv/www/pinry/settings/local_settings.example.py" "${local_settings_file}" + gen_key + sed -i "s/secret\_key\_place\_holder/${SECRET_KEY}/" "${local_settings_file}" + ln -s "${local_settings_file}" "/srv/www/pinry/settings/local_settings.py" +fi diff --git a/docker/scripts/gen_key.sh b/docker/scripts/gen_key.sh index ddc28e0..46392f7 100755 --- a/docker/scripts/gen_key.sh +++ b/docker/scripts/gen_key.sh @@ -1,13 +1,15 @@ #!/bin/bash -# Check for secret key if one doesn't exist create. -if [ ! -f /data/production_secret_key.txt ] -then - cd /data - PRODUCTION_SECRET_KEY=`pwgen -c -n -1 65` - echo $PRODUCTION_SECRET_KEY > /data/production_secret_key.txt -else - PRODUCTION_SECRET_KEY=`cat /data/production_secret_key.txt` -fi +gen_key() { + # Check for secret key if one doesn't exist create. + if [ ! -f /data/production_secret_key.txt ] + then + cd /data + PRODUCTION_SECRET_KEY=`pwgen -c -n -1 65` + echo $PRODUCTION_SECRET_KEY > /data/production_secret_key.txt + else + PRODUCTION_SECRET_KEY=`cat /data/production_secret_key.txt` + fi -echo ${PRODUCTION_SECRET_KEY} + echo ${PRODUCTION_SECRET_KEY} +} diff --git a/docker/scripts/start.sh b/docker/scripts/start.sh index 68251c9..c704668 100755 --- a/docker/scripts/start.sh +++ b/docker/scripts/start.sh @@ -9,13 +9,11 @@ # Updated: Aug 19th, 2014 # ----------------------------------------------------------------------------- +bash /scripts/bootstrap.sh # If static files don't exist collect them -if [ ! -d /data/static ] -then - cd /srv/www/pinry - python manage.py collectstatic --noinput -fi +cd /srv/www/pinry +python manage.py collectstatic --noinput # If database doesn't exist yet create it if [ ! -f /data/production.db ] From d9da2ee4f59935727a8940574f67dd56b30fc82e Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 19:51:28 +0800 Subject: [PATCH 03/14] Refactor: Use shortter path for project location --- Dockerfile.autobuild | 11 +++++------ docker/nginx/sites-enabled/default | 8 ++++---- docker/scripts/bootstrap.sh | 4 ++-- docker/scripts/start.sh | 9 +++++---- docker/start_docker.sh | 3 +-- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Dockerfile.autobuild b/Dockerfile.autobuild index 1b35896..3f32191 100644 --- a/Dockerfile.autobuild +++ b/Dockerfile.autobuild @@ -22,7 +22,6 @@ RUN groupadd -g 2300 tmpgroup \ && groupdel tmpgroup RUN mkdir /data -RUN mkdir -p /data/logs RUN chown -R www-data:www-data /data RUN apt-get update \ @@ -30,12 +29,13 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* \ && apt-get autoclean +# required for other database options RUN pip --no-cache-dir install pipenv gunicorn mysqlclient psycopg2 cx-Oracle # COPY and start installation -COPY . /srv/www/pinry/ +COPY . /pinry -RUN cd /srv/www/pinry \ +RUN cd /pinry \ && pipenv install --three --system --clear # config nodejs @@ -44,14 +44,13 @@ RUN bash n 10 RUN npm -g install yarn # build frontend -RUN cd /srv/www/pinry/pinry-spa/ && yarn install && yarn build +RUN cd /pinry/pinry-spa/ && yarn install && yarn build # Load in all of our config files. ADD docker/nginx/nginx.conf /etc/nginx/nginx.conf ADD docker/nginx/sites-enabled/default /etc/nginx/sites-enabled/default -ADD docker/scripts/* /scripts/ # 80 is for nginx web, /data contains static files and database /start runs it. EXPOSE 80 VOLUME ["/data"] -CMD ["/scripts/start.sh"] +CMD ["/pinry/docker/scripts/start.sh"] diff --git a/docker/nginx/sites-enabled/default b/docker/nginx/sites-enabled/default index 904bcd6..e3d287e 100644 --- a/docker/nginx/sites-enabled/default +++ b/docker/nginx/sites-enabled/default @@ -2,10 +2,10 @@ server { listen 80 default; server_name _; - access_log /data/logs/access.log; - error_log /data/logs/error.log; + access_log /data/nginx-access.log; + error_log /data/nginx-error.log; - root /srv/www/pinry/pinry-spa/dist/; + root /pinry/pinry-spa/dist/; location /static { alias /data/static; @@ -22,7 +22,7 @@ server { } location / { - root /srv/www/pinry/pinry-spa/dist/; + root /pinry/pinry-spa/dist/; access_log off; } } diff --git a/docker/scripts/bootstrap.sh b/docker/scripts/bootstrap.sh index 12302cc..5cadc49 100755 --- a/docker/scripts/bootstrap.sh +++ b/docker/scripts/bootstrap.sh @@ -22,8 +22,8 @@ local_settings_file="/data/local_settings.py" # Create local_settings.py if [ ! -f "${local_settings_file}" ]; then - cp "/srv/www/pinry/settings/local_settings.example.py" "${local_settings_file}" + cp "/pinry/pinry/settings/local_settings.example.py" "${local_settings_file}" gen_key sed -i "s/secret\_key\_place\_holder/${SECRET_KEY}/" "${local_settings_file}" - ln -s "${local_settings_file}" "/srv/www/pinry/settings/local_settings.py" + ln -s "${local_settings_file}" "/pinry/pinry/settings/local_settings.py" fi diff --git a/docker/scripts/start.sh b/docker/scripts/start.sh index c704668..cb1c727 100755 --- a/docker/scripts/start.sh +++ b/docker/scripts/start.sh @@ -8,17 +8,18 @@ # Authors: Isaac Bythewood # Updated: Aug 19th, 2014 # ----------------------------------------------------------------------------- +PROJECT_ROOT="/pinry" bash /scripts/bootstrap.sh # If static files don't exist collect them -cd /srv/www/pinry +cd ${PROJECT_ROOT} python manage.py collectstatic --noinput # If database doesn't exist yet create it if [ ! -f /data/production.db ] then - cd /srv/www/pinry + cd ${PROJECT_ROOT} python manage.py migrate --noinput --settings=pinry.settings.docker fi @@ -28,5 +29,5 @@ chown -R www-data:www-data /data # start all process /usr/sbin/nginx -cd /srv/www/pinry/ -/scripts/_start_gunicorn.sh +cd ${PROJECT_ROOT} +./docker/scripts/_start_gunicorn.sh diff --git a/docker/start_docker.sh b/docker/start_docker.sh index c6b1d93..8ed57d9 100755 --- a/docker/start_docker.sh +++ b/docker/start_docker.sh @@ -12,5 +12,4 @@ fi sudo docker run -d=true -p=80:80 \ -v=${DATA_PATH}:/data \ - -v=${SETTINGS_PATH}:/srv/www/pinry/pinry/settings/local_settings.py \ - pinry/pinry /scripts/start.sh + pinry/pinry From 1c9f74d27a1bbbd51f0c25a9dba58f9c66d15c4e Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 19:52:20 +0800 Subject: [PATCH 04/14] Fix: Should execute function in gen_key.sh --- docker/scripts/gen_key.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/scripts/gen_key.sh b/docker/scripts/gen_key.sh index 46392f7..515fcb3 100755 --- a/docker/scripts/gen_key.sh +++ b/docker/scripts/gen_key.sh @@ -13,3 +13,4 @@ gen_key() { echo ${PRODUCTION_SECRET_KEY} } +gen_key From a3ad1c6180607056a443e987c7906dca056d1181 Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 19:58:06 +0800 Subject: [PATCH 05/14] Fix: Fix path error in start.sh --- docker/scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/scripts/start.sh b/docker/scripts/start.sh index cb1c727..41e5565 100755 --- a/docker/scripts/start.sh +++ b/docker/scripts/start.sh @@ -10,7 +10,7 @@ # ----------------------------------------------------------------------------- PROJECT_ROOT="/pinry" -bash /scripts/bootstrap.sh +bash ${PROJECT_ROOT}/docker/scripts/bootstrap.sh # If static files don't exist collect them cd ${PROJECT_ROOT} From 8b3e834a7aa48548c81e649049e3d6e462460b22 Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 20:22:33 +0800 Subject: [PATCH 06/14] Fix: Add docker settings for collectstatic --- docker/scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/scripts/start.sh b/docker/scripts/start.sh index 41e5565..f3f05fc 100755 --- a/docker/scripts/start.sh +++ b/docker/scripts/start.sh @@ -14,7 +14,7 @@ bash ${PROJECT_ROOT}/docker/scripts/bootstrap.sh # If static files don't exist collect them cd ${PROJECT_ROOT} -python manage.py collectstatic --noinput +python manage.py collectstatic --noinput --settings=pinry.settings.docker # If database doesn't exist yet create it if [ ! -f /data/production.db ] From 6b5395dc393192956f107e2cd6b6db86f340f87b Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 20:31:36 +0800 Subject: [PATCH 07/14] Fix: Fix path error for secret-key-gen --- docker/scripts/bootstrap.sh | 2 +- docker/scripts/start.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/scripts/bootstrap.sh b/docker/scripts/bootstrap.sh index 5cadc49..0378acb 100755 --- a/docker/scripts/bootstrap.sh +++ b/docker/scripts/bootstrap.sh @@ -9,7 +9,7 @@ gen_key() { echo "If no previous pinry/local_settings.py generated, you can have a look and edit it." echo "If you want to use docker-compose, just edit docker-compose.yml and use 'docker-compose up'" - SECRET_KEY=$(bash /scripts/gen_key.sh) + SECRET_KEY=$(bash /pinry/docker/scripts/gen_key.sh) echo "" echo "Your secret-key is(also saved/overwritten your docker's /data/production_secret_key.txt):" diff --git a/docker/scripts/start.sh b/docker/scripts/start.sh index f3f05fc..fc04774 100755 --- a/docker/scripts/start.sh +++ b/docker/scripts/start.sh @@ -14,7 +14,7 @@ bash ${PROJECT_ROOT}/docker/scripts/bootstrap.sh # If static files don't exist collect them cd ${PROJECT_ROOT} -python manage.py collectstatic --noinput --settings=pinry.settings.docker +python manage.py collect --noinput --settings=pinry.settings.docker # If database doesn't exist yet create it if [ ! -f /data/production.db ] From e8211274bbf1f9195e67ec9412be399a73cbcfb8 Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 22:27:11 +0800 Subject: [PATCH 08/14] Fix: Fix collectstatic command --- docker/scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/scripts/start.sh b/docker/scripts/start.sh index fc04774..f3f05fc 100755 --- a/docker/scripts/start.sh +++ b/docker/scripts/start.sh @@ -14,7 +14,7 @@ bash ${PROJECT_ROOT}/docker/scripts/bootstrap.sh # If static files don't exist collect them cd ${PROJECT_ROOT} -python manage.py collect --noinput --settings=pinry.settings.docker +python manage.py collectstatic --noinput --settings=pinry.settings.docker # If database doesn't exist yet create it if [ ! -f /data/production.db ] From 26934dae71cb006baf0dcf77ddec4938b8c4fdbd Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 23:48:19 +0800 Subject: [PATCH 09/14] Doc: Add ignore info for secret-key env-test --- pinry/settings/docker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pinry/settings/docker.py b/pinry/settings/docker.py index 43c60b7..eb0cc1e 100644 --- a/pinry/settings/docker.py +++ b/pinry/settings/docker.py @@ -6,7 +6,8 @@ from .base import * # SECURITY WARNING: keep the secret key used in production secret! if 'SECRET_KEY' not in os.environ: logging.warning( - "No SECRET_KEY given in environ, please have a check" + "No SECRET_KEY given in environ, please have a check." + "If you have a local_settings file, please ignore this warning." ) SECRET_KEY = os.environ.get('SECRET_KEY', "PLEASE_REPLACE_ME") From 4c262a511c46297e1dacdf195f727e8a6a0534f1 Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 19 Dec 2019 23:54:52 +0800 Subject: [PATCH 10/14] Feature: Add django settings env for gunicorn --- docker/scripts/_start_gunicorn.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/scripts/_start_gunicorn.sh b/docker/scripts/_start_gunicorn.sh index 00bd77e..092aba1 100755 --- a/docker/scripts/_start_gunicorn.sh +++ b/docker/scripts/_start_gunicorn.sh @@ -1,3 +1,5 @@ #!/bin/bash gunicorn pinry.wsgi -b 0.0.0.0:8000 -w 4 \ - --capture-output --timeout 30 --user www-data --group www-data \ No newline at end of file + --capture-output --timeout 30 \ + --user www-data --group www-data \ + --env DJANGO_SETTINGS_MODULE=pinry.settings.docker From 312db1317141429df687b4d8c0242e1219dfb8f6 Mon Sep 17 00:00:00 2001 From: winkidney Date: Fri, 20 Dec 2019 00:03:09 +0800 Subject: [PATCH 11/14] Feature: Should not ignore local_settings in gunicorn --- pinry/settings/docker.py | 6 ++---- pinry/wsgi.py | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pinry/settings/docker.py b/pinry/settings/docker.py index eb0cc1e..7b23cc1 100644 --- a/pinry/settings/docker.py +++ b/pinry/settings/docker.py @@ -36,7 +36,5 @@ REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES'] = [ 'rest_framework.renderers.JSONRenderer', ] -try: - from .local_settings import * -except ImportError: - pass +# should not ignore import error in production, local_settings is required +from .local_settings import * diff --git a/pinry/wsgi.py b/pinry/wsgi.py index fdf910d..8afd24d 100644 --- a/pinry/wsgi.py +++ b/pinry/wsgi.py @@ -1,6 +1,4 @@ -import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pinry.settings.docker") application = get_wsgi_application() From db538c7c8421b870cfc727b0360a1e32e62b1906 Mon Sep 17 00:00:00 2001 From: winkidney Date: Fri, 20 Dec 2019 00:11:17 +0800 Subject: [PATCH 12/14] Feature: Should allow registration by default --- pinry/settings/local_settings.example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pinry/settings/local_settings.example.py b/pinry/settings/local_settings.example.py index d66ba5a..7c71f77 100644 --- a/pinry/settings/local_settings.example.py +++ b/pinry/settings/local_settings.example.py @@ -28,7 +28,7 @@ DATABASES = { } # Allow users to register by themselves -ALLOW_NEW_REGISTRATIONS = False +ALLOW_NEW_REGISTRATIONS = True # Delete image files once you remove your pin IMAGE_AUTO_DELETE = True From 99b1c6daa222a5026dd844c962d557e7ef547164 Mon Sep 17 00:00:00 2001 From: winkidney Date: Fri, 20 Dec 2019 00:32:38 +0800 Subject: [PATCH 13/14] Fix: Link local_settings_files every time it boots --- docker/scripts/bootstrap.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/scripts/bootstrap.sh b/docker/scripts/bootstrap.sh index 0378acb..9c08299 100755 --- a/docker/scripts/bootstrap.sh +++ b/docker/scripts/bootstrap.sh @@ -25,5 +25,6 @@ then cp "/pinry/pinry/settings/local_settings.example.py" "${local_settings_file}" gen_key sed -i "s/secret\_key\_place\_holder/${SECRET_KEY}/" "${local_settings_file}" - ln -s "${local_settings_file}" "/pinry/pinry/settings/local_settings.py" fi + +ln -s "${local_settings_file}" "/pinry/pinry/settings/local_settings.py" \ No newline at end of file From e5264ffe44d043c9ff230b999fd302677dbfb481 Mon Sep 17 00:00:00 2001 From: winkidney Date: Fri, 20 Dec 2019 00:42:09 +0800 Subject: [PATCH 14/14] Doc: Update doc for docker --- README.md | 1 + docker/README.rst | 135 -------------------------------- docs/src/install-with-docker.md | 71 +++++++++++++++++ mkdocs.yml | 1 + 4 files changed, 73 insertions(+), 135 deletions(-) delete mode 100644 docker/README.rst create mode 100644 docs/src/install-with-docker.md diff --git a/README.md b/README.md index dbb6032..043b83a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ For more information visit [getpinry.com](https://getpinry.com). - Browser Extensions - Multi-user support - Both public and private boards +- Works well with docker ## Requirements diff --git a/docker/README.rst b/docker/README.rst deleted file mode 100644 index c1e44ac..0000000 --- a/docker/README.rst +++ /dev/null @@ -1,135 +0,0 @@ -Pinry Docker -============ - -.. image:: https://travis-ci.org/pinry/docker-pinry.svg?branch=master - :target: https://travis-ci.org/pinry/docker-pinry - -A nice and easy way to get a Pinry instance up and running using docker. For -help on getting started with docker see the `official getting started guide`_. -For more information on Pinry and a demo check out it's `website`_. - - -Getting Pinry Docker ---------------------- - -Running this will get the latest version of pinry itself:: - - git clone https://github.com/pinry/pinry - cd pinry - ./docker/bootstrap.sh - -Now you can start your container by command like this:: - - # this is where your database and pins localted - mkdir data - # use absolute path for docker to avoid using default data-volume (we use directory instead) - ./docker/start_docker.sh `readlink -f data` - -Please visit `http://your-ip` to visit your instance and register a new account, enjoy it. - - -Configuring docker-pinry ------------------------- -Enable signups for new users by editing ``pinry/local_settings.py``:: - - ALLOW_NEW_REGISTRATIONS = True - -`Additional pinry configuration settings`_ - -Building docker-pinry again ---------------------------- - -Running this will build you a docker image with the latest version of pinry:: - - ./docker/build_docker.sh - - -Running docker-pinry in manual way ----------------------------------- - -Running the start command for the first time will setup your production secret -key, database and static files. It is important that you decide what port you -want and what location on the host machine you wish to store your files. If this -is the only thing running on your system and you wish to make it public without -a proxy then you can set ``-p=80:80``. The setting ``-p=10000:80`` assumes you -are wanting to proxy to this instance using something like nginx. Also note that -you must have your host mount directory created first (``mkdir -p /mnt/pinry``) - -Then you have two choice to run docker-pinry - -Fist one, with automaticlly configured default arguments:: - - ./docker/start_docker.sh /mnt/pinry - - -Second one, start docker by hand with customized arguments:: - - SETTINGS_PATH=$(readlink -f docker/pinry/local_settings.py) \ - DATA_PATH=$(readlink -f /mnt/pinry) \ - sudo docker run -d=true -p=10000:80 \ - -v=${DATA_PATH}:/data \ - -v=${SETTINGS_PATH}:/srv/www/pinry/pinry/settings/local_settings.py \ - pinry/pinry /scripts/start.sh - -If it's the first run it'll take a few seconds but it will print out your -container ID which should be used to start and stop the container in the future -using the commands:: - - sudo docker start - sudo docker stop - - -Running docker-pinry with docker-compose ------------------------------------------ - - -Just config your ``docker-compose.yml`` and then run:: - - sudo pip install -U docker-compose - sudo docker-compose --project-directory docker up -d - - -Notes on the run commands -````````````````````````` - -* ``-v`` is the volume you are mounting ``-v=host_dir:docker_dir`` -* ``pinry/pinry`` is simply what I called my docker build of this image -* ``-d=true`` allows this to run cleanly as a daemon, remove for debugging -* ``-p`` is the port it connects to, ``-p=host_port:docker_port`` -* Follow comments in ``local_settings.py`` to understand how the site configured - -Using docker-pinry ------------------- -Open a browser to ``http://:10000`` and register. Replace YOUR-HOSTNAME with the name -of the machine docker is running on, likely localhost. - -You can map ``http://localhost:10000`` to your outer nginx for SSL or just change -the default port-mapping to ``80:80`` to serve your site directly, just enjoy! - - -Why include nginx and not just map to gunicorn directly? ------------------------------------------------------------ - -Because gunicorn/django can't serve static files very well and it is unwise to do -so for security reasons. I built this so that people can have a full hosted -solution in a container. If you have a host machine running nginx then of course -there is no point to run nginx in the container as well, you can simply disable -nginx, map gunicorn to a port and then set your host machine's nginx to display -your media and static files since that directory is shared between the container -and host. - - -Why use sqlite3? ----------------- - -Because it has a very low resource cost and most pinry websites are small -personal ones. Why have a full on database for that? If you need more power -than you can easily modify the `pinry/local_settings.py` to point to a -stronger database solution. - - -.. Links - -.. _official getting started guide: http://www.docker.io/gettingstarted/ -.. _website: http://getpinry.com/ -.. _additional pinry configuration settings: https://github.com/pinry/pinry/blob/master/docker/pinry/local_settings.example.py diff --git a/docs/src/install-with-docker.md b/docs/src/install-with-docker.md new file mode 100644 index 0000000..a28c145 --- /dev/null +++ b/docs/src/install-with-docker.md @@ -0,0 +1,71 @@ +Pinry Docker +================ + +A nice and easy way to get a Pinry instance up and running using docker. For +help on getting started with docker see the official getting started guide at +the end of this page. + + +# Getting Pinry Docker + + +Running this will get the latest version of pinry itself +``` +git clone https://github.com/pinry/pinry +cd pinry/docker +./build_docker.sh +``` +Now you can start your container by command like this +``` +# this is where your database, local_settings and pins located +mkdir data +# use absolute path for docker to avoid using default data-volume (we use directory instead) +./start_docker.sh `readlink -f data` +``` +Please visit `http://your-ip` to visit your instance and register a new account, enjoy it. + + +Configuring docker-pinry +------------------------ +Enable signups for new users by editing `pinry/local_settings.py` +``` +ALLOW_NEW_REGISTRATIONS = True +``` + +# Building docker-pinry again (with latest version) + + +Running this will build you a docker image with the latest version of pinry +``` +git pull --rebase +cd ./docker/ +./build_docker.sh +``` + +# Backup +Just copy `data` folder's content to an safe place, enjoy :) + + +# Why include nginx and not just map to gunicorn directly? + +Because gunicorn/django can't serve static files very well and it is unwise to do +so for security reasons. I built this so that people can have a full hosted +solution in a container. If you have a host machine running nginx then of course +there is no point to run nginx in the container as well, you can simply disable +nginx, map gunicorn to a port and then set your host machine's nginx to display +your media and static files since that directory is shared between the container +and host. + + +# Why use sqlite3? + +Because it has a very low resource cost and most pinry websites are small +personal ones. Why have a full on database for that? If you need more power +than you can easily modify the `data/local_settings.py` to point to a +stronger database solution. + + +# Links + ++ [official getting started guide](http://www.docker.io/gettingstarted/) ++ [additional pinry configuration settings](https://github.com/pinry/pinry/blob/master/pinry/settings/local_settings.example.py) diff --git a/mkdocs.yml b/mkdocs.yml index 2ca43cc..22d296a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -17,6 +17,7 @@ nav: - Screenshots: 'screenshots.md' - Extensions: 'extensions.md' - Theories: 'theories.md' + - InstallWithDocker: 'install-with-docker.md' - Development: 'development.md' - Docs: 'docs.md' - Passwords: 'passwords.md'