add dry-run

This commit is contained in:
Snowyo 2018-08-05 01:05:20 +02:00
parent 3cb95ccf5f
commit 6c64962026

View File

@ -81,6 +81,7 @@ def restartContainerWithDomains(domains):
restartDomains = str.split(c.labels["com.github.SnowMB.traefik-certificate-extractor.restart_domain"], ',') restartDomains = str.split(c.labels["com.github.SnowMB.traefik-certificate-extractor.restart_domain"], ',')
if not set(domains).isdisjoint(restartDomains): if not set(domains).isdisjoint(restartDomains):
print('restarting container ' + c.id) print('restarting container ' + c.id)
if not args.dry:
c.restart() c.restart()
@ -122,6 +123,7 @@ def createCerts(args):
cert = fullchain[0:start] cert = fullchain[0:start]
chain = fullchain[start:] chain = fullchain[start:]
if not args.dry:
# Create domain directory if it doesn't exist # Create domain directory if it doesn't exist
directory = Path(args.directory) directory = Path(args.directory)
if not directory.exists(): if not directory.exists():
@ -215,6 +217,8 @@ if __name__ == "__main__":
help='outputs all certificates into one folder') help='outputs all certificates into one folder')
parser.add_argument('-r', '--restart_container', action='store_true', parser.add_argument('-r', '--restart_container', action='store_true',
help='uses the docker API to restart containers that are labeled accordingly') help='uses the docker API to restart containers that are labeled accordingly')
parser.add_argument('--dry-run', action='store_true', dest='dry',
help="Don't write files and do not start docker containers.")
group = parser.add_mutually_exclusive_group() group = parser.add_mutually_exclusive_group()
group.add_argument('--include', nargs='*') group.add_argument('--include', nargs='*')
group.add_argument('--exclude', nargs='*') group.add_argument('--exclude', nargs='*')