Commit 59101b58 authored by Buskermolen, Joost's avatar Buskermolen, Joost
Browse files

Modified to be suitable for Kubernetes

parent 522b0c90
...@@ -6,3 +6,4 @@ wsm.rest.sock ...@@ -6,3 +6,4 @@ wsm.rest.sock
logs logs
.project .project
.pydevproject .pydevproject
.vscode
\ No newline at end of file
FROM ubuntu:16.04 FROM ubuntu:18.04
MAINTAINER Luís de Sousa <luis.desousa@wur.nl> LABEL MAINTAINER Luís de Sousa <luis.desousa@wur.nl>
RUN apt update RUN apt update && apt -y install python-pip python-dev nginx curl
RUN apt -y install python-pip python-dev nginx RUN mkdir -p /var/www/wsm.rest
COPY ./requirements.txt /tmp/requirements.txt WORKDIR /var/www/wsm.rest
RUN pip install -r /tmp/requirements.txt
COPY . .
RUN chmod +x configs/startup.sh
RUN pip install -r requirements.txt
ENTRYPOINT [ "configs/startup.sh" ]
# Expose port 80
EXPOSE 80 EXPOSE 80
STOPSIGNAL SIGQUIT
HEALTHCHECK CMD curl --fail http://localhost:80 || exit 1
CMD ["nginx", "-g", "daemon off;"]
################### Usage ##################### ################### Usage #####################
# Build it # Build it
# docker build -t ldesousa/wsm.rest . # docker build -t ldesousa/wsm.rest .
# Run command # Set the correct database connection in using environment variables or an env-file:
# docker run -dit -v /var/www/wsm.rest:/var/www/wsm.rest -v /data/monoliths:/data/monoliths --name wsm.rest -p 8081:80 ldesousa/wsm.rest
# Set the correct database connection in common/secret.py
# Attach to the container and run the startup script # Run command with envfile
# docker attach wsm.rest # docker run -dit --env-file /path/to/envfile -v /data/monoliths:/data/monoliths --name wsm.rest -p 8081:80 ldesousa/wsm.rest
# sh /var/www/wsm.rest/configs/startup.sh
# Ctrl+P Ctrl+Q
# Declaring variables inline:
# docker run -dit -e DB_HOST=scomp1270.wurnet.nl -e DB_NAME=isric -e DB_USER=haas005 -e DB_PASSWORD=wur -e DB_PORT=5479 -v /data/monoliths:/data/monoliths --name wsm.rest -p 8081:80 ldesousa/wsm.rest
\ No newline at end of file
"""Password of database""" """Password of database"""
"""This is just an example, change to the correct values and rename the file to """Secrets will be read from environment variables, and have some example default values set."""
secret.py"""
DB={"host":"scomp1270.wurnet.nl","database":"isric", "user":"haas005", "password":"isis3543","port":"5479"} from os import environ
\ No newline at end of file # Get environment variables and set default if none specified:
DB_HOST = environ.get("DB_HOST", "scomp1270.wurnet.nl")
DB_NAME = environ.get("DB_NAME", "isric")
DB_USER = environ.get("DB_USER", "haas005")
DB_PASSWORD = environ.get("DB_PASSWORD", "isis3543")
DB_PORT = environ.get("DB_PORT", "5479")
DB={"host":DB_HOST,"database":DB_NAME, "user":DB_USER, "password":DB_PASSWORD,"port":DB_PORT}
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
cd /var/www/wsm.rest cd /var/www/wsm.rest
mkdir logs mkdir logs
echo "Launching Gunicorn..." echo "Launching Gunicorn..."
nohup /usr/local/bin/gunicorn wsgi:app --workers 3 --bind unix:wsm.rest.sock -m 007 </dev/null >logs/gunicorn.log 2>&1 & nohup /usr/local/bin/gunicorn wsgi:app --workers 3 --bind unix:wsm.rest.sock -m 007 </dev/null >logs/gunicorn.log 2>&1 &
...@@ -9,9 +10,6 @@ echo "Setting up nginx config." ...@@ -9,9 +10,6 @@ echo "Setting up nginx config."
rm -f /etc/nginx/sites-enabled/default rm -f /etc/nginx/sites-enabled/default
cp /var/www/wsm.rest/configs/wsm.rest.nginx /etc/nginx/sites-enabled/wsm.rest cp /var/www/wsm.rest/configs/wsm.rest.nginx /etc/nginx/sites-enabled/wsm.rest
echo "Launching nginx..."
nohup nginx </dev/null >logs/nginx.log 2>&1 &
# Wait a little for Gunicorn to set up # Wait a little for Gunicorn to set up
sleep 2 sleep 2
...@@ -19,3 +17,4 @@ echo "Fixing access to socket." ...@@ -19,3 +17,4 @@ echo "Fixing access to socket."
chown www-data:www-data /var/www/wsm.rest/wsm.rest.sock chown www-data:www-data /var/www/wsm.rest/wsm.rest.sock
echo "All done. Good to go!" echo "All done. Good to go!"
exec "$@"
\ No newline at end of file
server { server {
listen 80; listen 80;
server_name server_domain_or_IP; server_name localhost;
access_log /dev/stdout;
error_log /dev/stderr;
location / { location / {
include proxy_params; include proxy_params;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment