Skip to content

Commit c495c35

Browse files
committed
use ssh-tunnel port if present
1 parent 166164c commit c495c35

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
@@ -73,7 +73,7 @@ The Redis host. If [url](#url) is defined, then this option is not needed.
7373

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

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

7878
### database
7979

@@ -222,18 +222,13 @@ Add set up your `deploy.js` similar to the following:
222222
```js
223223
'redis': {
224224
host: "localhost",
225-
port: 49156
226225
},
227226
'ssh-tunnel': {
228227
username: "your-ssh-username",
229228
host: "remote-redis-host"
230-
srcPort: 49156
231229
}
232230
```
233231

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

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

261+
The following properties are used if present on the deployment `context` object:
262+
263+
- `tunnel.srcPort` (provided by [ember-cli-deploy-ssh-tunnel][7])
264+
268265
## Running Tests
269266

270267
- `npm test`
@@ -275,3 +272,4 @@ The following properties are expected to be present on the deployment `context`
275272
[4]: https://github.com/ember-cli-deploy/ember-cli-deploy-build "ember-cli-deploy-build"
276273
[5]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy"
277274
[6]: https://github.com/ember-cli-deploy/ember-cli-deploy-revision-data "ember-cli-deploy-revision-data"
275+
[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;
@@ -42,6 +48,7 @@ module.exports = {
4248
},
4349
redisDeployClient: function(context) {
4450
var redisOptions = this.pluginConfig;
51+
redisOptions.port = this.readConfig('port');
4552
var redisLib = context._redisLib;
4653

4754
return new Redis(redisOptions, redisLib);

tests/unit/index-nodetest.js

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

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

0 commit comments

Comments
 (0)