Skip to content

Commit

Permalink
Merge branch '0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ssmirr committed Feb 8, 2018
2 parents 35efae8 + 4608235 commit 9e8cb65
Show file tree
Hide file tree
Showing 32 changed files with 733 additions and 117 deletions.
6 changes: 4 additions & 2 deletions src/baker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const camelCase = require('camelcase');
const requireDir = require('require-dir');
const fs = Promise.promisifyAll(require('fs-extra'));
const mustache = require('mustache');
const child_process = require('child_process');
const child_process = Promise.promisifyAll(require('child_process'));
const vagrant = Promise.promisifyAll(require('node-vagrant'));
const scp2 = require('scp2');
const ssh2 = require('ssh2');
Expand All @@ -17,6 +17,7 @@ const slash = require('slash');
const git = require('simple-git');
const ora = require('ora');
const hasbin = require('hasbin');
const drivelist = Promise.promisifyAll(require('drivelist'));
require('console.table');

const boxes = path.join(require('os').homedir(), '.baker');
Expand Down Expand Up @@ -54,7 +55,8 @@ let dep = {
ansible,
configPath,
bakerletsPath,
remotesPath
remotesPath,
drivelist
};

// Internal dependencies
Expand Down
8 changes: 4 additions & 4 deletions src/config/BaseVM.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "{{{vagrant.box}}}"

config.ssh.insert_key = false
config.ssh.private_key_path = ["~/.baker/ansible-srv/keys/baker_rsa", "~/.vagrant.d/insecure_private_key"]

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
Expand Down Expand Up @@ -88,9 +91,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision "shell",
inline: "test -e /usr/bin/python || (sudo apt -y update && sudo apt install -y python-minimal)"

#
# View the documentation for the provider you are using for more
# information on available options.

config.vm.provision "file", source: "~/.baker/ansible-srv/keys/baker_rsa.pub", destination: "~/.ssh/authorized_keys"

end
51 changes: 51 additions & 0 deletions src/config/baker_rsa
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAqPmEYSNho56PuTQ/jf6Qb78Owb44ujhLWYFCryX/D/az3FAk
fMOw6Qz06S0jOLKQaiMKBDNQkEZx/Mf1H74a+dbVP++AOCdjIARIwpSPDOWfIqmI
Q1n6EcsKP9rgda6zxyAiDO9ei0RRiA6Kp7fpXh1OMHHx5hzWvPyqgubTcXff1QcX
r3odAiLu/wWt/1FbZ+gk2NrBjKNJiZNCI8yLCuNk4ES+2Tk0H26NU3dw6TgnbdNs
X7ecVwpPSrkcMK43bcmWz/J/MXO/2HEZNKbMBVYjXxGlORG+Nvg069DoQoGnRg/b
n8SW0oeLctlZkcnEAX49NFakDtszzS9ru+hH5DBCP07KVWp7DAoXkbbdwuUCUAr9
IF57Q0rp84CDr24EoXOuOHiK5lf5IdKC2JFvhYvNM6sf3SHSjHOzqVyv7piW9fGq
NiAbQaE4ja+XJWtV3qw8GVyRKerDyZUo2vcTW9MsNDwH8TIirEf348pmeRO3T2mI
0t2/iyMsY8S/hkq/GUS/t2h+5WLHQGkMHpHrMWjGVEnyg8EVpOVLxPNYKQllpIHE
3KsQhrogQnb4gVPPMl3w7haHYnYGEyd/STPb94Crr5SQLUWgW10iemE42p36M5Zq
WjWCJh1D3qKGNtL5aJZl87NpZWSPoDOvBmaZ5pd3p/NCyWJ4p9upIoFjPVkCAwEA
AQKCAgBRyAn5Fa3BChIXmiEUcVuoqfjTbmR4RJy7YiNLMAGl0Uo13Bf8xp3N/bZf
ULhWTZ41sGW9qLRaT64FoSWTSmg1+XNWsW0GQJHqQgiRHGOr40rE9PZ9WoP8rp90
TlQKwRZDztqMFiJVFyi6yAb1q75oDZj1O4DPVa/c4hEIr/0wUstjiD4/cMOvcAbq
KO6QvuiVfrauuhmpHrKNwlbliq7VAz+kh8Ey00vV1qTR++ILDmGO9x/hp7UkL1o3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0o6+sPve4CIECE4NSMCQdE/K1JPAvF+yZwHlVUZacX+a5M=
-----END RSA PRIVATE KEY-----
1 change: 1 addition & 0 deletions src/config/baker_rsa.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCo+YRhI2Gjno+5ND+N/pBvvw7Bvji6OEtZgUKvJf8P9rPcUCR8w7DpDPTpLSM4spBqIwoEM1CQRnH8x/Ufvhr51tU/74A4J2MgBEjClI8M5Z8iqYhDWfoRywo/2uB1rrPHICIM716LRFGIDoqnt+leHU4wcfHmHNa8/KqC5tNxd9/VBxeveh0CIu7/Ba3/UVtn6CTY2sGMo0mJk0IjzIsK42TgRL7ZOTQfbo1Td3DpOCdt02xft5xXCk9KuRwwrjdtyZbP8n8xc7/YcRk0pswFViNfEaU5Eb42+DTr0OhCgadGD9ufxJbSh4ty2VmRycQBfj00VqQO2zPNL2u76EfkMEI/TspVansMCheRtt3C5QJQCv0gXntDSunzgIOvbgShc644eIrmV/kh0oLYkW+Fi80zqx/dIdKMc7OpXK/umJb18ao2IBtBoTiNr5cla1XerDwZXJEp6sPJlSja9xNb0yw0PAfxMiKsR/fjymZ5E7dPaYjS3b+LIyxjxL+GSr8ZRL+3aH7lYsdAaQwekesxaMZUSfKDwRWk5UvE81gpCWWkgcTcqxCGuiBCdviBU88yXfDuFodidgYTJ39JM9v3gKuvlJAtRaBbXSJ6YTjanfozlmpaNYImHUPeooY20vlolmXzs2llZI+gM68GZpnml3en80LJYnin26kigWM9WQ== [email protected]
2 changes: 1 addition & 1 deletion src/installers/linux/deb-template/baker/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: Baker
Version: 0.2.0
Version: 0.3.0
Section: base
Priority: optional
Architecture: amd64
Expand Down
2 changes: 1 addition & 1 deletion src/installers/macos/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PACKAGEREL="installers/macos"
IDENTIFIER="io.ottomatica.$NAME"

# Package version number.
VERSION="0.0.1"
VERSION="0.3.0"

# The location to copy the contents of files.
INSTALL_LOCATION="/opt/baker/bin"
Expand Down
4 changes: 2 additions & 2 deletions src/installers/win/scripts/baker.iss
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{FF82CC8F-9CAD-4210-97AA-2C5F955DB742}
AppName=Baker
AppVersion=0.0.1
;AppVerName=Baker 0.0.1
AppVersion=0.3.0
;AppVerName=Baker 0.3.0
AppPublisher=Ottomatica LLC
AppPublisherURL=https://getbaker.io/
AppSupportURL=https://getbaker.io/
Expand Down
48 changes: 48 additions & 0 deletions src/lib/bakerlets/env/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { commands, modules } = require('../../../baker');
const baker = modules['baker'];
const ssh = modules['ssh'];

const Bakerlet = require('../bakerlet');
const path = require('path');
const mustache = require('mustache');
const fs = require('fs-extra');

class Env extends Bakerlet {
constructor(name, ansibleSSHConfig, version) {
super(ansibleSSHConfig);

this.name = name;
this.version = version;
}

async load(obj, variables) {
this.variables = variables;
this.envVars = {env: []};

obj.env.forEach( e => {
this.envVars.env.push({KEY: Object.keys(e)[0], VALUE: Object.values(e)[0]})
})

let playbookTemplate = path.resolve(
this.remotesPath,
`bakerlets-source/env/env.yml.mustache`
);
let playbookRendered = mustache.render(await fs.readFileAsync(playbookTemplate, 'utf8'), this.envVars);

let cmd = `echo "${playbookRendered.replace(/"/g, '\\"')}" > /home/vagrant/baker/${this.name}/env.yml`;
await this.exec(cmd);
}

async install() {
var cmd = `env.yml`;
await baker.runAnsiblePlaybook(
{ name: this.name },
cmd,
this.ansibleSSHConfig,
this.verbose,
this.variables
);
}
}

module.exports = Env;
16 changes: 15 additions & 1 deletion src/lib/bakerlets/lang/nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const baker = modules['baker'];

const Bakerlet = require('../bakerlet');
const path = require('path');
const fs = require('fs');

class Nodejs extends Bakerlet {

Expand All @@ -29,7 +30,20 @@ class Nodejs extends Bakerlet {
await baker.runAnsiblePlaybook(
{name: this.name}, cmd, this.ansibleSSHConfig, this.verbose, this.variables
);
//console.log(`installed java ${this.version}`);

var localPackageJsonPath = path.resolve(this.bakePath, "package.json");
if( fs.existsSync(localPackageJsonPath) )
{
// There could be some funkyness depending on if there is a package-lock.json, etc:
// and node_modules is manually deleted:
// https://github.com/ansible/ansible/pull/29131
var vmPackagePath = `/${path.basename(this.bakePath)}`;
if( this.verbose ) console.log(`Attempting to run npm install in vm at ${vmPackagePath}`);
await baker.runAnsibleNpmInstall(
{name: this.name}, vmPackagePath, this.ansibleSSHConfig, this.verbose
);
}

}


Expand Down
17 changes: 15 additions & 2 deletions src/lib/bakerlets/lang/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ const baker = modules['baker'];

const Bakerlet = require('../bakerlet');
const path = require('path');
const fs = require('fs');

class Python extends Bakerlet {

constructor(name, ansibleSSHConfig, version) {
super(ansibleSSHConfig);

this.name = name;
this.version = version;

// Default to python2
this.version = version || 2;
}

async load(obj, variables)
Expand All @@ -27,6 +28,18 @@ class Python extends Bakerlet {
await baker.runAnsiblePlaybook(
{name: this.name}, cmd, this.ansibleSSHConfig, this.verbose, this.variables
);

// Check for a requirements.txt and then run pip install -r requirements.txt
// TODO: Possible to allow a requirements: parameter in the python object.
// Otherwise, we might just want it in the packages: pip: requirements: path
var localRequirementsPath = path.resolve(this.bakePath, "requirements.txt");
if( fs.existsSync(localRequirementsPath) )
{
var vmRequirementsPath = `/${path.basename(this.bakePath)}/requirements.txt`;
await baker.runAnsiblePipInstall(
{name: this.name}, vmRequirementsPath, this.ansibleSSHConfig, this.verbose
);
}
}


Expand Down
27 changes: 21 additions & 6 deletions src/lib/bakerlets/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ module.exports.resolveBakerlet = async function(bakerletsPath,remotesPath,doc,ba
}
}

if( doc.env )
{
doc.env = [{env: doc.env}]; // fixing the format // TODO: it works ok, but probably too hacky
await resolve(doc.name, bakerScriptPath, remotesPath, path.join(bakerletsPath,"env"), doc.env[0], extra_vars, verbose);
}

if( doc.start )
{
let dir = path.join(boxes, doc.name);
Expand Down Expand Up @@ -115,16 +121,25 @@ async function resolve(vmName, bakerScriptPath, remotesPath, dir, bakerlet, extr
}
else
{
let regex = /([a-zA-Z-]+)([0-9]*\.?[0-9]*)/;
// This will correctly match neo4j3.3, java8, python etc.
let regex = /([a-zA-Z-0-9]*)([0-9]+\.?[0-9]*$)|([a-zA-Z-0-9]*)/;
mod = dir + "/" + bakerlet;
let match = bakerlet.match(regex);
version = null;
if( match.length == 3)
if( match.length == 4)
{
mod = dir + "/" + match[1];
version = match[2];
if( match[1] === undefined && match[2] === undefined )
{
// We did not capture anything in the first part of regex. So, we have no version, just the mod.
// This is captured in third group.
mod = dir + "/" + match[3];
}
else
{
mod = dir + "/" + match[1];
version = match[2];
}
}
if( verbose ) console.log("Found", mod, version);
if( verbose ) console.log("Found", mod, version, extra_vars);
}

let classFoo = require(mod)
Expand Down
36 changes: 36 additions & 0 deletions src/lib/bakerlets/services/neo4j.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { commands, modules } = require('../../../baker');
const baker = modules['baker'];
const ssh = modules['ssh'];


const Bakerlet = require('../bakerlet');
const path = require('path');

class Neo4j extends Bakerlet {

constructor(name,ansibleSSHConfig, version) {
super(ansibleSSHConfig);

this.name = name;
this.version = version;

}

async load(obj, variables)
{
this.variables = variables;

let playbook = path.resolve(this.remotesPath, `bakerlets-source/services/neo4j/neo4j${this.version}.yml`);
await this.copy(playbook,`/home/vagrant/baker/${this.name}/neo4j${this.version}.yml`);
}

async install()
{
var cmd = `neo4j${this.version}.yml`;
await baker.runAnsiblePlaybook(
{name: this.name}, cmd, this.ansibleSSHConfig, this.verbose, this.variables
);
}
}

module.exports = Neo4j;
Loading

0 comments on commit 9e8cb65

Please sign in to comment.