Reafactor: Docker auto-build should be a out-of-the-box image without any extra config

This commit is contained in:
winkidney
2019-12-19 16:10:14 +08:00
parent 2a2f65c437
commit 77fca13edf
7 changed files with 59 additions and 96 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -1,2 +0,0 @@
local_settings.py
production_secret_key.txt

29
docker/scripts/bootstrap.sh Executable file
View File

@@ -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

View File

@@ -1,5 +1,6 @@
#!/bin/bash
gen_key() {
# Check for secret key if one doesn't exist create.
if [ ! -f /data/production_secret_key.txt ]
then
@@ -11,3 +12,4 @@ else
fi
echo ${PRODUCTION_SECRET_KEY}
}

View File

@@ -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
# If database doesn't exist yet create it
if [ ! -f /data/production.db ]