diff --git a/README.md b/README.md new file mode 100644 index 0000000..34414bb --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# Bell + +Dockerize bell app + +## Components + +* Bell. It is bell app container build with node.js. +* Couchdb. It is the database container which is initiated with `db-init`. + +## How to use + +### Build manually + +1. Download the source code. Get into the version folder (x86 or arm for example). +2. Run command to build the image + + ```shell + /bin/bash build.sh + ``` +3. Run command to start containers + + ```shell + docker-compose up -d + ``` +4. Run command to stop containers + + ```shell + docker-compose stop + ``` +5. Run command to delete the environment + + ```shell + docker-compose down + ``` +6. See if docker containers running + + ```shell + docker ps + ``` + +7. View container log + + ```shell + docker logs {{container_id}} + ``` + +### Use the pre-build image + +1. Run command to start bell + ```shell + docker-compose -f docker-compose-ready.yml up -d + ``` + +2. Run command to stop bell + ```shell + docker-compose -f docker-compose-ready.yml stop + ``` + +3. Delete environment + ```shell + docker-compose -f docker-compose-ready.yml down + ``` \ No newline at end of file diff --git a/x86/bell/Dockerfile b/x86/bell/Dockerfile new file mode 100644 index 0000000..f5de9b0 --- /dev/null +++ b/x86/bell/Dockerfile @@ -0,0 +1,21 @@ +FROM node:6.11-alpine + +LABEL MAINTAINER "Dashlorde " +LABEL MAINTAINER "Abdurrachman Mappuji " +LABEL MAINTAINER "dogi " + +ENV version '0.13.21' + +RUN mkdir -p /app/server/src && \ + apk add --update openssl && npm install express + +WORKDIR /app/server/src + +COPY server.js ./ +COPY package.json ./ + +RUN chmod +x ./server.js && npm install + +EXPOSE 80 + +CMD ["npm","start"] diff --git a/x86/bell/build.sh b/x86/bell/build.sh new file mode 100644 index 0000000..446b0cf --- /dev/null +++ b/x86/bell/build.sh @@ -0,0 +1 @@ +docker build . -t bell:latest diff --git a/x86/bell/dockerfile b/x86/bell/dockerfile new file mode 100644 index 0000000..f5de9b0 --- /dev/null +++ b/x86/bell/dockerfile @@ -0,0 +1,21 @@ +FROM node:6.11-alpine + +LABEL MAINTAINER "Dashlorde " +LABEL MAINTAINER "Abdurrachman Mappuji " +LABEL MAINTAINER "dogi " + +ENV version '0.13.21' + +RUN mkdir -p /app/server/src && \ + apk add --update openssl && npm install express + +WORKDIR /app/server/src + +COPY server.js ./ +COPY package.json ./ + +RUN chmod +x ./server.js && npm install + +EXPOSE 80 + +CMD ["npm","start"] diff --git a/x86/bell/package.json b/x86/bell/package.json new file mode 100644 index 0000000..e2a3cfd --- /dev/null +++ b/x86/bell/package.json @@ -0,0 +1,26 @@ +{ + "name": "bell-apps", + "description": "A collection of Apps for the BeLL", + "version": "0.0.1", + "author": "R.J. Steinert ", + "main": "server.js", + "scripts": { + "start": "node server.js" + }, + "repository": { + "type": "git", + "url": "http://github.com/open-learning-exchange/bell-apps.git" + }, + "dependencies": { + "couchapp": ">= 0.10.0", + "underscore": ">= 1.5.2", + "nano": "6.0.1", + "commander": "2.5.0", + "request": ">= 2.27.0", + "co": ">= 4.6.0", + "cookie": ">= 0.3.1", + "express": "^4.16.1" + + }, + "engines": { "node": ">= 6.9.2" } +} \ No newline at end of file diff --git a/x86/bell/server.js b/x86/bell/server.js new file mode 100644 index 0000000..f17c170 --- /dev/null +++ b/x86/bell/server.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node + +var express = require('express') +var PortJack = express() +var path = require("path"); +var HOST = process.env.HOST; + +PortJack.get(/^(.+)$/, function(req, res) { + + res.setHeader('Location', 'http://' + HOST + ':5984/apps/_design/bell/MyApp/index.html') + + res.statusCode = 302 + res.end() +}) + +PortJack.listen(80) \ No newline at end of file diff --git a/x86/build-ready.sh b/x86/build-ready.sh new file mode 100644 index 0000000..052481d --- /dev/null +++ b/x86/build-ready.sh @@ -0,0 +1,2 @@ +docker build bell/. -t treehouses/bell:latest +docker build db-init/. -t treehouses/bell:db-init-latest diff --git a/x86/build.sh b/x86/build.sh new file mode 100644 index 0000000..2c51a3d --- /dev/null +++ b/x86/build.sh @@ -0,0 +1,2 @@ +docker build bell/. -t bell:latest +docker build db-init/. -t bell:db-init-latest diff --git a/x86/db-init/Dockerfile b/x86/db-init/Dockerfile new file mode 100644 index 0000000..ccebade --- /dev/null +++ b/x86/db-init/Dockerfile @@ -0,0 +1,24 @@ +FROM node:6.11-alpine + +LABEL MAINTAINER "Dashlorde " +LABEL MAINTAINER "Abdurrachman Mappuji " +LABEL MAINTAINER "dogi " + +ENV version '0.13.21' + +RUN apk update && \ + apk add --no-cache bash curl git jq openssl && \ + mkdir bell && wget -O bell/BeLL-Apps-${version}.tar.gz \ + https://github.com/open-learning-exchange/BeLL-Apps/archive/0.13.21.tar.gz && \ + cd bell && tar xvf BeLL-Apps-${version}.tar.gz && \ + mkdir -p /app && mv BeLL-Apps-${version}/* /app && \ + chmod +x /app/node_modules/.bin/couchapp && \ + #CORS DOWNLOAD + npm install -g add-cors-to-couchdb + +COPY docker-entrypoint.sh /root/docker-entrypoint.sh +COPY couchdb-setup.sh /root/couchdb-setup.sh + +RUN chmod +x /root/couchdb-setup.sh + +CMD sh /root/docker-entrypoint.sh diff --git a/x86/db-init/build.sh b/x86/db-init/build.sh new file mode 100644 index 0000000..37ac629 --- /dev/null +++ b/x86/db-init/build.sh @@ -0,0 +1 @@ +docker build . -t bell:db-init-latest diff --git a/x86/db-init/couchdb-setup.sh b/x86/db-init/couchdb-setup.sh new file mode 100644 index 0000000..da1c686 --- /dev/null +++ b/x86/db-init/couchdb-setup.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Options are -u for username -w for passWord and -p for port number +while getopts "u:w:p:h:" option; do + case $option in + u) COUCHUSER=${OPTARG};; + w) COUCHPASSWORD=${OPTARG};; + p) PORT=${OPTARG};; + h) HOST=${OPTARG};; + esac +done + +if [ -z "$HOST" ] +then + HOST=127.0.0.1 +fi + +# Default port for CouchDB accessed from host machine is 2200 +PORT=${PORT:-5984} +if [ -z "$COUCHUSER" ] +then + COUCHURL=http://$HOST:$PORT +else + COUCHURL=http://$COUCHUSER:$COUCHPASSWORD@$HOST:$PORT +fi + +curl -X PUT $COUCHURL/_users +curl -X PUT $COUCHURL/_replicator +curl -X PUT $COUCHURL/_global_changes + +for database in /app/databases/*.js; do + curl -X PUT $COUCHURL/${database:15:-3} + case ${database:15:-3} in + "communities" | "languages" | "configurations" ) ;; + * ) /app/node_modules/.bin/couchapp push $database $COUCHURL/${database:15:-3} ;; + esac +done + +## add bare minimal required data to couchdb for launching bell-apps smoothly +for filename in /app/init_docs/languages/*.txt; do + curl -d @$filename -H "Content-Type: application/json" -X POST $COUCHURL/languages; +done +curl -d @app/init_docs/ConfigurationsDoc-Community.txt -H "Content-Type: application/json" -X POST $COUCHURL/configurations +curl -d @app/init_docs/admin.txt -H "Content-Type: application/json" -X POST $COUCHURL/members diff --git a/x86/db-init/docker-entrypoint.sh b/x86/db-init/docker-entrypoint.sh new file mode 100644 index 0000000..2fb992e --- /dev/null +++ b/x86/db-init/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +#WAIT_TIME +while ! curl -X GET couchdb:5984/_all_dbs ; do + sleep 1 +done + + +#CORS SETUP +add-cors-to-couchdb http://couchdb:5984 + +#MIGRATOR +/root/couchdb-setup.sh -p 5984 -h couchdb diff --git a/x86/db-init/dockerfile b/x86/db-init/dockerfile new file mode 100644 index 0000000..ccebade --- /dev/null +++ b/x86/db-init/dockerfile @@ -0,0 +1,24 @@ +FROM node:6.11-alpine + +LABEL MAINTAINER "Dashlorde " +LABEL MAINTAINER "Abdurrachman Mappuji " +LABEL MAINTAINER "dogi " + +ENV version '0.13.21' + +RUN apk update && \ + apk add --no-cache bash curl git jq openssl && \ + mkdir bell && wget -O bell/BeLL-Apps-${version}.tar.gz \ + https://github.com/open-learning-exchange/BeLL-Apps/archive/0.13.21.tar.gz && \ + cd bell && tar xvf BeLL-Apps-${version}.tar.gz && \ + mkdir -p /app && mv BeLL-Apps-${version}/* /app && \ + chmod +x /app/node_modules/.bin/couchapp && \ + #CORS DOWNLOAD + npm install -g add-cors-to-couchdb + +COPY docker-entrypoint.sh /root/docker-entrypoint.sh +COPY couchdb-setup.sh /root/couchdb-setup.sh + +RUN chmod +x /root/couchdb-setup.sh + +CMD sh /root/docker-entrypoint.sh diff --git a/x86/docker-compose-ready.yml b/x86/docker-compose-ready.yml new file mode 100644 index 0000000..3774a8d --- /dev/null +++ b/x86/docker-compose-ready.yml @@ -0,0 +1,20 @@ +services: + couchdb: + expose: + - 5984 + ports: + - "5984:5984" + image: klaemo/couchdb + db-init: + image: treehouses/bell:db-init-latest + depends_on: + - couchdb + bell: + image: treehouses/bell:latest + ports: + - "80:80" + environment: + - HOST=127.0.0.1 + depends_on: + - couchdb +version: "2" diff --git a/x86/docker-compose.yml b/x86/docker-compose.yml new file mode 100644 index 0000000..7b5001f --- /dev/null +++ b/x86/docker-compose.yml @@ -0,0 +1,20 @@ +services: + couchdb: + expose: + - 5984 + image: klaemo/couchdb + ports: + - "5984:5984" + db-init: + image: bell:db-init-latest + depends_on: + - couchdb + bell: + image: bell:latest + ports: + - "80:80" + environment: + - HOST=127.0.0.1 + depends_on: + - couchdb +version: "2"