forked from materialscloud-org/tools-barebone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
106 lines (85 loc) · 3.3 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Use phusion/baseimage as base image. To make your builds
# reproducible, make sure you lock down to a specific version, not
# to `latest`! See
# https://github.com/phusion/baseimage-docker/blob/master/Changelog.md
# for a list of version numbers.
# Note also that we use phusion because, as explained on the
# http://phusion.github.io/baseimage-docker/ page, it automatically
# contains and starts all needed services (like logging), it
# takes care of sending around signals when stopped, etc.
##
# Actually, I use passenger-full that already has python
# https://github.com/phusion/passenger-docker#using
FROM phusion/passenger-customizable:2.0.0
LABEL maintainer="Materials Cloud <[email protected]>"
# Everything will be run as root
USER root
# Set correct environment variables.
ENV HOME /root
# If you're using the 'customizable' variant, you need to explicitly opt-in
# for features. Uncomment the features you want:
#
# Build system and git.
# Python support (2.7 and 3.x - it is 3.6.x in this ubuntu 18.04)
RUN /pd_build/utilities.sh && \
/pd_build/python.sh
##########################################
############ Installation Setup ##########
##########################################
# Install required software
# Install Apache
# (nginx doesn't have the X-Sendfile support that we want to use)
## NOTE: Here and below we install everything with python3
RUN apt-get update \
&& apt-get -y install \
python3-pip \
apache2 \
libapache2-mod-xsendfile \
libapache2-mod-wsgi-py3 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean all
# set $HOME
ENV HOME /home/app
# Run this as sudo to replace the version of pip
#RUN pip3 install -U 'pip>=10' setuptools wheel
# Setup apache
# Disable default apache site, enable tools site; also
# enable needed modules
ADD ./.docker_files/apache-site.conf /etc/apache2/sites-available/app.conf
RUN a2enmod wsgi && a2enmod xsendfile && \
a2dissite 000-default && a2ensite app
# Activate apache at startup
RUN mkdir /etc/service/apache
#RUN mkdir /var/run/apache2
ADD ./.docker_files/apache_run.sh /etc/service/apache/run
# Web
EXPOSE 80
# Set startup script to create the secret key
RUN mkdir -p /etc/my_init.d
ADD ./.docker_files/create_secret_key.sh /etc/my_init.d/create_secret_key.sh
# Download code
RUN mkdir -p $HOME/code/
WORKDIR $HOME/code/
COPY ./requirements.txt requirements.txt
RUN pip3 install -r $HOME/code/requirements.txt
COPY ./setup.py setup.py
COPY README.md README.md
COPY ./tools_barebone/ tools_barebone
RUN pip3 install -e .
# Actually, don't download, but get the code directly from this repo
COPY ./webservice/ webservice
# Get Materials Cloud header
RUN git clone https://github.com/materialscloud-org/frontend-theme.git && \
cp -r frontend-theme/header/jinja/app/* webservice/
# Create a proper wsgi file
ENV SP_WSGI_FILE=webservice/app.wsgi
RUN echo "import sys" > $SP_WSGI_FILE && \
echo "sys.path.insert(0, '/home/app/code/webservice')" >> $SP_WSGI_FILE && \
echo "from run_app import app as application" >> $SP_WSGI_FILE
# Set proper permissions for user 'app' who will be used to run the service
RUN chmod -R o+rX $HOME
RUN chown -R app:app $HOME
# Final cleanup, in case it's needed
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]