From f9a98f62e546bbaa97a6cb62ad7e1fb86a276a44 Mon Sep 17 00:00:00 2001 From: Deepti Date: Wed, 11 Jul 2018 19:53:55 +0530 Subject: [PATCH] #101 Create a script that alerts devs (#109) Fixes https://github.com/mozilla/fxa-local-dev/issues/101 --- .travis.yml | 4 +-- README.md | 14 +++------- _scripts/check.sh | 48 ++++++++++++++++++++++++++++++++++ _scripts/check_node_version.js | 33 +++++++++++++++++++++++ _scripts/install_all.sh | 3 +++ _scripts/memcached.js | 5 ---- _scripts/memcached.sh | 1 + _scripts/redis.js | 6 ----- mysql_servers.json | 4 +-- package.json | 2 +- servers.json | 2 +- 11 files changed, 94 insertions(+), 28 deletions(-) create mode 100755 _scripts/check.sh create mode 100644 _scripts/check_node_version.js delete mode 100755 _scripts/memcached.js create mode 100644 _scripts/memcached.sh delete mode 100755 _scripts/redis.js diff --git a/.travis.yml b/.travis.yml index 6a74009d7..4309cf013 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,12 +29,12 @@ matrix: - fast_finish: true before_install: - - npm i -g npm@5 + - npm i -g npm@6 - if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew install graphicsmagick; fi install: - PATH="`npm bin`:`npm bin -g`:$PATH" - - npm install -g npm@5 + - npm install -g npm@6 - node --version - npm --version diff --git a/README.md b/README.md index 1892388b6..8df7381d2 100644 --- a/README.md +++ b/README.md @@ -81,17 +81,13 @@ If you get an `error` status for any of the servers please verify that you insta ### Dependencies > Required developer dependencies: [Git](http://git-scm.com/book/en/v2/Getting-Started-Installing-Git), -[node.js **8+**, with npm 5](http://nodejs.org/), +[node.js **8+** with npm 6](http://nodejs.org/), [Python 2.6+](https://www.python.org/), [Java 8+](https://www.java.com/en/download/), -[Redis](http://redis.io/), [libgmp](https://gmplib.org/), [graphicsmagick](http://www.graphicsmagick.org/), -[memcached](https://memcached.org/), [docker](https://docs.docker.com/). -**Note:** Please use Node.js 8+. - ##### OS X (with [Brew](http://brew.sh/)): [Xcode and OS X Command Line Tools are required](https://developer.apple.com/xcode/), install it and verify that command line tools installed: @@ -100,15 +96,14 @@ xcode-select --install ``` then: ``` -brew install gmp redis graphicsmagick memcached sudo easy_install pip && sudo pip install virtualenv ``` [Install Docker for Mac](https://docs.docker.com/docker-for-mac/install/) ##### Ubuntu: ``` -sudo apt-get install build-essential git-core libgmp3-dev graphicsmagick redis-server python-virtualenv -python-dev memcached docker-ce +sudo apt-get install build-essential git-core libgmp3-dev graphicsmagick python-virtualenv +python-dev docker-ce ``` Docker commands require sudo, to avoid it, follow steps below: 1. Add the docker group if it doesn't already exist @@ -129,9 +124,6 @@ sudo service docker restart > NOTE: If you are experienced with Node.js: Use [nvm](https://github.com/creationix/nvm) to force node 8 just for `fxa-local-dev` using `nvm use 8`. (Install it first with `nvm install 8`) -##### OS X -Use this if you do not rely on other node.js programs on your system: Find the latest Node 8 LTS `.pkg` download at [nodejs.org/en/download/](https://nodejs.org/en/download/) and install it. - ##### Ubuntu / Debian: ``` diff --git a/_scripts/check.sh b/_scripts/check.sh new file mode 100755 index 000000000..81d3239f3 --- /dev/null +++ b/_scripts/check.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +if [[ $(which node) && $(node --version) ]]; then + node _scripts/check_node_version.js +else + echo "install node to continue installation" + echo "https://nodejs.org" + exit 1 +fi + +if [[ $(which docker) && $(docker --version) ]]; then + docker=y +else + docker=n +fi + +os="$(uname -a | cut -f 1 -d ' ')" +if [ "$os" = "Darwin" ]; then + if [ "$docker" = "n" ]; then + echo "install docker to continue installation" + echo "https://docs.docker.com/docker-for-mac/install/" + exit 1 + fi + + if [[ $(which brew) && $(brew --version) ]]; then + if [[ $(brew ls --versions gmp) ]]; then + echo "gmp is installed" + else + brew install gmp + fi + if [[ $(brew ls --versions graphicsmagick) ]]; then + echo "graphicsmagick is installed" + else + brew install graphicsmagick + fi + else + echo "install homebrew to continue installation" + echo "https://brew.sh/" + exit 1 + fi +elif [ "$os" = "Linux" ]; then + if [ "$docker" = "n" ]; then + echo "install docker to continue installation using the steps below:" + echo "sudo apt-get install docker-ce" + echo "sudo groupadd docker" + echo "sudo gpasswd -a $USER docker" + echo "sudo service docker restart" + fi +fi diff --git a/_scripts/check_node_version.js b/_scripts/check_node_version.js new file mode 100644 index 000000000..c2c2602ae --- /dev/null +++ b/_scripts/check_node_version.js @@ -0,0 +1,33 @@ +const check = require("check-node-version"); + +check( + { node: ">= 8", npm: ">= 6" }, + (error, results) => { + if (error) { + console.error(error); + return; + } + + if (results.isSatisfied) { + console.log("Node and nvm version ok"); + return; + } + + console.error("Some package version(s) failed!"); + + for (const packageName of Object.keys(results.versions)) { + if (!results.versions[packageName].isSatisfied) { + if(packageName === 'npm') + console.error(`Npm version must be > 6 . Run the following command to upgrade npm "npm i -g npm@6"`); + else if(packageName === 'node') + console.error(`Node version must be > 8`); + if(process.platform === 'darwin') + console.log("Use this if you do not rely on other node.js programs on your system: Find the latest Node 8 LTS .pkg download at nodejs.org/en/download/ and install it.") + else + console.error(`Missing ${packageName}.`); + + process.exit(1); + } + } + } +); diff --git a/_scripts/install_all.sh b/_scripts/install_all.sh index b88aed278..b28844b0c 100755 --- a/_scripts/install_all.sh +++ b/_scripts/install_all.sh @@ -1,4 +1,5 @@ #!/bin/sh -ex +_scripts/check.sh # Set ulimit, need it for npm ulimit -S -n 2048 || echo "Setting ulimit failed" @@ -48,6 +49,8 @@ cd fxa-basket-proxy; npm i; cd .. cd 123done; npm i; cd .. +docker pull memcached + docker pull mozilla/syncserver docker pull pafortin/goaws diff --git a/_scripts/memcached.js b/_scripts/memcached.js deleted file mode 100755 index d776d8d6c..000000000 --- a/_scripts/memcached.js +++ /dev/null @@ -1,5 +0,0 @@ -const spawn = require('child_process').spawn; -const memcachedProcess = spawn('memcached', ['-vv'], { stdio: 'inherit' }); -process.on('exit', (code) => { - memcachedProcess.close(); -}); diff --git a/_scripts/memcached.sh b/_scripts/memcached.sh new file mode 100644 index 000000000..dcf5393ea --- /dev/null +++ b/_scripts/memcached.sh @@ -0,0 +1 @@ +docker run --rm --name memcache memcached diff --git a/_scripts/redis.js b/_scripts/redis.js deleted file mode 100755 index cb4d771c5..000000000 --- a/_scripts/redis.js +++ /dev/null @@ -1,6 +0,0 @@ -const RedisServer = require('redis-server'); -const server = new RedisServer(process.env.port); -server.open().then(() => {}); -process.on('exit', (code) => { - server.close(); -}); diff --git a/mysql_servers.json b/mysql_servers.json index de9ab0ca2..16273510c 100644 --- a/mysql_servers.json +++ b/mysql_servers.json @@ -174,7 +174,7 @@ }, { "name": "memcached PORT 11211", - "script": "_scripts/memcached.js", + "script": "_scripts/memcached.sh", "max_restarts": "1", "min_uptime": "2m" }, @@ -186,4 +186,4 @@ "autorestart": false } ] -} +} \ No newline at end of file diff --git a/package.json b/package.json index 14d8e050f..6c35efaf9 100644 --- a/package.json +++ b/package.json @@ -26,13 +26,13 @@ "dependencies": { "bluebird": "2.10.2", "chalk": "1.1.1", + "check-node-version": "^3.2.0", "foxfire": "1.0.1", "fxa-dev-launcher": "vladikoff/fxa-dev-launcher", "internal-ip": "1.2.0", "lodash": "4.16.2", "minimist": "1.1.1", "pm2": "2.9.3", - "redis-server": "1.1.0", "replace-in-file": "0.2.1" } } diff --git a/servers.json b/servers.json index 49aa205cf..9ecd7a31e 100644 --- a/servers.json +++ b/servers.json @@ -153,7 +153,7 @@ }, { "name": "memcached PORT 11211", - "script": "_scripts/memcached.js", + "script": "_scripts/memcached.sh", "max_restarts": "1", "min_uptime": "2m" },