-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
73 lines (58 loc) · 2.2 KB
/
Copy pathexample.py
File metadata and controls
73 lines (58 loc) · 2.2 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
63
64
65
66
67
68
69
70
71
72
73
"""Deploy a Docker container (optionally from an Azure registry) using Azure Container Service.
"""
import argparse
import os
import sys
from collections import namedtuple
import requests
from azure.common.credentials import ServicePrincipalCredentials
from deployers.container_deployer import ContainerDeployer
from deployers.acr_container_deployer import ACRContainerDeployer
DEFAULT_DOCKER_IMAGE = 'mesosphere/simple-docker'
ClientArgs = namedtuple('ClientArgs', ['credentials', 'subscription_id'])
def set_up_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
'--image', default=DEFAULT_DOCKER_IMAGE,
help='Docker image to deploy.'
)
parser.add_argument(
'--use-acr', action='store_const', dest='deployer',
default=ContainerDeployer, const=ACRContainerDeployer,
help='Add the image to an Azure Container Registry and deploy from there.'
)
parser.add_argument(
'-n', '--name', default='containersample',
help='String to use in resource name templates (--resource-group, etc.)'
)
parser.add_argument(
'-g', '--resource-group',
default='{name}-group',
help='Name of resource group to use. (If nonexistent it will be created.)'
)
return parser
def main():
parser = set_up_parser()
args = parser.parse_args()
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
tenant=os.environ['AZURE_TENANT_ID'],
)
deployer = args.deployer(
ClientArgs(
credentials,
os.environ['AZURE_SUBSCRIPTION_ID'],
),
args.image,
resource_group=args.resource_group.format(name=args.name),
container_service=args.name + 'service',
storage_account=args.name + 'storage',
container_registry=args.name + 'registry',
)
deployer.deploy()
print('\nContacting ACS cluster at http://{}'.format(deployer.public_ip()))
print('Response:')
print(requests.get('http://{}'.format(deployer.public_ip())).text)
if __name__ == '__main__':
sys.exit(main())