Skip to content

Commit

Permalink
use ssh-tunnel port if present
Browse files Browse the repository at this point in the history
  • Loading branch information
ssendev committed Oct 12, 2015
1 parent 166164c commit c495c35
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 9 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The Redis host. If [url](#url) is defined, then this option is not needed.

The Redis port. If [url](#url) is defined, then this option is not needed.

*Default:* `6379`
*Default:* `6379` or `context.tunnel.srcPort` if present (set by [ember-cli-deploy-ssh-tunnel][7])

### database

Expand Down Expand Up @@ -222,18 +222,13 @@ Add set up your `deploy.js` similar to the following:
```js
'redis': {
host: "localhost",
port: 49156
},
'ssh-tunnel': {
username: "your-ssh-username",
host: "remote-redis-host"
srcPort: 49156
}
```

_(NB: by default `ssh-tunnel` assigns a random port for srcPort, but we need that
to be the same for our `redis` config, so I've just hardcoded it above)_

### What if my Redis server is only accessible *from* my remote server?

Sometimes you need to SSH into a server (a "bastion" server) and then run
Expand All @@ -245,12 +240,10 @@ your Redis host as the destination host, like so:
```js
'redis': {
host: "localhost",
port: 49156
},
'ssh-tunnel': {
username: "your-ssh-username",
host: "remote-redis-host"
srcPort: 49156,
dstHost: "location-of-your-elasticache-node-or-remote-redis"
}
```
Expand All @@ -265,6 +258,10 @@ The following properties are expected to be present on the deployment `context`
- `commandLineArgs.revisionKey` (provided by [ember-cli-deploy][5])
- `deployEnvironment` (provided by [ember-cli-deploy][5])

The following properties are used if present on the deployment `context` object:

- `tunnel.srcPort` (provided by [ember-cli-deploy-ssh-tunnel][7])

## Running Tests

- `npm test`
Expand All @@ -275,3 +272,4 @@ The following properties are expected to be present on the deployment `context`
[4]: https://github.com/ember-cli-deploy/ember-cli-deploy-build "ember-cli-deploy-build"
[5]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy"
[6]: https://github.com/ember-cli-deploy/ember-cli-deploy-revision-data "ember-cli-deploy-revision-data"
[7]: https://github.com/ember-cli-deploy/ember-cli-deploy-ssh-tunnel "ember-cli-deploy-ssh-tunnel"
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ module.exports = {
name: options.name,
defaultConfig: {
host: 'localhost',
port: 6379,
port: function(context) {
if (context.tunnel && context.tunnel.srcPort) {
return context.tunnel.srcPort;
} else {
return 6379;
}
},
filePattern: 'index.html',
distDir: function(context) {
return context.distDir;
Expand All @@ -42,6 +48,7 @@ module.exports = {
},
redisDeployClient: function(context) {
var redisOptions = this.pluginConfig;
redisOptions.port = this.readConfig('port');
var redisLib = context._redisLib;

return new Redis(redisOptions, redisLib);
Expand Down
72 changes: 72 additions & 0 deletions tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,78 @@ describe('redis plugin', function() {
assert.equal(redisLib.createdClient.options.database, 4);
});

describe('resolving port from the pipeline', function() {
it('uses the config data if it already exists', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
port: 1234,
};
var context = {
ui: mockUi,
project: stubProject,
config: {
redis: config
},
tunnel: {
srcPort: '2345'
}
};

plugin.beforeHook(context);
plugin.configure(context);
assert.equal(plugin.readConfig('port'), '1234');
});

it('uses the context value if it exists and config doesn\'t', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
};
var context = {
ui: mockUi,
project: stubProject,
config: {
redis: config
},
tunnel: {
srcPort: '2345'
}
};

plugin.beforeHook(context);
plugin.configure(context);
assert.equal(plugin.readConfig('port'), '2345');
});

it('uses the default port if config and context don\'t exist', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
};
var context = {
ui: mockUi,
project: stubProject,
config: {
redis: config
}
};

plugin.beforeHook(context);
plugin.configure(context);
assert.equal(plugin.readConfig('port'), '6379');
});
});

describe('resolving revisionKey from the pipeline', function() {
it('uses the config data if it already exists', function() {
var plugin = subject.createDeployPlugin({
Expand Down

0 comments on commit c495c35

Please sign in to comment.