Pārlūkot izejas kodu

Check that certificate file exists before we create the service.

This closes csmith/docker-service-nginx#2

Requires that `letsencrypt-data` volume is mounted at /letsencrypt in csmith/docker-automatic-nginx-letsencrypt
pull/3/head
Shane Mc Cormack 6 gadus atpakaļ
vecāks
revīzija
42235d4f1b
1 mainītis faili ar 13 papildinājumiem un 10 dzēšanām
  1. 13
    10
      generate.py

+ 13
- 10
generate.py Parādīt failu

4
 import etcdlib
4
 import etcdlib
5
 import jinja2
5
 import jinja2
6
 import os
6
 import os
7
+import os.path
7
 
8
 
8
 parser = argparse.ArgumentParser()
9
 parser = argparse.ArgumentParser()
9
 parser.add_argument('--name', help='Name of the docker host to request certificates for', default='unknown')
10
 parser.add_argument('--name', help='Name of the docker host to request certificates for', default='unknown')
26
   defaults = fetcher.get_label('com.chameth.proxy.default')
27
   defaults = fetcher.get_label('com.chameth.proxy.default')
27
   for container, values in fetcher.get_label('com.chameth.proxy').items():
28
   for container, values in fetcher.get_label('com.chameth.proxy').items():
28
     networks = fetcher.get_networks(container)
29
     networks = fetcher.get_networks(container)
29
-    services.append({
30
-      'protocol': protocols[container] if container in protocols else 'http',
31
-      'vhosts': domains[container],
32
-      'host': next(iter(networks.values())), # TODO: Pick a bridge sensibly?
33
-      'port': values,
34
-      'certificate': args.cert_path % domains[container][0],
35
-      'trusted_certificate': args.trusted_cert_path % domains[container][0],
36
-      'certificate_key': args.cert_key_path % domains[container][0],
37
-      'default': container in defaults,
38
-    })
30
+    certfile = args.cert_path % domains[container][0];
31
+    if os.path.isfile(certfile):
32
+      services.append({
33
+        'protocol': protocols[container] if container in protocols else 'http',
34
+        'vhosts': domains[container],
35
+        'host': next(iter(networks.values())), # TODO: Pick a bridge sensibly?
36
+        'port': values,
37
+        'certificate': args.cert_path % domains[container][0],
38
+        'trusted_certificate': args.trusted_cert_path % domains[container][0],
39
+        'certificate_key': args.cert_key_path % domains[container][0],
40
+        'default': container in defaults,
41
+      })
39
 
42
 
40
   with open('/nginx-config/vhosts.conf', 'w') as f:
43
   with open('/nginx-config/vhosts.conf', 'w') as f:
41
     print('Writing vhosts.conf...', flush=True)
44
     print('Writing vhosts.conf...', flush=True)

Notiek ielāde…
Atcelt
Saglabāt