archive
This commit is contained in:
66
silverstrike/scratch/Dockerfile
Executable file
66
silverstrike/scratch/Dockerfile
Executable file
@@ -0,0 +1,66 @@
|
||||
FROM ubuntu:18.04 as builder
|
||||
|
||||
### SYS
|
||||
RUN export DEBIAN_FRONTEND=noninteractive; \
|
||||
apt -y update || true; \
|
||||
apt -y install tzdata; \
|
||||
ln -fs /usr/share/zoneinfo/America/Denver /etc/localtime; \
|
||||
dpkg-reconfigure --frontend noninteractive tzdata; \
|
||||
apt -y install \
|
||||
curl \
|
||||
rsync \
|
||||
cron \
|
||||
postgresql postgresql-contrib \
|
||||
&& mkdir -p /mnt/save
|
||||
|
||||
### POSTGRES
|
||||
RUN apt -y install sudo \
|
||||
&& service postgresql start
|
||||
USER postgres
|
||||
RUN service postgresql start \
|
||||
&& createuser www-data \
|
||||
&& createdb -O www-data silverstrikedb
|
||||
|
||||
#&& psql --command "CREATE USER ss WITH SUPERUSER PASSWORD 'ss';" \
|
||||
#&& psql --command "CREATE DATABASE silverstrikedb;" \
|
||||
#&& psql --command "GRANT ALL PRIVILEGES ON DATABASE silverstrikedb TO ss;"
|
||||
|
||||
USER root
|
||||
|
||||
### APP
|
||||
RUN \
|
||||
apt -y install nginx postgresql uwsgi uwsgi-plugin-python git python-pip python python-psycopg2 libpq-dev python-dev \
|
||||
&& pip install venv \
|
||||
&& mkdir -p /srv/webapps \
|
||||
&& cd /srv/webapps \
|
||||
&& git clone https://github.com/agstrike/production-project silverstrike \
|
||||
&& cd silverstrike \
|
||||
&& python -m venv env \
|
||||
&& . env/bin/activate \
|
||||
&& pip3 install silverstrike psycopg2 django
|
||||
COPY settings.py /srv/webapps/silverstrike/
|
||||
RUN \
|
||||
cd /srv/webapps/silverstrike \
|
||||
&& service postgresql start \
|
||||
&& python manage.py migrate \
|
||||
&& python manage.py collectstatic \
|
||||
&& ln -s /srv/webapps/silverstrike/uwsgi.ini /etc/uwsgi/apps-enabled/silverstrike.ini \
|
||||
&& service uwsgi start
|
||||
|
||||
### CRON BACKUPS
|
||||
RUN true \
|
||||
&& echo 'b=$(date +%Y%m%d%H%M%S) && mkdir -p /mnt/save/$b && pg_dump $DATABASE_URL --clean > /mnt/save/$b/pg.dump' > /backup.sh \
|
||||
&& echo 'b=$(find /mnt/save -type f | sort | tail -n 1); if [ -n "$b" ]; then echo restoring $b; psql $DATABASE_URL < "$b"; fi && service postgresql start;' > /restore.sh \
|
||||
&& echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \
|
||||
&& echo '' >> /etc/cron.d/backups \
|
||||
&& chmod 0644 /etc/cron.d/backups \
|
||||
&& touch /var/log/cronj.log
|
||||
|
||||
### FINAL
|
||||
ENV DATABASE_URL=postgres://www-data:password@localhost/silverstrikedb?sslmode=disable
|
||||
ENV SECRET_KEY=AimmBfzjdWcVN3rQs8YawbUowv5R8Eex
|
||||
ENV ALLOWED_HOSTS=*
|
||||
ENTRYPOINT \
|
||||
until psql $DATABASE_URL < /dev/null; do sleep 5; done \
|
||||
&& bash /restore.sh \
|
||||
&& sleep 5 && python manage.py migrate && exec uwsgi
|
||||
Reference in New Issue
Block a user