Skip to content

Commit

Permalink
Merge pull request #701 from eapearson/develop
Browse files Browse the repository at this point in the history
adds deploy config file generation [SCT-1075]
  • Loading branch information
eapearson committed Jun 15, 2018
2 parents 39150b1 + c1b3d3f commit f96af43
Show file tree
Hide file tree
Showing 12 changed files with 1,812 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nbproject
/build/build
/build/build-test-coverage
/build/test
/build/deploy
/mutations/mutantfiles

# Developer artifacts
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ build: clean-build
@echo "> Building."
cd mutations; node build $(config)

build-deploy-configs:
@echo "> Building Deploy Configs..."
@mkdir -p $(TOPDIR)/build/deploy/configs
@cd mutations; node build-deploy-configs $(TOPDIR)/deployment/ci/docker/kb-deployment/conf/config.json.tmpl $(TOPDIR)/config/deploy $(TOPDIR)/build/deploy/configs
@echo "> ... deploy configs built in $(TOPDIR)/build/deploy/configs"

build-ci:
@echo "> Building for CI."
cd mutations; node build ci
Expand Down
60 changes: 60 additions & 0 deletions docs/dev/prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ You will need to ensure that you have a basic set of development tools on your h
| npm | 6 | |
| git | * | the source revision management tool with integration into github |
| docker | * | the linux container manager you will use to run kbase-ui |
| dockerize | * | a utility to make running docker containers more sane |
| make | * | all build tasks go through make |

> \* we haven't documented any substantial differences between these tools regarding the kbase-ui development process. However, it is best to keep them always at the most recent version by updating your tool stack periodically
Expand All @@ -38,6 +39,65 @@ Node and npm are used together to build _kbase-ui_ and to run tests. Node and np

[ to be done ]

### dockerize

dockerize may be installed via go or via a specific binary for linux or macOS:

#### download binary

Dockerize is available prebuilt for linux and macOS from the dockerize github repo:

```bash
export DOCKERIZE_VERSION=6.1
wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
tar xvfz dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
sudo mv dockerize /usr/local/bin
```

#### install via go

You may also install it via go. This is especially handy if you are already set up for go, or need to use other go-based programs which are not available through a package manager.

install go

```bash
sudo port install golang
```

update your macOS account profile. E.g.

edit ~/.profile

```bash
vi ~/.profile
```

add the following two lines to the end of the file:

```
export GOPATH="${HOME}/go"
export PATH=$PATH:$(go env GOPATH)/bin
```

and ensure that the go working directory exists

```bash
mkdir ~/go
```

You will need to spin up a new terminal window to pick up the go settings.

Install dockerize:

```
go get github.com/jwilder/dockerize
go install github.com/jwilder/dockerize
```

now the dockerize command will be available.



### make

[ to be done]
Expand Down
104 changes: 104 additions & 0 deletions mutations/build-deploy-configs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* build-deploy-config.js
*
*/

/*eslint-env node */
/*eslint strict: ["error", "global"] */
'use strict';

var Promise = require('bluebird'),
fs = Promise.promisifyAll(require('fs-extra')),
path = require('path'),
mutant = require('./mutant'),
glob = Promise.promisify(require('glob').Glob),
exec = require('child_process').exec;


function makeDeployConfig(templatePath, envFilesDir, destinationDir) {
// var root = state.environment.path;
// var cfgDir = root.concat(['build', 'deploy', 'cfg']);
// var sourceDir = root.concat(['config', 'deploy']);

// console.log('make deploy config...', root, cfgDir, sourceDir);

// make deploy dir
return fs.mkdirsAsync(destinationDir)
.then(function () {
// read yaml an write json deploy configs.
return glob(envFilesDir + '/*.env', {
nodir: true
});
})
.then(function (matches) {
// console.log('matches', matches);
return Promise.all(matches.map(function (match) {
var baseName = path.basename(match, '.env');

var outputPath = destinationDir + '/' + baseName + '.json';

var envPath = match;

return mutant.loadDockerEnvFile(envPath)
.then((function (templateVars) {
var envVars = Object.assign({}, process.env, templateVars);

var cmd = [
'dockerize',
'-template',
templatePath + ':' + outputPath
].join(' ');

return new Promise(function (resolve, reject) {
exec(cmd, {
env: envVars
}, function(error, stdout, stderr) {
if (error) {
reject(stderr);
} else {
resolve(stdout);
}
});
});
}));
}));
})
.catch(function (error) {
console.error('ERROR', error);
});

// save the deploy script
}

function main(cfgDir, sourceDir, destinationDir) {
return makeDeployConfig(cfgDir, sourceDir, destinationDir);
}

function usage() {
console.error('usage: node build-deploy-configs <config-dir> <source-dir> <destination-dir>');
}

var configTemplate= process.argv[2];
if (configTemplate === undefined) {
console.error('Config template file not specified');
usage();
process.exit(1);
}

var envFilesDir = process.argv[3];
if (envFilesDir === undefined) {
console.error('Environment file directory not specified');
usage();
process.exit(1);
}

var outputDir = process.argv[4];
if (outputDir === undefined) {
console.error('Output directory not specified');
usage();
process.exit(1);
}


main(configTemplate, envFilesDir, outputDir);

0 comments on commit f96af43

Please sign in to comment.