diff --git a/docker/v2/build_docker.sh b/docker/v2/build_docker.sh new file mode 100644 index 0000000..a15c7d7 --- /dev/null +++ b/docker/v2/build_docker.sh @@ -0,0 +1,14 @@ +#!/bin/sh +### +### Usage: sh ./build_docker.sh +### This script will run the build.sh file for keymaker & any other directories specified in the args +### +echo "" +echo "*** Cleaning build folder ***" +echo "" +find ./build -exec rm -rdf "{}" \; +mkdir ./build +### Build keymaker +cd ./keymaker +./build.sh +cd .. diff --git a/docker/v2/build_package.sh b/docker/v2/build_package.sh new file mode 100644 index 0000000..84de3f5 --- /dev/null +++ b/docker/v2/build_package.sh @@ -0,0 +1,48 @@ +#!/bin/sh +if [ -z "$KEYMAKER_VERSION" ] +then + echo "KEYMAKER_VERSION must be set first by running command:" + echo " source ./getVersion.sh" + exit 1 +else + echo "KEYMAKER_VERSION is ${KEYMAKER_VERSION}, ok to proceed? (y/n)" + read isVersionOk + if [ "$isVersionOk" != "y" ] + then + echo "Stopping build, re-run when version is ok." + exit 1 + else + echo "Building with KEYMAKER_VERSION ${KEYMAKER_VERSION}" + fi +fi + +### Cleaning build directory +echo "" +echo "*** Cleaning build directory ***" +echo "" +rm -r ./build/* +### Packaging Docker images +echo "" +echo "*** Packaging docker images ***" +echo "" +docker save keymaker-ui:${KEYMAKER_VERSION} keymaker-admin-api:${KEYMAKER_VERSION} keymaker-engine-api:${KEYMAKER_VERSION} | gzip > keymakerDocker.tar.gz +mv keymakerDocker.tar.gz ./build +### Packaging Config +echo "" +echo "*** Packaging Keymaker config ***" +echo "" + +tar --exclude='movies*' -zcvf keymaker_config.tar.gz ./config +mv ./keymaker_config.tar.gz ./build + + +#cp docker-compose.yml ./build/docker-compose.yml +sed 's|${KEYMAKER_VERSION}|'$KEYMAKER_VERSION'|g' docker-compose.yml > ./build/docker-compose.yml +cp ./keymaker.sh ./build/keymaker.sh +cp ../../admin-api/scripts/create-user.sh ./build +echo "" +echo "*** Packaging everything ***" +echo "" +cd ./build +tar cvf keymaker.tar.gz * +echo "*** Done ***" \ No newline at end of file diff --git a/docker/v2/config/keymaker-license/license.lic b/docker/v2/config/keymaker-license/license.lic new file mode 100644 index 0000000..c62da1b --- /dev/null +++ b/docker/v2/config/keymaker-license/license.lic @@ -0,0 +1 @@ +==== Keymaker 7.0.0 - Labs ==== ub6KcYH91hgO0v/NLrGzeD0/vl2iP76afPZmg97dwODgSR9XfqOEccwWOtVdgnzs8JmhkNV046Akg5zlmp6t6yM2JxxfDHhZO3D7uh2WSFA0GOJBoMznzx3iXAZETg3fJLK2WH6cAX/uLT0bFBTPvpRyc/hQMe4hK28nJh0608bcSudoe6wU0x92aZD0VHji/8D7Ol0FWmuLeVg8o+pmzYYODrLCE+36Pr49GhIdLzn+fhkSvYmbK2nVWlW4MVp4KLRP2ZM6h4YFKoEPyP3BmG5YakRLNGD6ZOMWdthucdTYWtAoXq/1S8fJ26wFBJvZlH0iX8jQIWRnlPo+tqdzkg==_$$_e3AEUk9sWOpvbb+5Ch6VprpZGv24V8SgfscmIKo8yicEOVqWVL5GZUmdi/zjKUfgjjdoS7ryFbKDPgMSSHP4Aw== \ No newline at end of file diff --git a/docker/v2/config/keymaker-ui-nginx/nginx.conf b/docker/v2/config/keymaker-ui-nginx/nginx.conf new file mode 100644 index 0000000..ff98f29 --- /dev/null +++ b/docker/v2/config/keymaker-ui-nginx/nginx.conf @@ -0,0 +1,56 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + server { + listen 3080; + listen 3443 ssl; + server_name localhost; + ssl_certificate neo4j.com.crt; + ssl_certificate_key neo4j.com.key; + + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri /index.html; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + } +} + diff --git a/docker/v2/config/keymaker-ui/env-config.js b/docker/v2/config/keymaker-ui/env-config.js new file mode 100644 index 0000000..2f33894 --- /dev/null +++ b/docker/v2/config/keymaker-ui/env-config.js @@ -0,0 +1,14 @@ +window._dynamicEnv_ = { + REACT_APP_GRAPHQL_URI: "http://localhost:36402/graphql", + REACT_APP_RECOMMENDATION_URI: "http://localhost:36401/graphql", + REACT_APP_EULA_GRAPHQL_URI: "ignore", + REACT_APP_AUTH_DOMAIN: "none", + REACT_APP_AUTH_CLIENT_ID: "none", + REACT_APP_AUTH_CALLBACK: "none", + REACT_APP_AUTH_METHOD: "local", + REACT_APP_AUTH_LOGOUT_URL: "localhost", + REACT_APP_EXPIRE_TIME: "3600", + REACT_APP_HIVE_URI: "", + REACT_APP_HIVE_UI: "", + REACT_APP_SOLUTION: "", +}; diff --git a/docker/v2/config/whitelist/whitelisted-origins.txt b/docker/v2/config/whitelist/whitelisted-origins.txt new file mode 100644 index 0000000..e69de29 diff --git a/docker/v2/docker-compose.yml b/docker/v2/docker-compose.yml new file mode 100644 index 0000000..104975c --- /dev/null +++ b/docker/v2/docker-compose.yml @@ -0,0 +1,76 @@ +version: "1" + +services: + keymaker-admin-api: + image: keymaker-admin-api:${KEYMAKER_VERSION} + ports: + - "36402:4002" + volumes: + - ./config/keymaker-license:/app/license + - ./config/keymaker-certificate:/app/ssh_keys + - ./config/logs:/app/logs + environment: + - LICENSE_FILE=/app/license/license.lic + - NEO4J_URI=neo4j://localhost:7687 + - NEO4J_USER=neo4j + - NEO4J_PASSWORD=neo4j + - NEO4J_DATABASE=neo4j + - GRAPHQL_LISTEN_PORT=4002 + - ENCRYPTION_KEY=keymakerEncryptionKey + - ENGINE_API_APIKEY=LZmIbId7He4dh0hH7ZUVKz5A + - AUTH_METHOD=local + - HOST_NAME=localhost + - HOST_PROTOCOL=http + - LOGS_DIR=/app/logs + - LOG_LEVEL=info + - LOG_MAX_SIZE=20m + - LOG_RETENTION_PERIOD=14d + - MAX_CACHED_DRIVERS=100 + - MAX_DRIVER_AGE=3600000 + - NEO4J_TRANSACTION_TIMEOUT=300000 + - DRIVER_CACHE_PRUNE_INTERVAL=600000 + keymaker-engine-api: + image: keymaker-engine-api:${KEYMAKER_VERSION} + ports: + - "36401:4001" + volumes: + - ./config/keymaker-license:/app/license + - ./config/keymaker-certificate:/app/ssh_keys + - ./config/whitelist:/app/config + - ./config/logs:/app/logs + environment: + - LICENSE_FILE=/app/license/license.lic + - WHITELISTED_ORIGINS_FILE=/app/config/whitelisted-origins.txt + - NEO4J_URI=neo4j://localhost:7687 + - NEO4J_USERNAME=neo4j + - NEO4J_PASSWORD=neo4j + - NEO4J_DATABASE=neo4j + - GRAPHQL_LISTEN_PORT=4001 + - ENCRYPTION_KEY=keymakerEncryptionKey + - HOST_NAME=localhost + - HOST_PROTOCOL=http + - MAX_CACHED_DRIVERS=100 + - MAX_DRIVER_AGE=3600000 + - NEO4J_TRANSACTION_TIMEOUT=300000 + - DRIVER_CACHE_PRUNE_INTERVAL=600000 + - MAX_CACHED_APIKEYS=100 + - APIKEY_CACHE_PRUNE_INTERVAL=600000 + - LOGS_DIR=/app/logs + - LOG_LEVEL=info + - LOG_MAX_SIZE=20m + - LOG_RETENTION_PERIOD=14d + - MAX_CACHED_ENGINES=100 + - MAX_ENGINE_AGE=3600000 + - ENGINE_CACHE_PRUNE_INTERVAL=600000 + - ENGINE_CACHE_RESET_INTERVAL=86400000 + keymaker-ui: + image: keymaker-ui:${KEYMAKER_VERSION} + ports: + - "36081:3080" + - "36444:3443" + volumes: + - ./config/keymaker-ui:/usr/share/nginx/html/config + - ./config/keymaker-ui-nginx:/usr/share/nginx/conf + depends_on: + - "keymaker-engine-api" + - "keymaker-admin-api" diff --git a/docker/v2/getVersion.sh b/docker/v2/getVersion.sh new file mode 100755 index 0000000..dff2790 --- /dev/null +++ b/docker/v2/getVersion.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Get the directory of the current script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Path to the version.js file +input="$SCRIPT_DIR/../../ui/src/version.js" + +# Check if the input file exists +if [[ ! -f "$input" ]]; then + echo "Error: File $input not found." + return 1 # Use 'return' instead of 'exit' when sourcing +fi + +# Extract the version number using sed +VERSION=$(sed -n "s/export const VERSION = '\([^']*\)';/\1/p" "$input") + +# Replace '-' and '+' with '_' +VERSION=${VERSION//-/_} +VERSION=${VERSION//+/_} + +# Output the version and export it as an environment variable +echo "VERSION: $VERSION" +export KEYMAKER_VERSION=$VERSION \ No newline at end of file diff --git a/docker/v2/keymaker.sh b/docker/v2/keymaker.sh new file mode 100644 index 0000000..af83ee9 --- /dev/null +++ b/docker/v2/keymaker.sh @@ -0,0 +1,38 @@ +#!/bin/sh +doExit () { + echo >&2 "$@" + exit 1 +} + +[ "$#" -eq 1 ] || doExit "Usage: keymaker (start | stop | status | unpack)" +if [ "$1" = "start" ] +then + echo "Starting Keymaker services" + docker-compose --project-name keymaker up --detach --remove-orphans --force-recreate + echo "Keymaker should be available in a few minutes" + echo " Keymaker Admin UI: http://localhost:36081" +elif [ "$1" = "stop" ] +then + echo "Stopping Keymaker services" + docker-compose --project-name keymaker stop +elif [ "$1" = "status" ] +then + echo "Keymaker status" + docker ps | grep keymaker +elif [ "$1" = "unpack" ] +then + if [ -d "./keymaker_config" ] + then + echo "*** Config folder exists. Skipping unpacking of config ***" + else + echo "" + echo "*** Unpacking config ***" + echo "" + tar xvfz keymaker_config.tar.gz + fi + echo "" + echo "*** Unpacking docker images ***" + echo "" + docker load < keymakerDocker.tar.gz + echo "" +fi \ No newline at end of file diff --git a/docker/v2/keymaker/.DS_Store b/docker/v2/keymaker/.DS_Store new file mode 100644 index 0000000..29997ae Binary files /dev/null and b/docker/v2/keymaker/.DS_Store differ diff --git a/docker/v2/keymaker/admin-api/build.sh b/docker/v2/keymaker/admin-api/build.sh new file mode 100755 index 0000000..76374b9 --- /dev/null +++ b/docker/v2/keymaker/admin-api/build.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Clean dir before build +echo ">>> Removing ./admin-api folder" +./cleanup.sh $1 +# Copy in source code +echo ">>> Copying ./admin-api folder without node_modules" +rsync -av --progress ../../../../admin-api . --exclude node_modules +cd admin-api + +# Install deps +echo ">>> Installing dependencies" +if [ "$1" = "-skipNpmInstall" ] +then + echo ">>> Skipping npm install" + mv ../keep/node_modules . +else + echo ">>> Doing npm install" + npm install +fi +# Copy in empty .env files (vars are specified in docker-compose.yml) +cp ../.env ./.env +cp ../.env ./dist/.env +# Build docker image +echo ">>> Doing docker build" +docker build --no-cache -f Dockerfile ./ -t keymaker-admin-api:${KEYMAKER_VERSION} +# Remove source code +echo ">>> Removing ./admin-api folder" +cd .. +./cleanup.sh $1 \ No newline at end of file diff --git a/docker/v2/keymaker/admin-api/cleanup.sh b/docker/v2/keymaker/admin-api/cleanup.sh new file mode 100755 index 0000000..55fddc6 --- /dev/null +++ b/docker/v2/keymaker/admin-api/cleanup.sh @@ -0,0 +1,9 @@ +#!/bin/sh +if [ "$1" = "-skipNpmInstall" ] +then + mkdir ./keep + mv ./admin-api/node_modules ./keep + find ./admin-api -exec rm -rdf "{}" \; +else + find ./admin-api -exec rm -rdf "{}" \; +fi diff --git a/docker/v2/keymaker/admin-api/package-lock.json b/docker/v2/keymaker/admin-api/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/docker/v2/keymaker/admin-api/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} diff --git a/docker/v2/keymaker/build.sh b/docker/v2/keymaker/build.sh new file mode 100755 index 0000000..7864877 --- /dev/null +++ b/docker/v2/keymaker/build.sh @@ -0,0 +1,42 @@ +#!/bin/sh +if [ -z "$KEYMAKER_VERSION" ] +then + echo "KEYMAKER_VERSION must be set first by running command:" + echo " source ./getVersion.sh" + exit 1 +else + echo "KEYMAKER_VERSION is ${KEYMAKER_VERSION}, ok to proceed? (y/n)" + read isVersionOk + if [ "$isVersionOk" != "y" ] + then + echo "Stopping build, re-run when version is ok." + exit 1 + else + echo "Building with KEYMAKER_VERSION ${KEYMAKER_VERSION}" + fi +fi + +echo "" +echo "*** Building Keymaker ***" +echo "" +### Build Keymaker Admin API +echo "" +echo "*** Building Keymaker Admin API ***" +echo "" +cd ./admin-api +./build.sh $1 +cd .. +### Build Keymaker Engine API +echo "" +echo "*** Building Keymaker Engine API ***" +echo "" +cd ./engine-api +./build.sh $1 +cd .. +### Build Keymaker UI +echo "" +echo "*** Building Keymaker UI ***" +echo "" +cd ./ui +./build.sh $1 +cd .. \ No newline at end of file diff --git a/docker/v2/keymaker/engine-api/build.sh b/docker/v2/keymaker/engine-api/build.sh new file mode 100755 index 0000000..2ddf8a9 --- /dev/null +++ b/docker/v2/keymaker/engine-api/build.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Clean dir before build +echo ">>> Removing ./engine-api folder" +./cleanup.sh $1 +# Copy in source code +echo ">>> Copying ./engine-api folder without node_modules" +rsync -av --progress ../../../../engine-api . --exclude node_modules +cd engine-api + +# Install deps +echo ">>> Installing dependencies" +if [ "$1" = "-skipNpmInstall" ] +then + echo ">>> Skipping npm install" + mv ../keep/node_modules . +else + echo ">>> Doing npm install" + npm install +fi +# Copy in empty .env files (vars are specified in docker-compose-all.yml) +cp ../.env ./.env +cp ../.env ./dist/.env +# Build docker image +echo ">>> Doing docker build" +docker build --no-cache -f Dockerfile ./ -t keymaker-engine-api:${KEYMAKER_VERSION} +# Remove source code +echo ">>> Removing ./engine-api folder" +cd .. +./cleanup.sh $1 \ No newline at end of file diff --git a/docker/v2/keymaker/engine-api/cleanup.sh b/docker/v2/keymaker/engine-api/cleanup.sh new file mode 100755 index 0000000..133adda --- /dev/null +++ b/docker/v2/keymaker/engine-api/cleanup.sh @@ -0,0 +1,9 @@ +#!/bin/sh +if [ "$1" = "-skipNpmInstall" ] +then + mkdir ./keep + mv ./engine-api/node_modules ./keep + find ./engine-api -exec rm -rdf "{}" \; +else + find ./engine-api -exec rm -rdf "{}" \; +fi diff --git a/docker/v2/keymaker/engine-api/package-lock.json b/docker/v2/keymaker/engine-api/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/docker/v2/keymaker/engine-api/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} diff --git a/docker/v2/keymaker/ui/build.sh b/docker/v2/keymaker/ui/build.sh new file mode 100755 index 0000000..025a19b --- /dev/null +++ b/docker/v2/keymaker/ui/build.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# Clean dir before build +echo ">>> Removing ./ui folder" +./cleanup.sh $1 +# Copy in source code +echo ">>> Copying ./ui folder without node_modules" +rsync -av --progress ../../../../ui . --exclude node_modules +cd ui +rm ./public/config/env-config.js +rmdir ./public/config +# Install deps +echo ">>> Doing Keymaker UI build" +if [ "$1" = "-skipNpmInstall" ] +then + echo ">>> Skipping npm install" + mv ../keep/node_modules . +else + echo ">>> Doing npm install" + npm install +fi +# Include Nginx config +echo ">>> Overwrite nginx.conf" +cp ../nginx.conf ./nginx.conf +# Build docker image +echo ">>> Doing docker build" +docker build --no-cache -f Dockerfile ./ -t keymaker-ui:${KEYMAKER_VERSION} +# Remove source code +echo ">>> Removing ./ui folder" +cd .. +./cleanup.sh $1 \ No newline at end of file diff --git a/docker/v2/keymaker/ui/cleanup.sh b/docker/v2/keymaker/ui/cleanup.sh new file mode 100755 index 0000000..614b2a0 --- /dev/null +++ b/docker/v2/keymaker/ui/cleanup.sh @@ -0,0 +1,9 @@ +#!/bin/sh +if [ "$1" = "-skipNpmInstall" ] +then + mkdir ./keep + mv ./ui/node_modules ./keep + find ./ui -exec rm -rdf "{}" \; +else + find ./ui -exec rm -rdf "{}" \; +fi diff --git a/docker/v2/keymaker/ui/nginx.conf b/docker/v2/keymaker/ui/nginx.conf new file mode 100644 index 0000000..3f3f9af --- /dev/null +++ b/docker/v2/keymaker/ui/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 3080; + server_name localhost; + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri /index.html; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file diff --git a/docker/v2/keymaker/ui/package-lock.json b/docker/v2/keymaker/ui/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/docker/v2/keymaker/ui/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +}