summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-30 17:26:19 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:44:35 +0200
commitcac980546e15882a232ce234cbde3e0cda693352 (patch)
tree50fed18858c6c5cbb11c3ecb690ebbff8bc98525
parent80730074581b8a934fb5b064a54912f620fad978 (diff)
Get Docker setup working
-rw-r--r--.gitignore9
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--Dockerfile35
-rwxr-xr-xbuild/configure.sh23
-rw-r--r--docker-compose.yml101
-rwxr-xr-xmongodb/configure.sh23
-rw-r--r--web-server/OpenDC.postman_collection.json61
-rw-r--r--web-server/main.py9
-rw-r--r--web-server/opendc/util/database.py2
9 files changed, 100 insertions, 165 deletions
diff --git a/.gitignore b/.gitignore
index e31adcb6..fc1cd81f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,15 @@
# JetBrains platform
.idea/
-# Credential setup file
-keys.json
-
# pyenv version files
.python-version
mongodb/opendc_testing/*
# macOS-specific files
.DS_Store
+
+# Environment files
+.env
+
+# Old credential setup file
+keys.json
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a90c1fb5..1f29e2fb 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,4 +1,4 @@
-# Contributing to the OpenDC Frontend
+# Contributing to OpenDC
First of all, thanks for wanting to contribute! 🎉
diff --git a/Dockerfile b/Dockerfile
index f7f36d87..fe64736e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,35 +1,26 @@
-FROM node:14.2.0
-MAINTAINER Sacheendra Talluri <sacheendra.t@gmail.com>
+FROM nikolaik/python-nodejs:python3.8-nodejs14
+MAINTAINER OpenDC Maintainers <opendc@atlarge-research.com>
-# Adding the mongodb repo and installing the client
-RUN wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add - \
- && echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.2 main" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list \
- && apt-get update \
- && apt-get install -y mongodb-org
+## Dockerfile for the frontend/server part of the deployment
-# Installing python and web-server dependencies
-RUN echo "deb http://ftp.debian.org/debian stretch main" >> /etc/apt/sources.list \
- && apt-get update \
- && apt-get install -y python3 python3-pip yarn git sed mysql-client pymongo \
- && pip3 install oauth2client eventlet flask-socketio flask-compress mysql-connector-python-rf \
- && pip3 install --upgrade pyasn1-modules \
- && rm -rf /var/lib/apt/lists/*
+# Installing packages
+RUN apt-get update \
+ && apt-get install -y yarn git sed
# Copy OpenDC directory
COPY ./ /opendc
-# Setting up simulator
-RUN pip install -e /opendc/opendc-web-server \
- && python /opendc/opendc-web-server/setup.py install \
- && chmod 555 /opendc/build/configure.sh \
- && cd /opendc/opendc-frontend \
+# Fetch web server dependencies
+RUN pip install -r /opendc/web-server/requirements.txt
+
+# Build frontend
+RUN cd /opendc/frontend \
&& rm -rf ./build \
- && rm -rf ./node_modules \
&& yarn \
- && export REACT_APP_OAUTH_CLIENT_ID=$(cat ../keys.json | python -c "import sys, json; print json.load(sys.stdin)['OAUTH_CLIENT_ID']") \
+ && export REACT_APP_OAUTH_CLIENT_ID=$OPENDC_OAUTH_CLIENT_ID \
&& yarn build
# Set working directory
WORKDIR /opendc
-CMD ["sh", "-c", "./build/configure.sh && python3 opendc-web-server/main.py keys.json"]
+CMD ["sh", "-c", "python web-server/main.py"]
diff --git a/build/configure.sh b/build/configure.sh
deleted file mode 100755
index 7dda7773..00000000
--- a/build/configure.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-if [ -z "$MONGO_DB" ]; then
- echo "MONGO_DB environment variable not specified"
- exit 1
-fi
-
-if [ -z "$MONGO_DB_USER" ]; then
- echo "MONGO_DB_USER environment variable not specified"
- exit 1
-fi
-
-if [ -z "$MONGO_DB_PASSWORD" ]; then
- echo "MONGO_DB_PASSWORD environment variable not specified"
- exit 1
-fi
-
-MONGO_COMMAND="mongo $MONGO_DB -h $MONGO_DB_HOST --port $MONGO_DB_PORT -u $MONGO_DB_USERNAME -p $MONGO_DB_PASSWORD --authenticationDatabase $MONGO_DB"
-
-until eval $MONGO_COMMAND --eval 'db.getCollectionNames();' ; do
- echo "MongoDB is unavailable - sleeping"
- sleep 1
-done
-
-echo "MongoDB available"
diff --git a/docker-compose.yml b/docker-compose.yml
index 3f4ad20a..bc2b2e25 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,78 +7,73 @@ services:
ports:
- "8081:8081"
links:
- - mariadb
+ - mongo
depends_on:
- - mariadb
+ - mongo
environment:
- - MYSQL_DATABASE=opendc
- - MYSQL_USER=opendc
- - MYSQL_PASSWORD=opendcpassword
- - MONGO_DB=opendc
- - MONGO_DB_USERNAME=opendc
- - MONGO_DB_PASSWORD=opendcpassword
- - MONGO_DB_HOST=mongo
- - MONGO_DB_PORT=27017
+ - MONGO_INITDB_ROOT_USERNAME
+ - MONGO_INITDB_ROOT_PASSWORD
+ - MONGO_INITDB_DATABASE
+ - OPENDC_DB
+ - OPENDC_DB_USERNAME
+ - OPENDC_DB_PASSWORD
+ - OPENDC_FLASK_SECRET
+ - OPENDC_OAUTH_CLIENT_ID
+ - OPENDC_ROOT_DIR
+ - OPENDC_SERVER_BASE_URL
+
+# TODO: Implement new database interaction on the simulator side
+# simulator:
+# build:
+# context: ./opendc-simulator
+# dockerfile: opendc-model-odc/setup/Dockerfile
+# image: simulator
+# restart: on-failure
+# links:
+# - mongo
+# depends_on:
+# - mongo
+# environment:
+# - PERSISTENCE_URL=jdbc:mysql://mariadb:3306/opendc
+# - PERSISTENCE_USER=opendc
+# - PERSISTENCE_PASSWORD=opendcpassword
+# - COLLECT_MACHINE_STATES=ON
+# - COLLECT_TASK_STATES=ON
+# - COLLECT_STAGE_MEASUREMENTS=OFF
+# - COLLECT_TASK_METRICS=OFF
+# - COLLECT_JOB_METRICS=OFF
- simulator:
- build:
- context: ./opendc-simulator
- dockerfile: opendc-model-odc/setup/Dockerfile
- image: simulator
- restart: on-failure
- links:
- - mariadb
- depends_on:
- - mariadb
- environment:
- - PERSISTENCE_URL=jdbc:mysql://mariadb:3306/opendc
- - PERSISTENCE_USER=opendc
- - PERSISTENCE_PASSWORD=opendcpassword
- - COLLECT_MACHINE_STATES=ON
- - COLLECT_TASK_STATES=ON
- - COLLECT_STAGE_MEASUREMENTS=OFF
- - COLLECT_TASK_METRICS=OFF
- - COLLECT_JOB_METRICS=OFF
- mariadb:
- build:
- context: ./database
- image: database
- restart: on-failure
- ports:
- - "3306:3306" # comment this line out in production
- environment:
- - MYSQL_DATABASE=opendc
- - MYSQL_USER=opendc
- - MYSQL_PASSWORD=opendcpassword
- - MYSQL_RANDOM_ROOT_PASSWORD=yes
- # uncomment in production
- # volumes:
- # - "/data/mariadb:/var/lib/mysql"
mongo:
build:
context: ./mongodb
restart: on-failure
environment:
- - MONGO_INITDB_ROOT_USERNAME=root
- - MONGO_INITDB_ROOT_PASSWORD=rootpassword
- - MONGO_INITDB_DATABASE=admin
- - OPENDC_DB=opendc
- - OPENDC_DB_USERNAME=opendc
- - OPENDC_DB_PASSWORD=opendcpassword
+ - MONGO_INITDB_ROOT_USERNAME
+ - MONGO_INITDB_ROOT_PASSWORD
+ - MONGO_INITDB_DATABASE
+ - OPENDC_DB
+ - OPENDC_DB_USERNAME
+ - OPENDC_DB_PASSWORD
+ # Comment out for public deployment
ports:
- 27017:27017
+ # Uncomment for persistent deployment
#volumes:
# - mongo-volume:/data/db
mongo-express:
image: mongo-express
restart: on-failure
+ links:
+ - mongo
+ depends_on:
+ - mongo
ports:
- 8082:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME: root
- ME_CONFIG_MONGODB_ADMINPASSWORD: rootpassword
+ ME_CONFIG_MONGODB_ADMINUSERNAME: "${MONGO_INITDB_ROOT_USERNAME}"
+ ME_CONFIG_MONGODB_ADMINPASSWORD: "${MONGO_INITDB_ROOT_PASSWORD}"
volumes:
mongo-volume:
- external: false \ No newline at end of file
+ external: false
diff --git a/mongodb/configure.sh b/mongodb/configure.sh
new file mode 100755
index 00000000..78f28ac8
--- /dev/null
+++ b/mongodb/configure.sh
@@ -0,0 +1,23 @@
+if [ -z "$OPENDC_DB" ]; then
+ echo "OPENDC_DB environment variable not specified"
+ exit 1
+fi
+
+if [ -z "$OPENDC_DB_USERNAME" ]; then
+ echo "OPENDC_DB_USERNAME environment variable not specified"
+ exit 1
+fi
+
+if [ -z "$OPENDC_DB_PASSWORD" ]; then
+ echo "OPENDC_DB_PASSWORD environment variable not specified"
+ exit 1
+fi
+
+MONGO_COMMAND="mongo $OPENDC_DB -u $OPENDC_DB_USERNAME -p $OPENDC_DB_PASSWORD --authenticationDatabase $OPENDC_DB"
+
+until eval $MONGO_COMMAND --eval 'db.getCollectionNames();' ; do
+ echo "MongoDB is unavailable - sleeping"
+ sleep 1
+done
+
+echo "MongoDB available"
diff --git a/web-server/OpenDC.postman_collection.json b/web-server/OpenDC.postman_collection.json
deleted file mode 100644
index c34dc310..00000000
--- a/web-server/OpenDC.postman_collection.json
+++ /dev/null
@@ -1,61 +0,0 @@
-{
- "variables": [],
- "info": {
- "name": "OpenDC",
- "_postman_id": "e8b68f59-29cb-71d0-6237-b22932c40f9c",
- "description": "Sample requests for developing the OpenDC API",
- "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
- },
- "item": [
- {
- "name": "Create New Simulation",
- "request": {
- "url": "localhost:8081/api/v1/simulations",
- "method": "POST",
- "header": [
- {
- "key": "Content-Type",
- "value": "application/json",
- "description": ""
- },
- {
- "key": "auth-token",
- "value": "PUT YOUR AUTH TOKEN HERE",
- "description": ""
- }
- ],
- "body": {
- "mode": "raw",
- "raw": "{\r\n \"simulation\": {\r\n \"name\": \"Simulation Name\"\r\n }\r\n}"
- },
- "description": ""
- },
- "response": []
- },
- {
- "name": "Create New User",
- "request": {
- "url": "localhost:8081/api/v1/users",
- "method": "POST",
- "header": [
- {
- "key": "Content-Type",
- "value": "application/json",
- "description": ""
- },
- {
- "key": "auth-token",
- "value": "PUT YOUR AUTH TOKEN HERE",
- "description": ""
- }
- ],
- "body": {
- "mode": "raw",
- "raw": "{\r\n \"user\": {\r\n \"email\": \"email@example.com\"\r\n }\r\n}"
- },
- "description": ""
- },
- "response": []
- }
- ]
-} \ No newline at end of file
diff --git a/web-server/main.py b/web-server/main.py
index 6d2f8747..94696e8d 100644
--- a/web-server/main.py
+++ b/web-server/main.py
@@ -15,17 +15,24 @@ from opendc.util.exceptions import AuthorizationTokenError, RequestInitializatio
TEST_MODE = "OPENDC_FLASK_TESTING" in os.environ
+# Specify the directory of static assets
if TEST_MODE:
STATIC_ROOT = os.curdir
else:
+ STATIC_ROOT = os.path.join(os.environ['OPENDC_ROOT_DIR'], 'frontend', 'build')
+
+# Set up database if not testing
+if not TEST_MODE:
database.DB.initialize_database(user=os.environ['OPENDC_DB_USERNAME'],
password=os.environ['OPENDC_DB_PASSWORD'],
database=os.environ['OPENDC_DB'],
host='localhost')
- STATIC_ROOT = os.path.join(os.environ['OPENDC_ROOT_DIR'], 'opendc-frontend', 'build')
+# Set up the core app
FLASK_CORE_APP = Flask(__name__, static_url_path='', static_folder=STATIC_ROOT)
FLASK_CORE_APP.config['SECRET_KEY'] = os.environ['OPENDC_FLASK_SECRET']
+
+# Set up CORS support for local setups
if 'localhost' in os.environ['OPENDC_SERVER_BASE_URL']:
CORS(FLASK_CORE_APP)
diff --git a/web-server/opendc/util/database.py b/web-server/opendc/util/database.py
index 12d6afc9..0402c2e1 100644
--- a/web-server/opendc/util/database.py
+++ b/web-server/opendc/util/database.py
@@ -14,7 +14,7 @@ class Database:
def __init__(self):
self.opendc_db = None
- def init_database(self, user, password, database, host):
+ def initialize_database(self, user, password, database, host):
"""Initializes the database connection."""
user = urllib.parse.quote_plus(user)