-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathDockerfile
86 lines (71 loc) · 3.12 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
FROM ubuntu:18.04
ENV PYTHONUNBUFFERED 1
ENV DEBIAN_FRONTEND noninteractive
EXPOSE 8000
# Usual update / upgrade with locale setup
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -yq software-properties-common sudo curl locales\
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& echo en_US.UTF-8 UTF-8 >> /etc/locale.gen \
&& locale-gen \
&& ln -fs /usr/share/zoneinfo/Europe/Helsinki /etc/localtime
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' LC_CTYPE='en_US.UTF-8'
# Install basics
RUN apt-get update \
&& apt-get install -yq postgresql git python3-dev virtualenv python3-virtualenv vim \
python3-pip python-pip npm \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
# Install maildump
EXPOSE 1080
RUN pip install --no-cache-dir maildump
# Create database
USER postgres
RUN service postgresql start && \
createuser asylum && \
createdb -E utf-8 -T template0 -O asylum asylum && \
psql -U postgres -d postgres -c "alter user asylum with password 'asylum'; alter user asylum with createdb;"
# Create a newuser
USER root
RUN adduser --disabled-password --gecos '' asylum && \
adduser asylum sudo && \
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Create volume
RUN mkdir /opt/asylum/ && chown asylum:asylum /opt/asylum/
# VOLUME /opt/asylum/ # Your local uid != 1000? Tough. Create an issue and add an idea how to fix it.
WORKDIR /opt/asylum/
# Install system packages
COPY project/requirements.apt /opt/asylum/
RUN apt-get update \
&& awk '/^\s*[^#]/' requirements.apt | xargs -r -- sudo apt-get install --no-install-recommends -y \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
USER root
# Install python requirements
RUN virtualenv -p `which python3` ../asylum-venv
COPY project/requirements /opt/asylum/requirements/
RUN . ../asylum-venv/bin/activate && \
pip3 install --no-cache-dir packaging appdirs urllib3[secure] && \
pip3 install --no-cache-dir -r requirements/local.txt && \
chown -R asylum:asylum ../asylum-venv && \
true
# Configure application
USER root
RUN echo "DATABASE_URL=postgres://asylum:asylum@localhost/asylum" > .env
COPY project /opt/asylum/
RUN chown -R asylum:asylum /opt/asylum/
# Build localisations
USER asylum
RUN . ../asylum-venv/bin/activate && \
for app in locale */locale; do (cd $(dirname $app) && ../manage.py compilemessages ); done
# Run migrate and create admin user
USER asylum
RUN npm run build \
&& sudo -u postgres service postgresql start; \
. ../asylum-venv/bin/activate \
&& export PGPASSWORD=asylum; while true; do psql -q asylum -c 'SELECT 1;' 1>/dev/null 2>&1 ; if [ "$?" -ne "0" ]; then echo "Waiting for psql"; sleep 1; else break; fi; done \
&& ./manage.py migrate \
&& echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', '[email protected]', 'admin') ; from rest_framework.authtoken.models import Token ; Token.objects.create(user=User.objects.get(username='admin'), key='deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')" | ./manage.py shell
ENTRYPOINT ["/opt/asylum/docker-entrypoint.sh"]