Skip to content

Commit 1df912d

Browse files
committed
Merge pull request #38 from ssendev/patch-1
use ssh-tunnel port if present
2 parents c49bf7e + c495c35 commit 1df912d

File tree

3 files changed

+86
-9
lines changed

3 files changed

+86
-9
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The Redis host. If [url](#url) is defined, then this option is not needed.
7272

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

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

7777
### database
7878

@@ -227,18 +227,13 @@ Add set up your `deploy.js` similar to the following:
227227
```js
228228
'redis': {
229229
host: "localhost",
230-
port: 49156
231230
},
232231
'ssh-tunnel': {
233232
username: "your-ssh-username",
234233
host: "remote-redis-host"
235-
srcPort: 49156
236234
}
237235
```
238236

239-
_(NB: by default `ssh-tunnel` assigns a random port for srcPort, but we need that
240-
to be the same for our `redis` config, so I've just hardcoded it above)_
241-
242237
### What if my Redis server is only accessible *from* my remote server?
243238

244239
Sometimes you need to SSH into a server (a "bastion" server) and then run
@@ -250,12 +245,10 @@ your Redis host as the destination host, like so:
250245
```js
251246
'redis': {
252247
host: "localhost",
253-
port: 49156
254248
},
255249
'ssh-tunnel': {
256250
username: "your-ssh-username",
257251
host: "remote-redis-host"
258-
srcPort: 49156,
259252
dstHost: "location-of-your-elasticache-node-or-remote-redis"
260253
}
261254
```
@@ -270,6 +263,10 @@ The following properties are expected to be present on the deployment `context`
270263
- `commandLineArgs.revisionKey` (provided by [ember-cli-deploy][5])
271264
- `deployEnvironment` (provided by [ember-cli-deploy][5])
272265

266+
The following properties are used if present on the deployment `context` object:
267+
268+
- `tunnel.srcPort` (provided by [ember-cli-deploy-ssh-tunnel][7])
269+
273270
## Running Tests
274271

275272
- `npm test`
@@ -280,3 +277,4 @@ The following properties are expected to be present on the deployment `context`
280277
[4]: https://github.com/ember-cli-deploy/ember-cli-deploy-build "ember-cli-deploy-build"
281278
[5]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy"
282279
[6]: https://github.com/ember-cli-deploy/ember-cli-deploy-revision-data "ember-cli-deploy-revision-data"
280+
[7]: https://github.com/ember-cli-deploy/ember-cli-deploy-ssh-tunnel "ember-cli-deploy-ssh-tunnel"

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ module.exports = {
2020
name: options.name,
2121
defaultConfig: {
2222
host: 'localhost',
23-
port: 6379,
23+
port: function(context) {
24+
if (context.tunnel && context.tunnel.srcPort) {
25+
return context.tunnel.srcPort;
26+
} else {
27+
return 6379;
28+
}
29+
},
2430
filePattern: 'index.html',
2531
distDir: function(context) {
2632
return context.distDir;
@@ -43,6 +49,7 @@ module.exports = {
4349
},
4450
redisDeployClient: function(context) {
4551
var redisOptions = this.pluginConfig;
52+
redisOptions.port = this.readConfig('port');
4653
var redisLib = context._redisLib;
4754

4855
return new Redis(redisOptions, redisLib);

tests/unit/index-nodetest.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,78 @@ describe('redis plugin', function() {
9393
assert.equal(redisLib.createdClient.options.database, 4);
9494
});
9595

96+
describe('resolving port from the pipeline', function() {
97+
it('uses the config data if it already exists', function() {
98+
var plugin = subject.createDeployPlugin({
99+
name: 'redis'
100+
});
101+
102+
var config = {
103+
host: 'somehost',
104+
port: 1234,
105+
};
106+
var context = {
107+
ui: mockUi,
108+
project: stubProject,
109+
config: {
110+
redis: config
111+
},
112+
tunnel: {
113+
srcPort: '2345'
114+
}
115+
};
116+
117+
plugin.beforeHook(context);
118+
plugin.configure(context);
119+
assert.equal(plugin.readConfig('port'), '1234');
120+
});
121+
122+
it('uses the context value if it exists and config doesn\'t', function() {
123+
var plugin = subject.createDeployPlugin({
124+
name: 'redis'
125+
});
126+
127+
var config = {
128+
host: 'somehost',
129+
};
130+
var context = {
131+
ui: mockUi,
132+
project: stubProject,
133+
config: {
134+
redis: config
135+
},
136+
tunnel: {
137+
srcPort: '2345'
138+
}
139+
};
140+
141+
plugin.beforeHook(context);
142+
plugin.configure(context);
143+
assert.equal(plugin.readConfig('port'), '2345');
144+
});
145+
146+
it('uses the default port if config and context don\'t exist', function() {
147+
var plugin = subject.createDeployPlugin({
148+
name: 'redis'
149+
});
150+
151+
var config = {
152+
host: 'somehost',
153+
};
154+
var context = {
155+
ui: mockUi,
156+
project: stubProject,
157+
config: {
158+
redis: config
159+
}
160+
};
161+
162+
plugin.beforeHook(context);
163+
plugin.configure(context);
164+
assert.equal(plugin.readConfig('port'), '6379');
165+
});
166+
});
167+
96168
describe('resolving revisionKey from the pipeline', function() {
97169
it('uses the config data if it already exists', function() {
98170
var plugin = subject.createDeployPlugin({

0 commit comments

Comments
 (0)