Skip to content

Commit 58f23a8

Browse files
authored
fix(medic#8205): Adds nginx resolver (medic#8206)
Adds `resolver` directive make nginx responsive to dynamic docker network IP allocation when containers are restarted. medic#8205
1 parent 74e6bfd commit 58f23a8

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Diff for: nginx/templates/server.conf.template

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
resolver 127.0.0.11 valid=10s; # 127.0.0.11 is from default /etc/resolv.conf
2+
set $upstream_endpoint http://${API_HOST}:${API_PORT};
3+
14
location / {
2-
proxy_pass http://${API_HOST}:${API_PORT};
5+
proxy_pass $upstream_endpoint;
36
proxy_set_header Host $host;
47
proxy_set_header X-Real-IP $remote_addr;
58
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Diff for: tests/integration/.mocharc.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const chaiAsPromised = require('chai-as-promised');
33
const chai = require('chai');
44
chai.use(chaiExclude);
55
chai.use(chaiAsPromised);
6+
global.expect = chai.expect;
67

78
module.exports = {
89
allowUncaught: false,

Diff for: tests/integration/api/server.spec.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const utils = require('../../utils');
22
const request = require('request');
33
const constants = require('../../constants');
44
const _ = require('lodash');
5-
const {expect} = require('chai');
65

76
describe('server', () => {
87
describe('JSON-only endpoints', () => {
@@ -181,4 +180,15 @@ describe('server', () => {
181180
expect(attachmentBody).to.equal(png);
182181
});
183182
});
183+
184+
describe('DNS resolver', () => {
185+
it('nginx should resolve updated api ips', async () => {
186+
await utils.stopHaproxy();
187+
await utils.stopApi();
188+
await utils.startHaproxy();
189+
await utils.startApi();
190+
191+
await utils.request('/');
192+
});
193+
});
184194
});

Diff for: tests/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,8 @@ module.exports = {
12451245
await startService('api');
12461246
await listenForApi();
12471247
},
1248+
stopHaproxy: () => stopService('haproxy'),
1249+
startHaproxy: () => startService('haproxy'),
12481250

12491251
saveCredentials: (key, password) => {
12501252
const options = {

0 commit comments

Comments
 (0)