From 70f9fb9818ca0721bd046f613637058debf7b6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Fri, 5 Jul 2019 01:26:52 +0200 Subject: [PATCH] Improve production setup --- .dockerignore | 16 +++++++++ Dockerfile | 18 +++------- bootstrap.sh | 10 +++--- build-docker.sh | 4 +-- linkdings.iml | 7 +--- requirements.prod.txt | 2 ++ requirements.txt | 1 + siteroot/settings/__init__.py | 5 +++ siteroot/{settings.py => settings/base.py} | 34 ++++-------------- siteroot/settings/custom.py | 1 + siteroot/settings/dev.py | 40 ++++++++++++++++++++++ siteroot/settings/prod.py | 33 ++++++++++++++++++ siteroot/settings_custom.py | 1 - siteroot/settings_prod.py | 18 ---------- uwsgi.ini | 7 ++-- 15 files changed, 120 insertions(+), 77 deletions(-) create mode 100644 .dockerignore create mode 100644 siteroot/settings/__init__.py rename siteroot/{settings.py => settings/base.py} (85%) create mode 100644 siteroot/settings/custom.py create mode 100644 siteroot/settings/dev.py create mode 100644 siteroot/settings/prod.py delete mode 100644 siteroot/settings_custom.py delete mode 100644 siteroot/settings_prod.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0691627 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +# Remove project files, data, tmp files, build files +/.env +/.idea +/data +/node_modules +/tmp + +/.dockerignore +/.gitignore +/build-*.sh +/Dockerfile +/*.iml +/package*.json + +# Remove development settings +/siteroot/settings/dev.py diff --git a/Dockerfile b/Dockerfile index 939e0ba..86e89ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,25 +5,17 @@ RUN apt-get update RUN apt-get -y install build-essential # Install requirements and uwsgi server for running python web apps -WORKDIR /etc/linkdings +WORKDIR /etc/linkding COPY requirements.prod.txt ./requirements.txt RUN pip install -U pip RUN pip install -Ur requirements.txt -RUN pip install uwsgi # Copy application -COPY bookmarks ./bookmarks -COPY siteroot ./siteroot -COPY static ./static -COPY manage.py . -COPY uwsgi.ini . -COPY bootstrap.sh . -RUN ["chmod", "+x", "./bootstrap.sh"] - -# Create data folder -RUN ["mkdir", "data"] +COPY . . +# Expose uwsgi server at port 9090 EXPOSE 9090 -# Start uwsgi server +# Run bootstrap logic +RUN ["chmod", "+x", "./bootstrap.sh"] CMD ["./bootstrap.sh"] diff --git a/bootstrap.sh b/bootstrap.sh index 450a108..80bc7d0 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,14 +1,12 @@ #!/usr/bin/env bash # Bootstrap script that gets executed in new Docker containers -# Set host name in settings if it was passed as environment variable -if [[ -v HOST_NAME ]] -then - printf "ALLOWED_HOSTS=['%s']" $HOST_NAME > ./siteroot/settings_custom.py -fi - +# Create data folder if it does not exist +mkdir -p data # Run database migration python manage.py migrate +# Generate secret key file if it does not exist +python manage.py generate_secret_key # Start uwsgi server uwsgi uwsgi.ini diff --git a/build-docker.sh b/build-docker.sh index 1c51aab..0813d47 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash ./build-static.sh -docker build -t sissbruecker/linkding . -#docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t sissbruecker/linkding:latest --push . +#docker build -t sissbruecker/linkding . +docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t sissbruecker/linkding:latest --push . diff --git a/linkdings.iml b/linkdings.iml index 613ffc2..afe2abf 100644 --- a/linkdings.iml +++ b/linkdings.iml @@ -4,7 +4,7 @@