diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..1bca7f4e6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +# syntax=docker/dockerfile:1.5-labs + +FROM node AS ui +# ref syntax: https://docs.docker.com/engine/reference/commandline/image_build/#git-repositories +ADD https://github.com/cairis-platform/cairis-ui.git /ui +WORKDIR /ui + +ENV NODE_OPTIONS=--openssl-legacy-provider + +RUN yarn install --immutable --immutable-cache --check-cache +RUN yarn run build + + +FROM python:3-slim +LABEL org.opencontainers.image.authors="admin@cairis.org" +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + pkg-config `# mysql` \ + default-libmysqlclient-dev `# mysql` \ + apache2 `# wsgi` \ + apache2-dev `# wsgi` \ + default-mysql-client `# init sql file imports` \ + docbook `# latex` \ + docbook-utils `# latex` \ + dblatex `# latex` \ + texlive-latex-extra `# latex` \ + pandoc `# latex` \ + graphviz `# TODO: unknown` \ + libxml2-dev `# TODO: unknown` \ + libxslt1-dev `# TODO: unknown` \ + libssl-dev `# TODO: unknown` \ + poppler-utils `# TODO: unknown` \ + && rm -rf /var/lib/apt/lists/* + +RUN --mount=type=bind,source=requirements.txt,target=/tmp/requirements.txt \ + pip install --requirement /tmp/requirements.txt + +RUN --mount=type=bind,source=wsgi_requirements.txt,target=/tmp/wsgi_requirements.txt \ + pip install --requirement /tmp/wsgi_requirements.txt + +# config is autogenerated +ENV CAIRIS_CFG=/tmp/cairis.cnf +COPY entrypoint.py / + +COPY ./examples /examples + +COPY --from=ui /ui/dist /cairis-ui + +# Using /cairis instead of /app/cairis, as it is less confusing. Symlink is for out-of-band tools (through docker exec) +ENV PYTHONPATH=/cairis +COPY ./cairis /cairis +RUN ln -s . /cairis/cairis + +EXPOSE 8000 +USER www-data:www-data +CMD ["python3", "/entrypoint.py"] diff --git a/cairis/config/cairis.cnf b/cairis/config/cairis.cnf index 85c2eef64..e62d87e93 100644 --- a/cairis/config/cairis.cnf +++ b/cairis/config/cairis.cnf @@ -9,4 +9,3 @@ default_image_dir = . web_port = 7071 log_level = warning web_static_dir = /home/cairisuser/cairis/cairis/web -upload_dir = /tmp diff --git a/cairis/core/BorgFactory.py b/cairis/core/BorgFactory.py index 1cb8849b3..0fd87279f 100644 --- a/cairis/core/BorgFactory.py +++ b/cairis/core/BorgFactory.py @@ -57,7 +57,6 @@ def initialiseCairisDbSettings(cfgDict): b.tmpDir = cfgDict['tmp_dir'] b.cairisRoot = cfgDict['root'] b.rPasswd = '' - b.docker = True if 'docker' in cfgDict else False try: b.rPasswd = cfgDict['rpasswd'] @@ -67,7 +66,7 @@ def initialiseCairisDbSettings(cfgDict): def setupDocBookConfig(): b = Borg() b.docBookDir = 'http://www.docbook.org/sgml/4.5' - if os.path.exists('/usr/share/sgml/docbook/dtd/4.5') or b.docker: + if os.path.exists('/usr/share/sgml/docbook/dtd/4.5'): b.docBookDir = '/usr/share/sgml/docbook/dtd/4.5' else: b.logger.warning('Unable to find DocBook schemes. Check if DocBook is correctly installed.') diff --git a/cairis/misc/DocumentBuilder.py b/cairis/misc/DocumentBuilder.py index 1eee76780..37e7e7877 100755 --- a/cairis/misc/DocumentBuilder.py +++ b/cairis/misc/DocumentBuilder.py @@ -2396,10 +2396,4 @@ def build(dbProxy,docType,sectionFlags,typeFlags,fileName,docDir): f.write(specDoc) f.close() - - b = Borg() - if(b.docker == True): - requestString = "http://cairis-docs:5000/latexApi" - requests.post(requestString, data={'docBookCmd': docBookCmd}) - else: - os.system(docBookCmd) + os.system(docBookCmd) diff --git a/cairis/tools/quickSetup.py b/cairis/tools/quickSetup.py index 66bb9d116..a656b0cff 100755 --- a/cairis/tools/quickSetup.py +++ b/cairis/tools/quickSetup.py @@ -17,54 +17,76 @@ # specific language governing permissions and limitations # under the License. -from cairis.core.ARM import ARMException -from sqlalchemy.exc import SQLAlchemyError +import binascii import os import sys -from cairis.core.dba import createDatabaseAccount, createDbOwnerDatabase, createDatabaseAndPrivileges, createDatabaseSchema, createDefaults, canonicalDbUser, dropCairisUserDatabase, createCairisUserDatabase -from flask_security import hash_password -import binascii from random import choice from string import ascii_letters, digits -from subprocess import Popen -from shlex import split +from flask_security import hash_password + +from cairis.core.ARM import ARMException +from cairis.core.dba import ( + canonicalDbUser, + createCairisUserDatabase, + createDatabaseAccount, + createDatabaseAndPrivileges, + createDatabaseSchema, + createDbOwnerDatabase, + createDefaults, + dropCairisUserDatabase, +) __author__ = 'Shamal Faily' +def validate_username(userName: str): + if userName == "": + return -def quick_setup(dbHost,dbPort,dbRootPassword,tmpDir,rootDir,configFile,webPort,logLevel,staticDir,assetDir,userName,passWd,mailServer = '',mailPort = '',mailUser = '',mailPasswd = ''): - if (len(userName) > 255): - raise ARMException("Username cannot be longer than 255 characters") if (userName == "root"): raise ARMException("Username cannot be root") + + if (len(userName) > 255): + raise ARMException("Username cannot be longer than 255 characters") + +def inject_bashrc(rootDir: str, configFile: str): + fileName = os.environ.get("HOME") + "/.bashrc" + + if not os.path.exists(fileName): + return + + with open(fileName,'a') as f: + f.write("export CAIRIS_SRC="+ rootDir + "\n") + f.write("export CAIRIS_CFG_DIR=${CAIRIS_SRC}/config\n") + f.write("export CAIRIS_CFG="+ configFile +"\n") + + pathName = os.path.split(os.path.split(os.path.realpath(os.path.dirname(__file__)))[0])[0] + sys.path.insert(0, pathName) + + f.write("export PYTHONPATH=${PYTHONPATH}:" + pathName +"\n") + +def quick_setup(dbHost,dbPort,dbRootPassword,tmpDir,rootDir,configFile,webPort,logLevel,staticDir,assetDir,userName,passWd,mailServer = '',mailPort = '',mailUser = '',mailPasswd = ''): createCairisCnf(configFile,dbRootPassword,dbHost,dbPort,tmpDir,rootDir,webPort,logLevel,staticDir,assetDir,mailServer,mailPort,mailUser,mailPasswd) - os.environ["CAIRIS_CFG"] = configFile + + import MySQLdb + with MySQLdb.connect(host=dbHost,user='root',passwd=dbRootPassword) as con: + with con.cursor() as cur: + if cur.execute('SHOW DATABASES LIKE "cairis_owner"') == 1: + return + + validate_username(userName) + createDbOwnerDatabase(dbRootPassword,dbHost,dbPort) createUserDatabase(dbHost,dbPort,dbRootPassword,rootDir) - pathName = os.path.split(os.path.split(os.path.realpath(os.path.dirname(__file__)))[0])[0] - sys.path.insert(0, pathName) - fileName = os.environ.get("HOME") + "/.bashrc" - f = open(fileName,'a') - f.write("export CAIRIS_SRC="+ rootDir + "\n") - f.write("export CAIRIS_CFG_DIR=${CAIRIS_SRC}/config\n") - f.write("export CAIRIS_CFG="+ configFile +"\n") - f.write("export PYTHONPATH=${PYTHONPATH}:" + pathName +"\n") - f.close() - - from cairis.bin.add_cairis_user import user_datastore,db + + os.environ["CAIRIS_CFG"] = configFile + from cairis.bin.add_cairis_user import db db.create_all() - if (userName != ''): - rp = ''.join(choice(ascii_letters + digits) for i in range(255)) - dbAccount = canonicalDbUser(userName) - user_datastore.create_user(email=userName, account=dbAccount, password=hash_password(passWd),name = 'Default user') - db.session.commit() - createDatabaseAccount(dbRootPassword,dbHost,dbPort,userName,dbAccount,rp) - createDatabaseAndPrivileges(dbRootPassword,dbHost,dbPort,userName,rp,dbAccount + '_default') - createDatabaseSchema(rootDir,dbHost,dbPort,userName,rp,dbAccount + '_default') - createDefaults(rootDir,dbHost,dbPort,userName,rp,dbAccount + '_default') + if userName: + createUser(rootDir, dbRootPassword, dbHost, dbPort, userName, passWd) + inject_bashrc(rootDir, configFile) def createUserDatabase(dbHost,dbPort,dbRootPassword,rootDir): dropCairisUserDatabase(dbRootPassword,dbHost,dbPort) @@ -73,23 +95,33 @@ def createUserDatabase(dbHost,dbPort,dbRootPassword,rootDir): createDatabaseAndPrivileges(dbRootPassword,dbHost,dbPort,'cairis_test','cairis_test','cairis_test_default') createDatabaseSchema(rootDir,dbHost,dbPort,'cairis_test','cairis_test','cairis_test_default') +def createUser(rootDir,dbRootPassword,dbHost,dbPort,userName,passWd): + from cairis.bin.add_cairis_user import db, user_datastore + + rp = ''.join(choice(ascii_letters + digits) for i in range(255)) + dbAccount = canonicalDbUser(userName) + user_datastore.create_user(email=userName, account=dbAccount, password=hash_password(passWd),name = 'Default user') + db.session.commit() + createDatabaseAccount(dbRootPassword,dbHost,dbPort,userName,dbAccount,rp) + createDatabaseAndPrivileges(dbRootPassword,dbHost,dbPort,userName,rp,dbAccount + '_default') + createDatabaseSchema(rootDir,dbHost,dbPort,userName,rp,dbAccount + '_default') + createDefaults(rootDir,dbHost,dbPort,userName,rp,dbAccount + '_default') def createCairisCnf(configFile,dbRootPassword,dbHost,dbPort,tmpDir,rootDir,webPort,logLevel,staticDir,assetDir,mailServer,mailPort,mailUser,mailPasswd): - f = open(configFile,'w') - f.write("rpasswd = " + dbRootPassword + "\n") - f.write("dbhost = " + dbHost + "\n") - f.write("dbport = " + str(dbPort) + "\n") - f.write("tmp_dir = " + tmpDir + "\n") - f.write("root = " + rootDir + "\n") - f.write("web_port = " + str(webPort) + "\n") - f.write("log_level = " + logLevel + "\n") - f.write("web_static_dir = " + staticDir + "\n") - f.write("web_asset_dir = " + assetDir + "\n") - f.write("mail_server = " + mailServer + "\n") - f.write("mail_port = " + mailPort + "\n") - f.write("mail_user = " + mailUser + "\n") - f.write("mail_passwd = " + mailPasswd + "\n") - - f.write("\n") - f.write("secret_key = " + str(binascii.hexlify(os.urandom(16))) + "\n") - f.close() + with open(configFile,'w') as f: + f.write("rpasswd = " + dbRootPassword + "\n") + f.write("dbhost = " + dbHost + "\n") + f.write("dbport = " + str(dbPort) + "\n") + f.write("tmp_dir = " + tmpDir + "\n") + f.write("root = " + rootDir + "\n") + f.write("web_port = " + str(webPort) + "\n") + f.write("log_level = " + logLevel + "\n") + f.write("web_static_dir = " + staticDir + "\n") + f.write("web_asset_dir = " + assetDir + "\n") + f.write("mail_server = " + mailServer + "\n") + f.write("mail_port = " + mailPort + "\n") + f.write("mail_user = " + mailUser + "\n") + f.write("mail_passwd = " + mailPasswd + "\n") + + f.write("\n") + f.write("secret_key = " + str(binascii.hexlify(os.urandom(16))) + "\n") diff --git a/compose.yml b/compose.yml new file mode 100644 index 000000000..d11da81f9 --- /dev/null +++ b/compose.yml @@ -0,0 +1,43 @@ +networks: + cairis: + internal: true + portsHatch: # only needed for ports + +services: + cairis-db: + image: 'mariadb:latest' + environment: + - MYSQL_ROOT_PASSWORD=changeme1 # changeme + command: > + --thread_stack=256K + --max_sp_recursion_depth=255 + --log_bin_trust_function_creators=1 + volumes: [cairis-db:/var/lib/mysql] + networks: [cairis] + healthcheck: + test: ["CMD", "healthcheck.sh", "--su=mysql", "--connect", "--innodb_initialized"] + cairis: + image: shamalfaily/cairis + build: . # comment this to pull image + environment: + - MYSQL_HOST=cairis-db + - MYSQL_ROOT_PASSWORD=changeme1 # changeme + # - CAIRIS_LOGLEVEL=DEBUG + # - CAIRIS_SMTP_SERVER= + # - CAIRIS_SMTP_PORT=465 + # - CAIRIS_SMTP_USER= + # - CAIRIS_SMTP_PASS= + # only applied on first run (database generation): + - CAIRIS_USER=example@example.tld + - CAIRIS_PASS=changeme2 + networks: + - cairis + - portsHatch + ports: + - 8000:8000 + depends_on: + cairis-db: + condition: service_healthy + +volumes: + cairis-db: diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 4e600e7ee..000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,63 +0,0 @@ -FROM ubuntu:latest -MAINTAINER Shamal Faily -ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get update -RUN apt-get install -y build-essential \ - python3-dev \ - mysql-client \ - graphviz \ - python3-pip \ - python3-numpy \ - python3-mysqldb \ - git \ - default-libmysqlclient-dev \ - python3-apt \ - libxml2-dev \ - libxslt1-dev \ - libssl-dev \ - apache2 \ - apache2-dev \ - poppler-utils \ - python3-setuptools \ - apt-transport-https \ - ca-certificates - -RUN pip3 install wheel -#Installing Python modules -COPY requirements.txt / -RUN pip3 install -r requirements.txt -COPY wsgi_requirements.txt / -RUN pip3 install -r wsgi_requirements.txt - -#Environment Variable starts from here -ENV CAIRIS_SRC=/cairis/cairis -ENV CAIRIS_CFG_DIR=/cairis/docker -ENV CAIRIS_CFG=/cairis.cnf -ENV PYTHONPATH=/cairis - -RUN mkdir /tmpDocker -RUN mkdir /images - -#Clonning the repo -RUN git clone --depth 1 -b master https://github.com/cairis-platform/cairis /cairis -#creating folder here and moving the files and folder - -RUN mkdir /cairisTmp &&\ - mv /cairis/cairis /cairisTmp/cairis &&\ - rm -rf /cairis/ &&\ - mv /cairisTmp/ /cairis/ - -COPY cairis.cnf / -COPY setupDb.sh / -COPY createdb.sql / -COPY addAccount.sh / -COPY register_user.html /cairis/cairis/daemon/templates/security - -RUN /cairis/cairis/bin/installUI.sh - -EXPOSE 8000 - -RUN apt-get remove --purge -y git -RUN apt-get autoremove -y - -CMD ["./setupDb.sh"] diff --git a/docker/addAccount.sh b/docker/addAccount.sh deleted file mode 100755 index 44aebecfd..000000000 --- a/docker/addAccount.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -export CAIRIS_SRC=/cairis/cairis -export PYTHONPATH=/cairis -export CAIRIS_CFG=/cairis.cnf - -USERNAME=$1 -PASSWD=$2 -FULLNAME=$3 - -$CAIRIS_SRC/bin/add_cairis_user.py $USERNAME $PASSWD $FULLNAME diff --git a/docker/buildDemo.sh b/docker/buildDemo.sh deleted file mode 100755 index 800f5b900..000000000 --- a/docker/buildDemo.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -set -x - -export REPOS_DIR=/tmp -export CAIRIS_REPO=$REPOS_DIR/cairis - -rm -rf $CAIRIS_REPO - -git clone http://github.com/cairis-platform/cairis $CAIRIS_REPO - -sudo docker stop CAIRIS -sudo docker stop cairis-mysql -sudo docker rm $(sudo docker ps -aq) -sudo docker rmi $(sudo docker images -q) -sudo docker volume rm $(docker volume ls) -sudo docker run --name cairis-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest --thread_stack=512K -sudo docker run --name cairis-docs -d -v cairisDocumentation:/tmpDocker -v cairisImage:/images -t shamalfaily/cairis-docs -sudo docker run --name CAIRIS -d --link cairis-mysql:mysql --link cairis-docs:docs -P -p 80:8000 --net=bridge -v cairisDocumentation:/tmpDocker -v cairisImage:/images shamalfaily/cairis - -sleep 60 - -# Make sure the requests and argparse packages are installed before running model_import_web.py or web_cimport.py. -$CAIRIS_REPO/cairis/bin/model_import_web.py --url http://localhost --database NeuroGrid $CAIRIS_REPO/examples/exemplars/NeuroGrid.cairis -$CAIRIS_REPO/cairis/bin/model_import_web.py --url http://localhost --database ACME_Water $CAIRIS_REPO/examples/exemplars/ACME_Water.cairis -$CAIRIS_REPO/cairis/bin/model_import_web.py --url http://localhost --database webinos $CAIRIS_REPO/examples/exemplars/webinos.cairis diff --git a/docker/cairis.cnf b/docker/cairis.cnf deleted file mode 100644 index 0fb3e346f..000000000 --- a/docker/cairis.cnf +++ /dev/null @@ -1,15 +0,0 @@ -dbhost = cairis-mysql -dbport = 3306 -rpasswd = my-secret-pw -tmp_dir = /tmpDocker -root = /cairis/cairis -web_port = 8000 -log_level = debug -web_static_dir = /cairis/cairis/dist -web_asset_dir = /cairis/cairis/dist -mail_server = -mail_port = -mail_user = -mail_passwd = -secret_key = super-secret -docker = True diff --git a/docker/cmd.sh b/docker/cmd.sh deleted file mode 100755 index e2caaf510..000000000 --- a/docker/cmd.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -mod_wsgi-express start-server /cairis/cairis/bin/cairis.wsgi --user www-data --group www-data diff --git a/docker/createdb.sql b/docker/createdb.sql deleted file mode 100644 index a26cad6ef..000000000 --- a/docker/createdb.sql +++ /dev/null @@ -1,23 +0,0 @@ -drop database if exists `cairis_user`; -create database if not exists `cairis_user`; -create table cairis_user.db_token(email varchar(255), token varchar(255), primary key(email)) engine=innodb; - -drop database if exists `cairis_owner`; -create database if not exists `cairis_owner`; -create table cairis_owner.db_owner(db varchar(64), owner varchar(32), primary key(db,owner)) engine=innodb; - -drop user if exists cairis_test; -create user if not exists 'cairis_test'@'%' identified by 'cairis_test'; -grant usage on `cairis_test`.* to 'cairis_test'@'%'; -flush privileges; - -drop database if exists `cairis_test_default`; -create database if not exists `cairis_test_default`; -grant all privileges on `cairis_test_default`.* to 'cairis_test'@'%'; -set global max_sp_recursion_depth = 255; - -alter database cairis_test_default default character set utf8mb4; -alter database cairis_test_default default collate utf8mb4_general_ci; - -flush tables; -flush privileges; diff --git a/docker/register_user.html b/docker/register_user.html deleted file mode 100644 index 9993ec105..000000000 --- a/docker/register_user.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - -{% extends "security/base.html" %} -{% from "security/_macros.html" import render_field_with_errors, render_field, render_form_errors %} - -{% block content %} -{% include "security/_messages.html" %} -
-
-

{{ _fsdomain('Register CAIRIS user') }}

- {{ register_user_form.hidden_tag() }} - {{ render_form_errors(register_user_form) }} - {{ render_field_with_errors(register_user_form.email) }} - {{ render_field_with_errors(register_user_form.password) }} - {% if register_user_form.password_confirm %} - {{ render_field_with_errors(register_user_form.password_confirm) }} - {% endif %} - {{ render_field(register_user_form.submit) }} -
-
-{% endblock %} diff --git a/docker/requirements.txt b/docker/requirements.txt deleted file mode 100644 index 1129cb3a3..000000000 --- a/docker/requirements.txt +++ /dev/null @@ -1,30 +0,0 @@ -argparse>=1.4.0 -coveralls>=1.1 -coverage>=4.2 -jsonpickle>=0.9.3 -mysqlclient>=1.4.4 -numpy>=1.6.2 -pyparsing>=2.1.10 -pydot>=1.2.3 -pytest>=3.0.3 -pytest-cache>=1.0 -pytest-cov>=2.4.0 -pytest-pep8>=1.0.6 -npyscreen>= 4.10.5 -Flask>=1.0.2 -Flask-RESTful>= 0.3.5 -flask-restful-swagger>= 0.19 -Flask-Cors>= 3.0.2 -Flask-SQLAlchemy>=2.5.1 -Flask-Security-Too>=5.1.0 -Flask-Script>=2.0.6 -Flask-OAuthlib>=0.9.3 -Flask-Mail>=0.9.1 -mako>=1.0.4 -lxml>=3.6.4 -openpyxl>=2.4.0 -SQLAlchemy>=2.0.0 -bcrypt>=3.1.6 -python-magic>=0.4.15 -email_validator>=1.0.5 -xlsxwriter>=1.2.7 diff --git a/docker/setupDb.sh b/docker/setupDb.sh deleted file mode 100755 index 618cbbf8f..000000000 --- a/docker/setupDb.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -set -x -mysql -h cairis-mysql --user=root --password=my-secret-pw < createdb.sql -mysql -h cairis-mysql --user=cairis_test --password=cairis_test --database=cairis_test_default < $CAIRIS_SRC/sql/init.sql -mysql -h cairis-mysql --user=cairis_test --password=cairis_test --database=cairis_test_default < $CAIRIS_SRC/sql/procs.sql -mysql -h cairis-mysql --user=root --password=my-secret-pw <=2.4.27.1 -mod_wsgi>=4.5.22 diff --git a/dockerLaTeX/Dockerfile b/dockerLaTeX/Dockerfile deleted file mode 100644 index b613e725d..000000000 --- a/dockerLaTeX/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -FROM python:3.6-slim - -RUN apt-get update -RUN apt-get install -y docbook -RUN apt-get install -y docbook-utils -RUN apt-get install -y dblatex -RUN apt-get install -y texlive-latex-extra -RUN apt-get install -y inkscape -RUN apt-get install -y pandoc -RUN apt-get install -y git -RUN apt-get install -y python3-pip - -RUN pip3 install Flask -RUN mkdir /latex -COPY LaTeXApi.py /latex -RUN touch __init__.py -RUN git clone --depth 1 -b master https://github.com/cairis-platform/cairis /cairis - -RUN mkdir -p /cairisTmp/cairis -RUN mv /cairis/cairis/config /cairisTmp/cairis -RUN mv /cairis/cairis/core/armid.py /latex/armid.py -RUN rm -rf /cairis -RUN mv /cairisTmp /cairis - -RUN apt-get remove --purge -y git -RUN apt-get autoremove -y - -EXPOSE 5000 - -CMD ["./latex/LaTeXApi.py"] diff --git a/dockerLaTeX/LaTeXApi.py b/dockerLaTeX/LaTeXApi.py deleted file mode 100755 index a974a61a0..000000000 --- a/dockerLaTeX/LaTeXApi.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3.6 -from flask import Flask, request, abort -from armid import * -import os - - -app = Flask(__name__) - - -@app.route('/latexApi', methods=['POST']) -def index(): - try: - dockBookCmd = request.values.get('docBookCmd') - os.system(dockBookCmd) - return "Success" - except: - abort(500) - - -if __name__ == '__main__': - app.run(host="0.0.0.0", debug=True) diff --git a/docs/install.rst b/docs/install.rst index 05c85254f..c5fdd85f5 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -43,73 +43,39 @@ Installation via Docker If you have Docker installed on your laptop or an available machine, you can download the CAIRIS container from `Docker hub `_. Like the live demo, this is built from the latest version of CAIRIS in GitHub, and uses `mod_wsgi-express `_ to deliver the CAIRIS web services. -There are two options for running the container, a full install of everything or a smaller install which doesn't provide pdf export functionality: - -For the full install (with pdf export functionality) download and run the container, the documentation container, and its linked mysql container: +Download and run the container, and its linked mysql container: .. code-block:: bash - - sudo docker run --name cairis-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest --thread_stack=256K --max_sp_recursion_depth=255 --log_bin_trust_function_creators=1 - sudo docker run --name cairis-docs -d -v cairisDocumentation:/tmpDocker -v cairisImage:/images -t shamalfaily/cairis-docs - sudo docker run --name CAIRIS -d --link cairis-mysql:mysql --link cairis-docs:docs -P -p 80:8000 --net=bridge -v cairisDocumentation:/tmpDocker -v cairisImage:/images shamalfaily/cairis -For the smaller install (without pdf export functionality) download and run the container, and its linked mysql container: + docker compose up -d -.. code-block:: bash - - sudo docker run --name cairis-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest --thread_stack=256K --max_sp_recursion_depth=255 --log_bin_trust_function_creators=1 - sudo docker run --name CAIRIS --link cairis-mysql:mysql -d -P -p 80:8000 --net=bridge shamalfaily/cairis +If you want to use the containers to support account self-registration and revocation then you can set *MAIL_\** environment variables in *compose.yml* to correspond with the SSL outgiong mail server, mail server port, mail account username, and password for the mail account, i.e. -If you run the above commands on macOS (and possibly other non-Linux platformns), you might get the error *links are only supported for user-defined networks*. If so, you should instead run the below commands to download and run your containers: +Populate the instance with examples: .. code-block:: bash - - NET=cairisnet - docker network create -d bridge $NET - docker run --name cairis-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest --thread_stack=256K --max_sp_recursion_depth=255 --log_bin_trust_function_creators=1 - docker network connect $NET cairis-mysql - docker run --name CAIRIS -d -P -p 80:8000 --net=$NET shamalfaily/cairis -If you want to use the containers to support account self-registration and revocation then you can set MAIL_SERVER, MAIL_PORT, MAIL_USER, and MAIL_PASSWD environment variables to correspond with the SSL outgiong mail server, mail server port, mail account username, and password for the mail account, i.e. - -.. code-block:: bash + docker compose exec cairis python3 /cairis/bin/model_import_web.py --url http://localhost --database NeuroGrid /examples/exemplars/NeuroGrid.cairis + docker compose exec cairis python3 /cairis/bin/model_import_web.py --url http://localhost --database ACME_Water /examples/exemplars/ACME_Water.cairis + docker compose exec cairis python3 /cairis/bin/model_import_web.py --url http://localhost --database webinos /examples/exemplars/webinos.cairis - docker run --name CAIRIS --env MAIL_SERVER=mymailserver.com --env MAIL_PORT=465 --env MAIL_USER=admin@mymailserver.com --env MAIL_PASSWD=mypassword -d -P -p 80:8000 --net=$NET shamalfaily/cairis - -The *docker run* commands will create and start-up CAIRIS. If you haven't setup account self-registration then you will need to create an account before you can use it. To do this, run the below command - replacing test@test.com and test with your desired username and password. +If you haven't setup account self-registration, you will need to create an account before you can use it: .. code-block:: bash - docker exec -t `docker ps | grep shamalfaily/cairis | head -1 | cut -d ' ' -f 1` /addAccount.sh test@test.com test TestUser - -If you are using PowerSheell on Windows to run the above command then this might fail because *grep* is not installed. To work around this, you need to use *docker ps* to get the Container ID and run the below modified command: - - -.. code-block:: bash - - docker exec -t CONTAINER_ID /addAccount.sh test@test.com test TestUser - -Once the containers have been installed then, in the future, you should use *docker start* rather than *docker run* to start up the already downloaded containers. - -.. code-block:: bash - - sudo docker start cairis-mysql - sudo docker start CAIRIS + docker compose exec cairis python3 /cairis/bin/add_cairis_user.py test@test.com test TestUser The containers can be stopped using *docker stop*, i.e. .. code-block:: bash - sudo docker stop CAIRIS - sudo docker stop cairis-mysql + docker compose down -To update your docker containers, stop the docker containers and run the below commands to remove any old containers and volume files. Following that, you can re-run the above *docker run* commands to install and run the container. Don't forget to re-add your user account! +To update your docker containers, build or pull them: .. code-block:: bash - sudo docker rm $(sudo docker ps -aq) - sudo docker rmi --force $(sudo docker images -q) - sudo docker volume rm $(docker volume ls) + docker compose up -d --build --pull=always Installation and configuration via GitHub (automated) diff --git a/entrypoint.py b/entrypoint.py new file mode 100644 index 000000000..1e9822c9a --- /dev/null +++ b/entrypoint.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 + +# Essentially the same as quick_setup.py, quick_setup_headless.py and server_setup_headless.py + +import os +import subprocess +import sys +import traceback + +import cairis.tools.quickSetup as qs + +dockerConf = os.environ.get('CAIRIS_CFG') + +def init(args=None): + # TODO: MYSQL_* should be replaced with URI in the codebase. + if os.environ.get('MYSQL_PORT', 3306) != 3306: + raise NotImplementedError('Changing MYSQL_PORT aka dbport is not fully supported and will break the installation.') + if os.environ.get('MYSQL_USER', 'root') != 'root': + raise NotImplementedError('Changing MYSQL_USER aka dbUser to non-root user is not supported.') + + if os.path.exists(dockerConf): + os.remove(dockerConf) + + qs.quick_setup( + os.environ.get('MYSQL_HOST'), + 3306, + os.environ.get('MYSQL_ROOT_PASSWORD'), + os.environ.get('CAIRIS_TMP', "/tmp"), + '/cairis', + dockerConf, + 8000, + os.environ.get('CAIRIS_LOGLEVEL', "INFO"), + '/cairis-ui', '/cairis-ui', + os.environ.get('CAIRIS_USER', ''), os.environ.get('CAIRIS_PASS', ''), + os.environ.get('CAIRIS_SMTP_SERVER', ''), os.environ.get('CAIRIS_SMTP_PORT', '465'), + os.environ.get('CAIRIS_SMTP_USER', ''), os.environ.get('CAIRIS_SMTP_PASS', '') + ) + +def main(args=None): + try: + init() + except: # noqa: E722 + traceback.print_exc() + sys.exit(1) + + subprocess.run(["mod_wsgi-express", "start-server", "/cairis/bin/cairis.wsgi"]) + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt index 671976a10..f57e44852 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,29 +1,31 @@ -argparse>=1.4.0 -pytest-cov>=2.7.1 -coveralls>=1.4.0 +bcrypt>=3.1.6,!=4.1.* # https://github.com/pyca/bcrypt/issues/684 coverage>=4.5.1 +coveralls>=1.4.0 +Flask>=2.2.2 +Flask-Cors>=3.0.10 +Flask-Mail>=0.9.1 +Flask-OAuthlib>=0.9.6 +Flask-RESTful>= 0.3.9 +Flask-Script>=2.0.6 +Flask-Security-Too>=5.1.0 +Flask-SQLAlchemy>=2.5.1 jsonpickle>=0.9.3 +lxml>=3.6.4 +mako>=1.0.4 mysqlclient>=1.4.4 +npyscreen>= 4.10.5 numpy>=1.6.2 -pyparsing>=2.1.10 +openpyxl>=2.4.0 pydot>=1.2.3 -pytest>=3.3.0 +pyparsing>=2.1.10 pytest-cache>=1.0 +pytest-cov>=2.7.1 pytest-pep8>=1.0.6 -npyscreen>= 4.10.5 -Flask>=2.2.2 -Flask-RESTful>= 0.3.9 -Flask-Cors>= 3.0.10 -Flask-SQLAlchemy>=2.5.1 -Flask-Security-Too>=5.1.0 -Flask-Script>=2.0.6 -Flask-OAuthlib>=0.9.6 -Flask-Mail>=0.9.1 -mako>=1.0.4 -lxml>=3.6.4 -openpyxl>=2.4.0 -SQLAlchemy>=2.0.0 -bcrypt>=3.1.6 +pytest>=3.3.0 python-magic>=0.4.15 +Requests>=2.31.0 # added by pipreqs 2024-01-21 +# setuptools # suggestion by pipreqs 2024-01-21 +six>=1.16.0 # added by pipreqs 2024-01-21 +SQLAlchemy>=2.0.0 +Werkzeug>=3.0.1 # added by pipreqs 2024-01-21 xlsxwriter>=1.2.7 -email_validator>=1.0.5