Skip to content

use ssh-tunnel port if present #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukemelia How do you feel about this modifying the config object? Feels like this is a perfect candidate for need to have passed in a clone of the config so that any modifications to it don't affect anything outside this hook.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achambers Every default config value has this issue. Maybe the right path is for ember-cli-deploy to clone the config once per plugin. Anyway, not an issue for this PR in particular.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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