Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Thank you for your contribution!
Code of Conduct: https://iofog.org/docs/contributing/code-of-conduct.html
-->

- [ ] Does the iofog.org or README.md documentation need to change?
- Does the iofog.org or README.md documentation need to change?
- [ ] Yes <!-- include PR link -->
- [ ] No

Expand Down
23 changes: 12 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ notifications:
email: false
slack:
rooms:
- secure: T6GjQi6ap7dvARwdxo619XBUO8aXyzeP4wB8LRpnLKgDQtd+EVw3hwMcHEB7C5+KBC9D0LE0i5HjnLKj2T9ih1L1zKM0QDYFVO8jTt+zhWbEs9Famdq0kmfGiTCbiVG/vxr+9bvFF4QkFhzK8kV44uyqZkmQrHuFnrCpJivsg7dsqvxZ6iU3FV1lMOLU0SJTBHwjbVnIOEqbYcbXmuBJerLMqU7kSlGdlDgBMX8xnzPo/Ccqft+CHDSEl5XU2RZZo2kGSBApO0jpfl1r+7LzWBiwHbuIkFAR5/bVecyuCRpRB4EGEXD7cxCeNUHYjvdr/vaJwTCiPspvSOkJv5YDWgGl7V3WtCV0oPDcQGOU844nHxUTp9FPCQ1bfsPqJ13tCHgv177/Oku3xH22ex6rgTBI6kkVqP3QWTgVtRW91opaKLeBM0ZigQyxQ/hUvQKsMmXzqDrWELG2CuXt2cnNBQ5Hw9wvzEdyY/T4mkXHlbd1UMJ0PUuaymICusfzcErTTnNeByTDkSjrd4dudQtH3jg+Vn3BSQ1R1U1T6DdUhkV75tt37Ej/cbL9ZN8iey7gqx0N3nzqXA0JsBAsJspjCOZWZ0ODdI2XP9FiD+4TUj+HTBgwHtx5kUqf2uuGlKX0S74zN/RjEmHa2riviW3IVur16Vf33U8oiwY+ilht0Zo=
- secure: amP0nLt6NoTtatbxzq1DXpkyVWCmwasGVrzwtyeTEkz/A4H8rA6nAOHdBIIiIVBySaTBVpR2uar9MFWTVy7kWuzRDnBLlkjuXia0Paykv9ENf8CysW0bddhRZNz0zp3SKjjCUCPXe5bmEszQjGKCBOj2XJrkpdnYQdk0L+AqNMGcI2xhu8/RSlww6Ld7OsnkvDyVvOnriclXinZu3V3f6mY7GuXcRva/qowIE8RMGmH70DPBOkCbo7D8g6WtGXcT7sgJVsTOiqPknmQRHJcHi9d55J1fr2cRNRxOCi3pz6B8jwx9BLxKbSttEAO9r9634/Yx6GByE8JaidgVkIm6OTvi6fkCHZZWJGgyxRke/EOOjhdMHSuhVQtBX6RQ4ADRs4Ja4+g9EplXsPaxY4KI7E5jV0HuBn5M7m8RrZ2npP36kqc5/T87tDrocQVKTw5TxYiHUh2GHVw90eA5XFS5eYxT/Ts39n+Jk0CznBQsV47xcUi78OdajP8dAHu/6uC8+xTuN3A00KodH+8H0rQIq6GemMF9FbqRZDjb5ouGu5sI2aiTamKomn1XkBQkDkkrRXLbFg1xfG2XwQHuT7+rBrLqc9QSS+55hz3YDoHvs2EGoYjHLbs/5N25V24LbFJfbg1dF5PxVQ4L58NR5A23zNduElWgzsME8UDtgT9/lac=
on_success: always
on_failure: always
template:
- Repo `%{repository_slug}` *%{result}* build (<%{build_url}|#%{build_number}>)
for commit (<%{compare_url}|%{commit}>) on branch `%{branch}`.
- 'Execution time: *%{duration}*'
- 'Message: %{message}'
- "Build <%{build_url}|#%{build_number}> (<%{compare_url}|%{commit}>) of %{repository_slug}@%{branch} in PR <%{pull_request_url}|#%{pull_request_number}> by %{author} %{result} in %{duration}"
stages:
- name: build
if: type = pull_request
Expand All @@ -28,18 +25,21 @@ jobs:
- stage: build
script:
- npm test
- NODE_ENV=production node /home/travis/build/ioFog/Controller/src/main.js start
- npm run postman_test
- stage: dev_deploy
before_install:
- sudo apt-get install sshpass
script:
- sshpass -p $DEV_MACHINE_PASSWORD ssh -o StrictHostKeyChecking=no $DEV_MACHINE_USERNAME@$DEV_MACHINE_IP "cd /FogController; NODE_ENV=production node src/main.js stop; git pull; npm i; npm test; NODE_ENV=production node src/main.js start; npm run postman_test"
- sshpass -p $DEV_MACHINE_PASSWORD ssh -o StrictHostKeyChecking=no $DEV_MACHINE_USERNAME@$DEV_MACHINE_IP
"cd /FogController; NODE_ENV=production node src/main.js stop; git pull; npm
i; npm test; npm run postman_test; NODE_ENV=production node src/main.js start;"
- stage: pre_release
before_install:
- sudo apt-get install sshpass
script:
- sshpass -p $PREPROD_MACHINE_PASSWORD ssh -o StrictHostKeyChecking=no $PREPROD_MACHINE_USERNAME@$PREPROD_MACHINE_IP "cd /Controller; NODE_ENV=production node src/main.js stop; git pull; git checkout ${TRAVIS_BRANCH}; npm i; npm test; NODE_ENV=production node src/main.js start; npm run postman_test"
- sshpass -p $PREPROD_MACHINE_PASSWORD ssh -o StrictHostKeyChecking=no $PREPROD_MACHINE_USERNAME@$PREPROD_MACHINE_IP
"cd /Controller; NODE_ENV=production node src/main.js stop; git checkout $TRAVIS_BRANCH; npm i;
npm test; npm run postman_test; NODE_ENV=production node src/main.js start;"
- stage: release
#before_install:
#- git clone "https://github.com/$TRAVIS_REPO_SLUG.git" "$TRAVIS_REPO_SLUG";
Expand All @@ -54,9 +54,10 @@ jobs:
deploy:
skip_cleanup: true
provider: npm
email: ${NPM_EMAIL_ADDRESS}
api_key: ${NPM_AUTH_TOKEN}
email: "${NPM_EMAIL_ADDRESS}"
api_key: "${NPM_AUTH_TOKEN}"
on:
tags: false
after_deploy:
- sshpass -p $PROD_MACHINE_PASSWORD ssh -o StrictHostKeyChecking=no $PROD_MACHINE_USERNAME@$PROD_MACHINE_IP "iofog-controller stop; npm update -g iofogcontroller; iofog-controller start"
- sshpass -p $PROD_MACHINE_PASSWORD ssh -o StrictHostKeyChecking=no $PROD_MACHINE_USERNAME@$PROD_MACHINE_IP
"iofog-controller stop; npm update -g iofogcontroller; iofog-controller start"
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iofogcontroller",
"version": "1.0.35",
"version": "1.0.36",
"description": "ioFog Controller project for Eclipse IoFog @ iofog.org \\nCopyright (c) 2018 Edgeworx, Inc.",
"main": "./src/main.js",
"author": "Saeid Baghbidi",
Expand Down Expand Up @@ -34,17 +34,17 @@
"url": "https://github.com/ioFog/Controller"
},
"scripts": {
"start": "node scripts/start.js",
"start-dev": "node scripts/start-dev.js",
"build": "node scripts/init.js",
"preuninstall": "node scripts/preuninstall.js",
"postinstall": "node scripts/postinstall.js",
"start": "node scripts/scripts-api.js start",
"start-dev": "node scripts/scripts-api.js start-dev",
"build": "node scripts/scripts-api.js init",
"preuninstall": "node scripts/scripts-api.js preuninstall",
"postinstall": "node scripts/scripts-api.js postinstall",
"lint": "./node_modules/.bin/eslint \"**/*.js\"",
"automatic-release": "automatic-release",
"test": "node scripts/test.js && node scripts/cli-tests.js",
"postman_test": "node scripts/postmantest.js",
"cli-tests": "node scripts/cli-tests.js",
"coverage": "node scripts/coverage.js"
"test": "node scripts/scripts-api.js test",
"postman_test": "node scripts/scripts-api.js postmantest",
"cli-tests": "node scripts/scripts-api.js cli-tests",
"coverage": "node scripts/scripts-api.js coverage"
},
"preferGlobal": true,
"bin": {
Expand Down
60 changes: 38 additions & 22 deletions scripts/cli-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/

const execSync = require('child_process').execSync;
const {init} = require('./init');
const {restoreDBs, backupDBs} = require('./util');

const options = {
env: {
Expand Down Expand Up @@ -394,27 +396,41 @@ function responseContains(response, expectedResponsePart) {
}
}

try {
testControllerSection();
testUserSection();
testConfigSection();
testConnectorSection();
testTunnelSection();
testIoFogSection();
testCatalogSection();
testFlowSection();
testMicroserviceSection();
testRegistrySection();
testDiagnosticsSection();
} catch (exception) {
console.log("\nException during execution: ");
console.error(exception);
process.exit(1);
function cliTest() {
try {
backupDBs();
//create new DBs
init();

testControllerSection();
testUserSection();
testConfigSection();
testConnectorSection();
testTunnelSection();
testIoFogSection();
testCatalogSection();
testFlowSection();
testMicroserviceSection();
testRegistrySection();
testDiagnosticsSection();

restoreDBs();
} catch (exception) {
restoreDBs();

console.log("\nException during execution: ");
console.error(exception);
process.exit(1);
}

if (testsFailed > 0) {
console.log("\nFailed tests count: " + testsFailed);
process.exit(1);
} else {
console.log("\nCLI Tests passed successfully.");
}
}

if (testsFailed > 0) {
console.log("\nFailed tests count: " + testsFailed);
process.exit(1);
} else {
console.log("\nCLI Tests passed successfully.");
}
module.exports = {
cliTest: cliTest
};
22 changes: 14 additions & 8 deletions scripts/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@

const execSync = require('child_process').execSync;

const options = {
env: {
'NODE_ENV': 'test',
"PATH": process.env.PATH
},
stdio: [process.stdin, process.stdout, process.stderr]
};
function coverage() {
const options = {
env: {
'NODE_ENV': 'test',
"PATH": process.env.PATH
},
stdio: [process.stdin, process.stdout, process.stderr]
};

execSync('nyc mocha', options);
execSync('nyc mocha', options);
}

module.exports = {
coverage: coverage
};
23 changes: 15 additions & 8 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@

const execSync = require('child_process').execSync;

const options = {
env: {
'NODE_ENV': 'production',
"PATH": process.env.PATH
},
stdio: [process.stdin, process.stdout, process.stderr]
};

execSync('node ./src/main.js init', options);
function init() {
const options = {
env: {
'NODE_ENV': 'production',
"PATH": process.env.PATH
},
stdio: [process.stdin, process.stdout, process.stderr]
};

execSync('node ./src/main.js init', options);
}

module.exports = {
init: init
};
110 changes: 37 additions & 73 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,89 +16,49 @@ const execSync = require('child_process').execSync;
const fs = require('fs');
const semver = require('semver');
const currentVersion = require('../package').version;
const {restoreDBs, restoreConfigs, INSTALLATION_VARIABLES_FILE} = require('./util');

const rootDir = `${__dirname}/..`;
let installationVariablesFileName = 'iofogcontroller_install_variables';
let tempDir = getTempDirLocation();
const installationVariablesFile = tempDir + '/' + installationVariablesFileName;

function postinstall() {
//restore all files
const devDbBackup = `${tempDir}/dev_database.sqlite`;
const devDb = `${rootDir}/src/sequelize/dev_database.sqlite`;
moveFileIfExists(devDbBackup, devDb);

const prodDbBackup = `${tempDir}/prod_database.sqlite`;
const prodDb = `${rootDir}/src/sequelize/prod_database.sqlite`;
moveFileIfExists(prodDbBackup, prodDb);

const defConfigBackup = `${tempDir}/default_iofog_backup.json`;
const defConfig = `${rootDir}/src/config/default.json`;
moveFileIfExists(defConfigBackup, defConfig);

const prodConfigBackup = `${tempDir}/production_iofog_backup.json`;
const prodConfig = `${rootDir}/src/config/production.json`;
moveFileIfExists(prodConfigBackup, prodConfig);

const devConfigBackup = `${tempDir}/development_iofog_backup.json`;
const devConfig = `${rootDir}/src/config/development.json`;
moveFileIfExists(devConfigBackup, devConfig);
restoreDBs();
restoreConfigs();

//process migrations
try {
const installationVarsStr = fs.readFileSync(installationVariablesFile);
const installationVars = JSON.parse(installationVarsStr);
const prevVersion = installationVars.prevVer;

console.log(`previous version - ${prevVersion}`);
console.log(`new version - ${currentVersion}`);

if (semver.satisfies(prevVersion, '<=1.0.0')) {
console.log('upgrading from version <= 1.0.0 :');
insertSeeds();
}

if (semver.satisfies(prevVersion, '<=1.0.30')) {
console.log('upgrading from version <= 1.0.30 :');
updateEncryptionMethod();
}

fs.unlinkSync(installationVariablesFile);
} catch (e) {
console.log('no previous version');
}
try {
const installationVarsStr = fs.readFileSync(INSTALLATION_VARIABLES_FILE);
const installationVars = JSON.parse(installationVarsStr);
const prevVersion = installationVars.prevVer;

//init db
const options = {
env: {
'NODE_ENV': 'production',
"PATH": process.env.PATH
},
stdio: [process.stdin, process.stdout, process.stderr]
};
console.log(`previous version - ${prevVersion}`);
console.log(`new version - ${currentVersion}`);

execSync('node ./src/main.js init', options);
if (semver.satisfies(prevVersion, '<=1.0.0')) {
console.log('upgrading from version <= 1.0.0 :');
insertSeeds();
}

//other functions definitions
if (semver.satisfies(prevVersion, '<=1.0.30')) {
console.log('upgrading from version <= 1.0.30 :');
updateEncryptionMethod();
}

function getTempDirLocation() {
let tempDir;
if (os.type() === 'Linux') {
tempDir = '/tmp';
} else if (os.type() === 'Darwin') {
tempDir = '/tmp';
} else if (os.type() === 'Windows_NT') {
tempDir = `${process.env.APPDATA}`;
} else {
throw new Error("Unsupported OS found: " + os.type());
fs.unlinkSync(INSTALLATION_VARIABLES_FILE);
} catch (e) {
console.log('no previous version');
}
return tempDir;
}

function moveFileIfExists(from, to) {
if (fs.existsSync(from)) {
fs.renameSync(from, to);
}
//init db
const options = {
env: {
'NODE_ENV': 'production',
"PATH": process.env.PATH
},
stdio: [process.stdin, process.stdout, process.stderr]
};

execSync('node ./src/main.js init', options);
}
//other functions definitions

function insertSeeds() {
console.log(' inserting seeds meta info in db');
Expand Down Expand Up @@ -189,4 +149,8 @@ function updateEncryptionMethod() {
updateEncryptionMethodForEmailService(defConfig, decryptTextVer30);
updateEncryptionMethodForEmailService(devConfig, decryptTextVer30);
updateEncryptionMethodForEmailService(prodConfig, decryptTextVer30);
}
}

module.exports = {
postinstall: postinstall
};
Loading