Skip to content

Commit

Permalink
#140: Add mysql-import script
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Jul 26, 2017
1 parent 7ff8d20 commit 0dcfb03
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
7 changes: 7 additions & 0 deletions docs/changelog/2017.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v3.0.0-alpha.19 - In Development
-------------------------------

* Provided option handling for `tooling` routes [#141](https://github.com/kalabox/lando/issues/141)
* Added `mysql-import` helper [#140](https://github.com/kalabox/lando/issues/140)
* Added `pv` to all `php` images [#140](https://github.com/kalabox/lando/issues/140)

v3.0.0-alpha.18 - [July 22, 2017](https://github.com/kalabox/lando/releases/tag/v3.0.0-alpha.18)
-------------------------------

Expand Down
38 changes: 38 additions & 0 deletions plugins/lando-recipes/lamp/lamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,42 @@ module.exports = function(lando) {

};

/*
* Helper to return import tooling route
* @TODO: Add pgsql cmd at some point
*/
var dbImport = function() {
return {
service: 'appserver',
description: 'Import <file> into database. File is relative to approot.',
cmd: '/helpers/mysql-import.sh',
options: {
host: {
description: 'The database host',
alias: ['h']
},
user: {
description: 'The database user',
default: 'root',
alias: ['u']
},
database: {
description: 'The database name',
alias: ['d']
},
password: {
description: 'The database password',
alias: ['p']
},
port: {
description: 'The database port',
default: 3306,
alias: ['P']
}
}
};
};

/*
* Helper to return tooling config
*/
Expand Down Expand Up @@ -217,7 +253,9 @@ module.exports = function(lando) {
description: 'Drop into a MySQL shell',
user: 'root'
};
tooling['db-import <file>'] = dbImport();
}
// @todo: also need a pgimport cmd
else if (_.includes(database, 'postgres')) {
tooling.pgsql = {
service: 'database',
Expand Down
3 changes: 2 additions & 1 deletion plugins/lando-services/helpers/mysql-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ fi
# Put the pieces together
CMD="$CMD | mysql -h $HOST -P $PORT -u $USER"
if [ ! -z "$PASSWORD" ]; then
CMD="$CMD -p $PASSWORD $DATABASE"
CMD="$CMD -p$PASSWORD $DATABASE"
else
CMD="$CMD $DATABASE"
fi
echo $CMD

# Import
echo "Importing $FILE..."
Expand Down
20 changes: 12 additions & 8 deletions plugins/lando-services/lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ module.exports = function(lando) {

};

// Set an envvar for our config directory
var confDir = path.join(lando.config.userConfRoot, 'services', 'config');
lando.config.engineConfigDir = confDir;
lando.config.env.LANDO_ENGINE_CONFIG_DIR = confDir;

// Move our scripts over and set useful ENV we can use
var scriptsDir = path.join(__dirname, '..', 'scripts');
scriptsDir = moveConfig('scripts', scriptsDir);
Expand All @@ -103,14 +108,10 @@ module.exports = function(lando) {

// Set an envvar for our helpers directory
var helpersDir = path.join(__dirname, '..', 'helpers');
helpersDir = moveConfig('helpers', helpersDir);
lando.config.engineHelpersDir = helpersDir;
lando.config.env.LANDO_ENGINE_HELPERS_DIR = helpersDir;

// Set an envvar for our config directory
var confDir = path.join(lando.config.userConfRoot, 'services', 'config');
lando.config.engineConfigDir = confDir;
lando.config.env.LANDO_ENGINE_CONFIG_DIR = confDir;

// Registry of services
var registry = {};

Expand Down Expand Up @@ -305,11 +306,14 @@ module.exports = function(lando) {
vols.push('$LANDO_ENGINE_SCRIPTS_DIR/user-perms.sh:/user-perms.sh');
services[name].volumes = _.uniq(vols);

// Add in SSH key loading
// Add SSH key loading to every container
services[name].volumes = addScript('load-keys.sh', services[name].volumes);

// Add generic helper scripts
services[name].volumes = addHelper('mysql-import.sh', services[name].volumes);
// Add generic helper scripts to every contaniner
var helpers = ['mysql-import.sh'];
_.forEach(helpers, function(helper) {
services[name].volumes = addHelper(helper, services[name].volumes);
});

// Add in any custom pre-runscripts
if (!_.isEmpty(config.scripts)) {
Expand Down

0 comments on commit 0dcfb03

Please sign in to comment.