mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
Reafactor: Docker auto-build should be a out-of-the-box image without any extra config
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
# Require: Docker (http://www.docker.io/)
|
# Require: Docker (http://www.docker.io/)
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# Base system is the LTS version of Ubuntu.
|
# Base system is the LTS version of Ubuntu.
|
||||||
FROM python:3.7-stretch
|
FROM python:3.7-stretch
|
||||||
|
|
||||||
@@ -20,28 +19,26 @@ RUN groupadd -g 2300 tmpgroup \
|
|||||||
&& groupadd -g 1000 www-data \
|
&& groupadd -g 1000 www-data \
|
||||||
&& usermod -g www-data www-data \
|
&& usermod -g www-data www-data \
|
||||||
&& usermod -u 1000 www-data \
|
&& usermod -u 1000 www-data \
|
||||||
&& groupdel tmpgroup \
|
&& groupdel tmpgroup
|
||||||
#
|
|
||||||
&& mkdir -p /srv/www/pinry/logs \
|
RUN mkdir /data
|
||||||
#
|
RUN mkdir -p /data/logs
|
||||||
&& mkdir /data \
|
RUN chown -R www-data:www-data /data
|
||||||
&& chown -R www-data:www-data /data \
|
|
||||||
#
|
RUN apt-get update \
|
||||||
&& mkdir -p /var/log/gunicorn \
|
|
||||||
&& apt-get update \
|
|
||||||
&& apt-get -y install nginx nginx-extras pwgen \
|
&& 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
|
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 \
|
RUN cd /srv/www/pinry \
|
||||||
&& pipenv install --three --system --clear
|
&& pipenv install --three --system --clear
|
||||||
|
|
||||||
COPY . /srv/www/pinry/
|
# config nodejs
|
||||||
|
|
||||||
# config nodejs and build frontend
|
|
||||||
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n || exit
|
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n || exit
|
||||||
RUN bash n 10
|
RUN bash n 10
|
||||||
RUN npm -g install yarn
|
RUN npm -g install yarn
|
||||||
@@ -49,12 +46,6 @@ RUN npm -g install yarn
|
|||||||
# build frontend
|
# build frontend
|
||||||
RUN cd /srv/www/pinry/pinry-spa/ && yarn install && yarn build
|
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.
|
# Load in all of our config files.
|
||||||
ADD docker/nginx/nginx.conf /etc/nginx/nginx.conf
|
ADD docker/nginx/nginx.conf /etc/nginx/nginx.conf
|
||||||
ADD docker/nginx/sites-enabled/default /etc/nginx/sites-enabled/default
|
ADD docker/nginx/sites-enabled/default /etc/nginx/sites-enabled/default
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -2,14 +2,10 @@ server {
|
|||||||
listen 80 default;
|
listen 80 default;
|
||||||
server_name _;
|
server_name _;
|
||||||
|
|
||||||
access_log /srv/www/pinry/logs/access.log;
|
access_log /data/logs/access.log;
|
||||||
error_log /srv/www/pinry/logs/error.log;
|
error_log /data/logs/error.log;
|
||||||
|
|
||||||
location /media {
|
root /srv/www/pinry/pinry-spa/dist/;
|
||||||
alias /data/static/media;
|
|
||||||
expires max;
|
|
||||||
access_log off;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /static {
|
location /static {
|
||||||
alias /data/static;
|
alias /data/static;
|
||||||
|
|||||||
2
docker/pinry/.gitignore
vendored
2
docker/pinry/.gitignore
vendored
@@ -1,2 +0,0 @@
|
|||||||
local_settings.py
|
|
||||||
production_secret_key.txt
|
|
||||||
29
docker/scripts/bootstrap.sh
Executable file
29
docker/scripts/bootstrap.sh
Executable 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
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
gen_key() {
|
||||||
# Check for secret key if one doesn't exist create.
|
# Check for secret key if one doesn't exist create.
|
||||||
if [ ! -f /data/production_secret_key.txt ]
|
if [ ! -f /data/production_secret_key.txt ]
|
||||||
then
|
then
|
||||||
@@ -11,3 +12,4 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo ${PRODUCTION_SECRET_KEY}
|
echo ${PRODUCTION_SECRET_KEY}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,13 +9,11 @@
|
|||||||
# Updated: Aug 19th, 2014
|
# Updated: Aug 19th, 2014
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bash /scripts/bootstrap.sh
|
||||||
|
|
||||||
# If static files don't exist collect them
|
# If static files don't exist collect them
|
||||||
if [ ! -d /data/static ]
|
|
||||||
then
|
|
||||||
cd /srv/www/pinry
|
cd /srv/www/pinry
|
||||||
python manage.py collectstatic --noinput
|
python manage.py collectstatic --noinput
|
||||||
fi
|
|
||||||
|
|
||||||
# If database doesn't exist yet create it
|
# If database doesn't exist yet create it
|
||||||
if [ ! -f /data/production.db ]
|
if [ ! -f /data/production.db ]
|
||||||
|
|||||||
Reference in New Issue
Block a user