FROM ubuntu:xenial # a few useful packages RUN apt-get clean && \ apt-get update && \ apt-get install -y \ bzip2 \ ca-certificates \ curl \ git \ less \ python-software-properties \ screen \ software-properties-common \ sudo \ time \ vim \ wget \ xterm RUN apt-get install -y \ aptitude \ mongodb ## install nvm and node RUN \ (curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash) ENV NVM_DIR="$HOME/.nvm" RUN \ export NVM_DIR="$HOME/.nvm" && \ . "$NVM_DIR/nvm.sh" && \ nvm install 7.7.2 RUN mkdir /opt/xbrowsersync WORKDIR /opt/xbrowsersync ## start and configure mongodb RUN echo '\nuse xBrowserSync\n\ db.createUser({ user: "xbrowsersyncdb", pwd: "password", roles: ["readWrite"] })\n\ db.createCollection("bookmarks")\n\ db.createCollection("newSyncsLog")\n\ db.newSyncsLog.createIndex({ "ipAddress": 1, "syncCreated": 1 })'\ >> xbrowser_mongosetup.js RUN echo '\n\ RET=1;\n\ while [[ $RET -ne 0 ]]; do \n\ echo "=> Waiting for confirmation of MongoDB service startup"; \n\ sleep 5; \n\ tail -n 5 /var/log/mongodb/mongodb.log\n\ mongo admin --eval "help" >/dev/null 2>&1 ; \n\ RET=$?; \n\ done; \n'\ >> mongo_wait.sh ## may take a while ... :/ RUN echo "starting mongodb.." && \ service mongodb start && \ bash ./mongo_wait.sh && \ bash ./mongo_wait.sh && \ mongo < xbrowser_mongosetup.js ## clone git repo and build RUN \ git clone --depth=50 --branch=master https://github.com/xBrowserSync/API.git API WORKDIR /opt/xbrowsersync/API # fix restify version, then build RUN \ apt-get install -y make && \ sed -i 's/"restify": "4.0.x"/"restify": "4.3.x"/' package.json && \ export NVM_DIR="$HOME/.nvm" && \ . "$NVM_DIR/nvm.sh" && \ npm install && \ npm run build RUN \ touch '/var/log/xBrowserSync_api.log' ## make a launch script RUN echo '\n\ if [ -f /run/mongodb/mongodb.pid ]; then rm /run/mongodb/mongodb.pid; fi; \n\ service mongodb start; \n\ export XBROWSERSYNC_DB_USER=xbrowsersyncdb; \n\ export XBROWSERSYNC_DB_PWD=password; \n\ bash ../mongo_wait.sh; \n\ bash ../mongo_wait.sh; \n\ node api.js\n'\ >> launch.sh CMD "bash"