Skip to content

Commit

Permalink
#16: Add express example for elasticsearch (non-working).
Browse files Browse the repository at this point in the history
  • Loading branch information
reynoldsalec committed Jul 10, 2017
1 parent 997af82 commit cd415b5
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 7 deletions.
2 changes: 2 additions & 0 deletions examples/elasticsearch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.log
42 changes: 42 additions & 0 deletions examples/elasticsearch/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# elasticsearch example
name: elasticsearch

# Give me http://elasticsearch.lndo.site
proxy:
appserver:
- port: 80/tcp
default: true

# Spin up a basic nodes server with elasticsearch backend
services:

# Spin up a memcache container called "search"
# NOTE: "search" is arbitrary, you could just as well call this "theboss" or "eljefe"
search:

# Use version 5.4 of elasticsearch
type: elasticsearch:5.4

# Optionally allow access to the cache at localhost:9999
# You will need to make sure port 9999 is open on your machine
#
# You can also set `portforward: true` to have Lando dynamically assign
# a port. Unlike specifying an actual port setting this to true will give you
# a different port every time you restart your app
portforward: 9999

# Spin up services to run a basic node server
appserver:
type: node:6.10
command: npm start
build:
- "cd $LANDO_MOUNT & npm install"

# Add some nice command routing
tooling:
npm:
service: appserver
gulp:
service: appserver
node:
service: appserver
38 changes: 38 additions & 0 deletions examples/elasticsearch/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Lando node elasticsearch example
*
* @name taylorswift
*/

'use strict';

// Load modules
var http = require('http');
var express = require('express');
var Elasticsearch = require('elasticsearch');
var app = express();

// Get our elasticsearch client
var elasticsearch = new Elasticsearch.Client({
host: 'search:9999',
log: 'trace'
});

// Create our servers
http.createServer(app).listen(80);

// Try to connect to elasticsearch.
app.get('/', function(req, res) {

res.header('Content-type', 'text/html');
var info = 'Elasticsearch is not up.';
elasticsearch.ping({
}, function (error) {
if (error) {
console.log(error);
return res.end('elasticsearch cluster is down!' + JSON.stringify(error, null, 2));
} else {
return res.end('All is well.');
}
});
});
26 changes: 26 additions & 0 deletions examples/elasticsearch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "elasticsearch-lando",
"version": "1.0.0",
"description": "Elasticsearch example for Lando.",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm install && node app.js"
},
"repository": {
"type": "git",
"url": "https://github.com/kalabox/lando/tree/master/examples/elasticsearch"
},
"keywords": [
"node",
"docker",
"localdev",
"elasticsearch"
],
"author": "Alec Reynolds",
"license": "MIT",
"dependencies": {
"elasticsearch": "^13.2.0",
"express": "^4.15.3"
}
}
2 changes: 1 addition & 1 deletion examples/lamp/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
appserver:

# PHP version 5.6
type: php:5.6
type: php:5.4

# Serve php by either apache or nginx. You can put in any `service:version`
# string that is supported by Lando's nginx and apache services.
Expand Down
14 changes: 8 additions & 6 deletions plugins/lando-services/elasticsearch/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = function(lando) {
* Supported versions for elasticsearch
*/
var versions = [
'5.5.0',
'5.4',
'latest',
];

/**
Expand All @@ -40,29 +41,30 @@ module.exports = function(lando) {

// Default elasticsearch service
var elastic = {
image: 'docker.elastic.co/elasticsearch/elasticsearch:' + config.version,
command: '/usr/share/elasticsearch/bin/elasticsearch',
image: 'itzg/elasticsearch:' + config.version,
command: '/start',
environment: {
LANDO_NO_SCRIPTS: 'true',
TERM: 'xterm',
'HTTP.HOST': '0.0.0.0',
'TRANSPORT.HOST': '127.0.0.1',
'NODE.MASTER': 'false',
'DISCOVERY.ZEN.PING.UNICAST.HOSTS': 'elasticsearch1'
},
}
};

// Handle port forwarding
if (config.portforward) {

// If true assign a port automatically
if (config.portforward === true) {
elastic.ports = ['9200'];
elastic.ports = ['9200', '9300'];
}

// Else use the specified port
else {
elastic.ports = [config.portforward + ':9200'];
var newPort = config.portforward + 100;
elastic.ports = [config.portforward + ':9200', newPort + ':9300'];
}

}
Expand Down

0 comments on commit cd415b5

Please sign in to comment.