Skip to content

Commit

Permalink
#140: Add helper script loading framework
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Jul 26, 2017
1 parent 6b246e9 commit 426fc8d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 4 deletions.
41 changes: 41 additions & 0 deletions examples/mysql-import/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The name of the app
name: mysql-import

# Give me http://mysql-import.lndo.site and https://mysql-import.lndo.site
proxy:
appserver:
- mysql-import.lndo.site

# Set up my services
services:

# Set up a basic webserver running the latest nginx with ssl turned on
appserver:
type: nginx
ssl: true
webroot: www

# Spin up a mariadb container called "database"
# NOTE: "database" is arbitrary, you could just as well call this "db" or "kanye"
db:

# Use the latest version of mysql
type: mysql

# Optionally forward out our port so we can access it at `localhost:someport`.
# This port will change every time you restart this app
#
# You can also set this to a static port you want to use `portforward:3311`.
# You will need to make sure the port is open and avialable
portforward: true

# Optionally change the default db credentials
# creds:
# user: mysql
# password: mysql
# database: mysql

# Optionally load in all the mysql config files in the config directory
# This is relative to the app root
# config:
# confd: config
21 changes: 21 additions & 0 deletions examples/mysql-import/www/50x.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>An error occurred.</h1>
<p>Sorry, the page you are looking for is currently unavailable.<br/>
Please try again later.</p>
<p>If you are the system administrator of this resource then you should check
the <a href="http://nginx.org/r/error_log">error log</a> for details.</p>
<p><em>Faithfully yours, nginx.</em></p>
</body>
</html>
6 changes: 6 additions & 0 deletions examples/mysql-import/www/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<title>ROLLING WITH THE HOMIES</title>
<h1>HOLLA!!! MySQL in da house.</h1>
<h2>and da GARAGE!!!</h2>
</html>
5 changes: 5 additions & 0 deletions plugins/lando-services/helpers/helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -e

echo thing
38 changes: 34 additions & 4 deletions plugins/lando-services/lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ module.exports = function(lando) {
lando.config.engineScriptsDir = scriptsDir;
lando.config.env.LANDO_ENGINE_SCRIPTS_DIR = scriptsDir;

// Set an envvar for our helpers directory
var helpersDir = path.join(__dirname, '..', 'helpers');
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;
Expand Down Expand Up @@ -163,13 +168,17 @@ module.exports = function(lando) {
};

/**
* Helper function to inject scripts
* Helper function to inject utility scripts
*/
var addScript = function(script, volumes) {
var addThing = function(script, volumes, here, there) {

// Set the base
var local = here || lando.config.engineScriptsDir;
var remote = there || 'scripts';

// Construct the local path
var localFile = path.join(lando.config.engineScriptsDir, script);
var scriptFile = '/scripts/' + script;
var localFile = path.join(local, script);
var scriptFile = '/' + remote + '/' + script;

// Filter the volumes by the host mount
volumes = _.filter(volumes, function(volume) {
Expand All @@ -182,11 +191,28 @@ module.exports = function(lando) {
// Push to volume
volumes.push([localFile, scriptFile].join(':'));

// Log
lando.log.verbose('Injecting %s from %s to %s', script, here, there);

// Return the volumes
return volumes;

};

/**
* Helper function to inject utility scripts
*/
var addHelper = function(script, volumes) {
return addThing(script, volumes, lando.config.engineHelpersDir, 'helpers');
};

/**
* Helper function to inject pre-run scripts
*/
var addScript = function(script, volumes) {
return addThing(script, volumes, lando.config.engineScriptsDir, 'scripts');
};

/**
* Delegator to gather info about a service for display to the user
*/
Expand Down Expand Up @@ -282,6 +308,9 @@ module.exports = function(lando) {
// Add in SSH key loading
services[name].volumes = addScript('load-keys.sh', services[name].volumes);

// Add generic helper scripts
services[name].volumes = addHelper('helper.sh', services[name].volumes);

// Add in any custom pre-runscripts
if (!_.isEmpty(config.scripts)) {
_.forEach(config.scripts, function(script) {
Expand Down Expand Up @@ -316,6 +345,7 @@ module.exports = function(lando) {
return {
add: add,
addConfig: addConfig,
addHelper: addHelper,
addScript: addScript,
build: build,
buildVolume: buildVolume,
Expand Down
5 changes: 5 additions & 0 deletions plugins/lando-services/scripts/lando-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ if [ -d "/scripts" ] && [ -z ${LANDO_NO_SCRIPTS+x} ]; then
find /scripts/ -type f -exec {} \;
fi;

# Executable all the helpers
if [ -d "/helpers" ] && [ -z ${LANDO_NO_SCRIPTS+x} ]; then
chmod +x /helpers/*
fi;

# Run the COMMAND
echo "Running command $@"
"$@"

0 comments on commit 426fc8d

Please sign in to comment.