Skip to content

Commit

Permalink
single multistage Dockerfile for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaranasou committed Nov 26, 2021
1 parent a86256a commit 6c60b2f
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 146 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,28 @@ docker-compose exec kafka bash

# the following will consume / display a few messages, just to make sure all is well
/opt/bitnami/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic deflect.logs --offset 6131 --partition 0
```
```

### Dashboard
Notes for the Baskerville dashboard:
- The Dockerfile is heavy, as it is a multistage Dockerfile. It uses Nginx internally but, since we already have an nginx service
it would be nice to have a common volume for the front-end to be served and proper networking for the backend to be served also (only for the web-sockets)
- It has Baskerville as a dependency (with all that this entails, like esretriever, iforest pyspark etc, which means different pyspark versions with conflicts and a lot of build time)



### Misc
In case baskerville_preprocessing and baskerville_postprocessing fail to start because `baskerville` database does not exist:
```bash
docker-compose exec postgres bash
psql
CREATE DATABASE baskerville;
\q
exit

docker-compose restart baskerville_preprocessing baskerville_postprocessing
```

### Firewall
- open 29092 port for Kafka connections

97 changes: 97 additions & 0 deletions containers/baskerville_dashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# GLOBAL ARGS:
ARG DOCKER_KAFKA_HOST
ARG DASHBOARD_BRANCH
# for front-end
ARG API_BASE_URL
ARG SOCKET_URL
# for backend:
ARG BASKERVILLE_BRANCH
ARG REDIS_HOST

#FROM nginx:1.17.1-alpine AS NGINX
FROM node:14.8.0-alpine AS FRONTEND
ARG DASHBOARD_BRANCH
ARG API_BASE_URL
ARG SOCKET_URL

ENV DASHBOARD_BRANCH $DASHBOARD_BRANCH
ENV API_BASE_URL $API_BASE_URL
ENV SOCKET_URL $SOCKET_URL

RUN apk update \
# && apk upgrade \
&& apk add git \
&& mkdir /app && cd /app \
&& git clone --branch $DASHBOARD_BRANCH https://github.com/deflect-ca/baskerville_dashboard.git \
&& cd baskerville_dashboard/front-end \
&& npm install \
&& npm install -g @angular/[email protected]

RUN echo $SOCKET_URL, $API_BASE_URL && echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"

# this builds the front-end with provided configuration and copies the result in /var/www for nginx
RUN cd /app/baskerville_dashboard/front-end \
&& npm run config \
&& ng build --prod

FROM openjdk:8 AS OJDK8
FROM python:3.6 AS BACKEND

ARG DOCKER_KAFKA_HOST
ARG BASKERVILLE_BRANCH
ARG DASHBOARD_BRANCH
ARG REDIS_HOST

ENV DOCKER_KAFKA_HOST $DOCKER_KAFKA_HOST
ENV DASHBOARD_BRANCH $DASHBOARD_BRANCH
ENV BASKERVILLE_BRANCH $BASKERVILLE_BRANCH
ENV REDIS_HOST $REDIS_HOST
ENV BASKERVILLE_ROOT '/app/baskerville'
ENV BASKERVILLE_DASH_ROOT '/app/baskerville_dashboard'


# Get jdk8 from previous stage https://docs.docker.com/develop/develop-images/multistage-build/
COPY --from=OJDK8 /usr/local/openjdk-8 /usr/local/openjdk-8
COPY --from=FRONTEND /app/baskerville_dashboard/front-end/dist/baskerville_dashboard_frontend/ /var/www/baskerville_dashboard_frontend/

# Set java path
ENV JAVA_HOME /usr/local/openjdk-8
ENV PATH $PATH:$JAVA_HOME/bin

# TODO: The following installs spark-iforest, esretriever and baskerville
# which takes a long time - mostly because of the different pyspark versions.
RUN apt-get clean && apt-get update \
# && apt-get -y upgrade \
&& apt-get install -y nginx=1.18.* \
&& apt-get install git \
&& pip install --upgrade pip \
&& mkdir /app && cd /app \
&& git clone https://github.com/titicaca/spark-iforest.git \
&& cd spark-iforest/python \
&& pip install . \
&& cd /app \
&& git clone https://github.com/equalitie/esretriever.git \
&& cd esretriever \
&& pip install . \
&& cd /app \
&& git clone --branch $BASKERVILLE_BRANCH https://github.com/deflect-ca/baskerville.git \
&& cd baskerville \
&& pip install . \
&& cd /app \
&& git clone --branch $DASHBOARD_BRANCH https://github.com/deflect-ca/baskerville_dashboard.git \
&& cd baskerville_dashboard/backend \
&& pip install . \
&& cd /app/baskerville_dashboard/backend/src/baskerville_dashboard

# copy all related configurations
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./config.yaml /app/baskerville_dashboard/backend/conf
COPY ./baskerville.yaml /app/baskerville_dashboard/backend/conf

WORKDIR /app/baskerville_dashboard/backend/src/baskerville_dashboard

# socketio for Python includes a production grade web server.
# start.sh starts nginx and runs dashboard backend.
COPY start.sh start.sh
CMD ["sh", "./start.sh"]
EXPOSE 80 81 5000
51 changes: 0 additions & 51 deletions containers/baskerville_dashboard/backend/Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
database:
name: baskerville
user: !ENV ${DB_USER:postgres}
host: !ENV ${DB_HOST:postgres}
host: !ENV ${DB_HOST:127.0.0.1}
port: !ENV ${DB_PORT:5432}
password: !ENV ${DB_PASS:secret}
type: 'postgres'
Expand Down Expand Up @@ -91,7 +91,7 @@ engine:

kafka:
connection:
bootstrap_servers: !ENV '${KAFKA_HOST:kafka}'
bootstrap_servers: !ENV '${DOCKER_KAFKA_HOST:0.0.0.0}'
# bootstrap_servers: !ENV ${KAFKA_HOST}
auto_offset_reset: 'smallest'
data_topic: 'feedback'
Expand All @@ -111,10 +111,10 @@ spark:
parallelism: -1
log_conf: 'true'
log_level: 'ERROR'
redis_host: !ENV ${REDIS_HOST:localhost}
redis_host: !ENV ${REDIS_HOST:redis}
redis_password: !ENV ${REDIS_PASSWORD:""}
redis_port: '6379'
jars: !ENV '${BASKERVILLE_ROOT}/data/jars/spark-redis_2.11-2.5.0-SNAPSHOT-jar-with-dependencies.jar,${BASKERVILLE_ROOT}/data/jars/spark-iforest-3.0.1.jar,${BASKERVILLE_ROOT}/data/jars/postgresql-42.2.4.jar,${BASKERVILLE_ROOT}/data/jars/spark-streaming-kafka-0-8-assembly_2.11-2.4.0.jar'
jars: !ENV '${BASKERVILLE_ROOT}/data/jars/spark-redis_2.11-2.5.0-SNAPSHOT-jar-with-dependencies.jar,${BASKERVILLE_ROOT}/data/jars/spark-iforest-2.4.0.99.jar,${BASKERVILLE_ROOT}/data/jars/postgresql-42.2.4.jar,${BASKERVILLE_ROOT}/data/jars/spark-streaming-kafka-0-8-assembly_2.11-2.4.0.jar'
session_timezone: 'UTC'
shuffle_partitions: 12
spark_driver_memory: '8G'
Expand All @@ -135,20 +135,3 @@ spark:
driver_java_options: '-Dio.netty.noPreferDirect=true -Dio.netty.allocator.type=unpooled -XX:+UseCompressedOops -XX:G1HeapRegionSize=10 -XX:+UseG1GC -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2 -XX:InitiatingHeapOccupancyPercent=25 -XX:+UnlockDiagnosticVMOptions -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1098'
executor_extra_java_options: '-Dio.netty.noPreferDirect=true -Dio.netty.allocator.type=unpooled -XX:+UseCompressedOops -XX:G1HeapRegionSize=10 -XX:+UseG1GC -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2 -XX:InitiatingHeapOccupancyPercent=25 -XX:+PrintFlagsFinal -XX:+PrintReferenceGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UnlockDiagnosticVMOptions -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1098'


#spark:
# ssl_enabled: True
# ssl_truststore: '/root/keys/truststore/kafka.truststore.jks'
# ssl_truststore_password: 'B1^ZRUUVoIuKND7t2HiJ8fwRg0kdMo4zdh8m8eRzgXw!'
# ssl_keystore: '/root/keys/keystore_client/kafka.keystore.jks'
# ssl_keystore_password: 'B1^ZRUUVoIuKND7t2HiJ8fwRg0kdMo4zdh8m8eRzgXw!'
# ssl_keypassword: 'B1^ZRUUVoIuKND7t2HiJ8fwRg0kdMo4zdh8m8eRzgXw!'
# auth_secret: 'B1^ZRUUVoIuKND7t2HiJ8fwRg0kdMo4zdh8m8eRzgXw!'
# redis_host: 'bnode1.deflect.ca'
# redis_password: 'B1^ZRUUVoIuKND7t2HiJ8fwRg0kdMo4zdh8m8eRzgXw!'
# app_name: 'Postprocessing'
# master: !ENV 'spark://${SPARK_MASTER_HOST}:7077'
# parallelism: -1
# log_conf: 'true'
# log_level: 'ERROR'

34 changes: 0 additions & 34 deletions containers/baskerville_dashboard/front-end/Dockerfile

This file was deleted.

26 changes: 0 additions & 26 deletions containers/baskerville_dashboard/front-end/nginx.conf

This file was deleted.

76 changes: 76 additions & 0 deletions containers/baskerville_dashboard/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
events{}
http {
include /etc/nginx/mime.types;
server {
listen 80;
server_name _;
server_name localhost;

location / {
root /var/www/baskerville_dashboard_frontend/;
index index.html;
}
location /api {
rewrite ^/api/(.*) /$1 break;
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP ip_address;
}

location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:5000/socket.io;
}
# location /api {
# rewrite ^/api/(.*) /$1 break;
# proxy_pass http://127.0.0.0:5000;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP ip_address;
# }
# location ~* \.io {
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $http_host;
# proxy_set_header X-NginX-Proxy false;
#
# proxy_pass http://127.0.0.0:5000;
# proxy_redirect off;
#
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# }

}

# server {
# listen 81;
# server_name "dashboard_backend";
# # server_name $hostname;
# location /api {
# rewrite ^/api/(.*) /$1 break;
# proxy_pass http://localhost:5000;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP ip_address;
# }
# location ~* \.io {
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $http_host;
# proxy_set_header X-NginX-Proxy false;
#
# proxy_pass http://localhost:5000;
# proxy_redirect off;
#
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# }
#
# }
# include /etc/nginx/sites.d/*.conf;
}
1 change: 1 addition & 0 deletions containers/baskerville_dashboard/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nginx && python app.py
Loading

0 comments on commit 6c60b2f

Please sign in to comment.