Skip to content

Commit 86b6ad5

Browse files
author
Xantios Krugor
committed
Added support for LetsEncrypt
1 parent 753608e commit 86b6ad5

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

app/ApiClient.js

+40-4
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,59 @@ class ApiClient {
7171

7272
createVhost(id,name,target,port=80,secure=false) {
7373

74+
/**
75+
* {
76+
* "domain_names":["cokemaster.xantios.nl"],
77+
* "forward_scheme":"http",
78+
* "forward_host":"10.13.37.254",
79+
* "forward_port":1337,
80+
* "access_list_id":"0",
81+
* "certificate_id":"new",
82+
* "ssl_forced":true,
83+
* "meta":{
84+
* "letsencrypt_email":"info@xantios.nl",
85+
* "letsencrypt_agree":true
86+
* },
87+
* "advanced_config":"",
88+
* "locations":[],
89+
* "block_exploits":false,
90+
* "caching_enabled":false,
91+
* "allow_websocket_upgrade":false,
92+
* "http2_support":false,
93+
* "hsts_enabled":false,
94+
* "hsts_subdomains":false
95+
* }
96+
*/
97+
7498
const metadata = {
7599
automagic:"true",
76100
name: name,
77-
id: id
101+
id: id,
102+
secure: secure
78103
};
79104

80-
const data = {
105+
let data = {
81106
domain_names: [ name ],
82-
forward_scheme: (secure) ? 'https' : 'http',
107+
forward_scheme: 'http',
83108
forward_host: target,
84109
forward_port: port,
85-
advanced_config: "# [metadata]=["+JSON.stringify(metadata)+"]"
110+
advanced_config: "# [metadata]=["+JSON.stringify(metadata)+"]",
111+
meta: {}
86112
};
87113

114+
if(secure) {
115+
116+
data.certificate_id = "new";
117+
data.ssl_forced = secure;
118+
119+
data.meta.letsencrypt_email = process.env['le_email'];
120+
data.meta.letsencrypt_agree = true;
121+
}
122+
88123
this.axios.post('nginx/proxy-hosts',data)
89124
.then(resp => {
90125
console.log('Created vhost!');
126+
console.log('==> ',data);
91127
})
92128
.catch(e => {
93129
// console.error(e);

app/ContainerEvents.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,28 @@ class ContainerEvents {
4040
// use Vhost port if defined, else use first port in map
4141
const port = (vhost_port) ? parseInt(vhost_port.split('=')[1]) : ports[0];
4242

43+
// Generate cert?
44+
let generateCert = data.Config.Env.find(item => {
45+
let kv = item.split('=');
46+
return (kv[0] == "GEN_CERT" && kv[1] == "true")
47+
});
48+
49+
let secure = false;
50+
if(generateCert) {
51+
secure = true;
52+
}
53+
54+
let cert = (secure) ? 'yes' : 'no';
55+
4356
// Create
44-
console.log('Mapping V-Host ' + vhost + " => " + ip + ":" + port);
45-
this.api.createVhost(msg.id,vhost, ip, port);
57+
console.log(`Mapping V-Host ${vhost} => ${ip}:${port} (certificate: ${cert})`);
58+
this.api.createVhost(msg.id,vhost, ip, port,secure);
4659
});
4760
}
4861

4962
remove(msg) {
5063
this.api.deleteVhost(msg.id);
5164
}
52-
5365
}
5466

55-
5667
export default ContainerEvents;

app/NetworkEvents.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ class NetworkEvents {
108108
if(!vhost) return false;
109109
if(network.Name == "host" || network.Name == "bridge" || network.name == this.exclude) return false;
110110

111-
await this.connect(container_id,network_id);
111+
//
112+
// await this.connect(container_id,network_id);
113+
114+
// Connect the parent container to the new network
115+
await this.connect(this.parent.Id,network_id);
112116
}
113117

114118
async connect(container_id,network_id) {

docker-compose.example.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ services:
3232
environment:
3333
username: '[email protected]' # your npm login
3434
password: 'superdupersecret' # npm password
35+
le_email: '[email protected]'
3536
volumes:
3637
- /var/run/docker.sock:/var/run/docker.sock
3738

0 commit comments

Comments
 (0)