-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·62 lines (46 loc) · 1.72 KB
/
main.py
File metadata and controls
executable file
·62 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
import click
from server_providers import ServerProvider
from dns_providers import DnsProvider
from configuration import Configuration
from prepare_server_and_run_ansible import Server
@click.group()
def cli():
pass
@cli.command()
@click.argument('file_name', type=click.Path(exists=True))
def deploy(file_name):
config = Configuration.from_manifest(file_name)
server_provider = ServerProvider(config)
server_info = server_provider.fetch_provisioned_server()
if server_info != None:
click.echo(f"Server {server_info.ipv4} ({server_info.ipv6}) already provisioned")
else:
click.echo(f"Provisioning server...")
server_info = server_provider.provision_server()
click.echo(f"Server {server_info.ipv4} ({server_info.ipv6}) successfully provisioned")
config.render_ansible_vars()
dns_provider = DnsProvider(config, server_info)
dns_provider.render_dns_config()
s = Server(server_info.ipv4)
s.prepare_server_and_run_ansible()
print(f"Server {server_info.ipv4} ({server_info.ipv6}) is now set up")
print("Setting up DNS")
s.run_dnscontrol()
hostnames = dns_provider.get_hostnames()
for hostname in hostnames:
print(f"Waiting for DNS update for {hostname}")
s.wait_for_dns(hostname, [server_info.ipv4, server_info.ipv6])
print(f"DNS record successfully updated")
print(f"Restarting services")
s.restart_reverse_proxy()
print(f"\n-----\n")
print(f"ServeInfo:")
print(f" IPv4: {server_info.ipv4}")
print(f" IPv6: {server_info.ipv6}")
print(f"")
print(f"Deployed Web Apps:")
for hostname in hostnames:
print(f" https://{hostname}")
if __name__ == '__main__':
cli()