Pass through more storage endpoint info
- Compact env vars - Azure file endpoint - Docker private registry realm
This commit is contained in:
Родитель
ee242c21d6
Коммит
a99bee7100
|
@ -12,8 +12,7 @@ import azure.storage.table as azuretable
|
|||
|
||||
# global defines
|
||||
_DEFAULT_PRIVATE_REGISTRY_PORT = 5000
|
||||
_STORAGEACCOUNT = os.environ['PRIVATE_REGISTRY_SA']
|
||||
_STORAGEACCOUNTKEY = os.environ['PRIVATE_REGISTRY_SAKEY']
|
||||
_CASCADE_STORAGEACCOUNT = None
|
||||
_BATCHACCOUNT = os.environ['AZ_BATCH_ACCOUNT_NAME']
|
||||
_POOLID = os.environ['AZ_BATCH_POOL_ID']
|
||||
_NODEID = os.environ['AZ_BATCH_NODE_ID']
|
||||
|
@ -35,15 +34,17 @@ def _setup_container_names(sep: str):
|
|||
(sep + 'registry', _BATCHACCOUNT.lower(), _POOLID.lower()))
|
||||
|
||||
|
||||
def _create_credentials() -> tuple:
|
||||
def _create_credentials() -> azure.storage.table.TableService:
|
||||
"""Create storage credentials
|
||||
:rtype: azure.storage.table.TableService
|
||||
:return: table client
|
||||
"""
|
||||
ep = os.getenv('CASCADE_EP') or 'core.windows.net'
|
||||
global _CASCADE_STORAGEACCOUNT
|
||||
_CASCADE_STORAGEACCOUNT, ep, sakey = os.environ[
|
||||
'CASCADE_STORAGE_ENV'].split(':')
|
||||
table_client = azuretable.TableService(
|
||||
account_name=_STORAGEACCOUNT,
|
||||
account_key=_STORAGEACCOUNTKEY,
|
||||
account_name=_CASCADE_STORAGEACCOUNT,
|
||||
account_key=sakey,
|
||||
endpoint_suffix=ep)
|
||||
return table_client
|
||||
|
||||
|
@ -83,8 +84,7 @@ async def _start_private_registry_instance_async(
|
|||
if proc.returncode != 0:
|
||||
raise RuntimeError('docker load non-zero rc: {}'.format(
|
||||
proc.returncode))
|
||||
sa = os.getenv('PRIVATE_REGISTRY_SA') or _STORAGEACCOUNT
|
||||
sakey = os.getenv('PRIVATE_REGISTRY_SAKEY') or _STORAGEACCOUNTKEY
|
||||
sa, ep, sakey = os.environ['PRIVATE_REGISTRY_STORAGE_ENV'].split(':')
|
||||
registry_cmd = [
|
||||
'docker', 'run', '-d', '-p',
|
||||
'{p}:{p}'.format(p=_DEFAULT_PRIVATE_REGISTRY_PORT),
|
||||
|
@ -92,6 +92,7 @@ async def _start_private_registry_instance_async(
|
|||
'-e', 'REGISTRY_STORAGE_AZURE_ACCOUNTNAME={}'.format(sa),
|
||||
'-e', 'REGISTRY_STORAGE_AZURE_ACCOUNTKEY={}'.format(sakey),
|
||||
'-e', 'REGISTRY_STORAGE_AZURE_CONTAINER={}'.format(container),
|
||||
'-e', 'REGISTRY_STORAGE_AZURE_REALM={}'.format(ep),
|
||||
'--restart=always', '--name=registry', 'registry:2',
|
||||
]
|
||||
print('starting private registry on port {} -> {}:{}'.format(
|
||||
|
@ -136,7 +137,7 @@ async def setup_private_registry_async(
|
|||
'RowKey': _NODEID,
|
||||
'IpAddress': ipaddress,
|
||||
'Port': _DEFAULT_PRIVATE_REGISTRY_PORT,
|
||||
'StorageAccount': _STORAGEACCOUNT,
|
||||
'StorageAccount': _CASCADE_STORAGEACCOUNT,
|
||||
'Container': container,
|
||||
}
|
||||
table_client.insert_or_replace_entity(
|
||||
|
@ -145,6 +146,13 @@ async def setup_private_registry_async(
|
|||
|
||||
def main():
|
||||
"""Main function"""
|
||||
# delete existing private registry file if it exists
|
||||
cprfile = pathlib.Path('.cascade_private_registry.txt')
|
||||
try:
|
||||
cprfile.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
# get command-line args
|
||||
args = parseargs()
|
||||
container, regarchive, regimageid = args.settings.split(':')
|
||||
|
@ -166,10 +174,11 @@ def main():
|
|||
|
||||
# set up private registry
|
||||
loop.run_until_complete(setup_private_registry_async(
|
||||
loop, table_client, args.ipaddress, container, regarchive, regimageid))
|
||||
loop, table_client, args.ipaddress, container, regarchive,
|
||||
regimageid))
|
||||
|
||||
# create a private registry file to notify cascade
|
||||
pathlib.Path('.cascade_private_registry.txt').touch()
|
||||
cprfile.touch()
|
||||
|
||||
# stop asyncio loop
|
||||
loop.stop()
|
||||
|
@ -185,8 +194,7 @@ def parseargs():
|
|||
description='Install Docker Private Registry')
|
||||
parser.add_argument(
|
||||
'settings',
|
||||
help='private registry settings '
|
||||
'[container:archive:imageid]')
|
||||
help='private registry settings [container:archive:imageid]')
|
||||
parser.add_argument(
|
||||
'ipaddress', nargs='?', default=None, help='ip address')
|
||||
parser.add_argument(
|
||||
|
|
35
shipyard.py
35
shipyard.py
|
@ -265,6 +265,7 @@ def setup_azurefile_volume_driver(
|
|||
# construct systemd env file
|
||||
sa = None
|
||||
sakey = None
|
||||
saep = None
|
||||
for svkey in config[
|
||||
'global_resources']['docker_volumes']['shared_data_volumes']:
|
||||
conf = config[
|
||||
|
@ -273,13 +274,13 @@ def setup_azurefile_volume_driver(
|
|||
# check every entry to ensure the same storage account
|
||||
ssel = conf['storage_account_settings']
|
||||
_sa = config['credentials']['storage'][ssel]['account']
|
||||
_sakey = config['credentials']['storage'][ssel]['account_key']
|
||||
if sa is not None and sa != _sa:
|
||||
raise ValueError(
|
||||
'multiple storage accounts are not supported for '
|
||||
'azurefile docker volume driver')
|
||||
sa = _sa
|
||||
sakey = _sakey
|
||||
sakey = config['credentials']['storage'][ssel]['account_key']
|
||||
saep = config['credentials']['storage'][ssel]['endpoint']
|
||||
if sa is None or sakey is None:
|
||||
raise RuntimeError(
|
||||
'storage account or storage account key not specified for '
|
||||
|
@ -288,6 +289,7 @@ def setup_azurefile_volume_driver(
|
|||
with srvenv.open('w') as f:
|
||||
f.write('AZURE_STORAGE_ACCOUNT={}\n'.format(sa))
|
||||
f.write('AZURE_STORAGE_ACCOUNT_KEY={}\n'.format(sakey))
|
||||
f.write('AZURE_STORAGE_BASE={}\n'.format(saep))
|
||||
# create docker volume mount command script
|
||||
volcreate = pathlib.Path('resources/azurefile-dockervolume-create.sh')
|
||||
with volcreate.open('w') as f:
|
||||
|
@ -345,10 +347,10 @@ def add_pool(
|
|||
nonp2pcd = True
|
||||
# private registry settings
|
||||
try:
|
||||
preg = config['docker_registry']['private']['enabled']
|
||||
pcont = config['docker_registry']['private']['container']
|
||||
pregpubpull = config['docker_registry']['private'][
|
||||
'allow_public_docker_hub_pull_on_missing']
|
||||
preg = config['docker_registry']['private']['enabled']
|
||||
except KeyError:
|
||||
preg = False
|
||||
pregpubpull = False
|
||||
|
@ -437,8 +439,8 @@ def add_pool(
|
|||
config['pool_specification']['additional_node_prep_commands'])
|
||||
except KeyError:
|
||||
pass
|
||||
ssel = config['docker_registry']['private']['storage_account_settings']
|
||||
# create pool param
|
||||
ssel = config['credentials']['shipyard_storage']
|
||||
pool = batchmodels.PoolAddParameter(
|
||||
id=config['pool_specification']['id'],
|
||||
virtual_machine_configuration=batchmodels.VirtualMachineConfiguration(
|
||||
|
@ -453,16 +455,18 @@ def add_pool(
|
|||
wait_for_success=True,
|
||||
environment_settings=[
|
||||
batchmodels.EnvironmentSetting('LC_ALL', 'en_US.UTF-8'),
|
||||
batchmodels.EnvironmentSetting('CASCADE_SA', _STORAGEACCOUNT),
|
||||
batchmodels.EnvironmentSetting(
|
||||
'CASCADE_SAKEY', _STORAGEACCOUNTKEY),
|
||||
batchmodels.EnvironmentSetting(
|
||||
'CASCADE_EP',
|
||||
config['credentials']['storage'][ssel]['endpoint']),
|
||||
'CASCADE_STORAGE_ENV',
|
||||
'{}:{}:{}'.format(
|
||||
_STORAGEACCOUNT,
|
||||
config['credentials']['storage'][ssel]['endpoint'],
|
||||
_STORAGEACCOUNTKEY)
|
||||
)
|
||||
],
|
||||
resource_files=[],
|
||||
),
|
||||
)
|
||||
del ssel
|
||||
for rf in sas_urls:
|
||||
pool.start_task.resource_files.append(
|
||||
batchmodels.ResourceFile(
|
||||
|
@ -470,16 +474,17 @@ def add_pool(
|
|||
blob_source=sas_urls[rf])
|
||||
)
|
||||
if preg:
|
||||
ssel = config['docker_registry']['private']['storage_account_settings']
|
||||
pool.start_task.environment_settings.append(
|
||||
batchmodels.EnvironmentSetting(
|
||||
'PRIVATE_REGISTRY_SA',
|
||||
config['credentials']['storage'][ssel]['account'])
|
||||
)
|
||||
pool.start_task.environment_settings.append(
|
||||
batchmodels.EnvironmentSetting(
|
||||
'PRIVATE_REGISTRY_SAKEY',
|
||||
'PRIVATE_REGISTRY_STORAGE_ENV',
|
||||
'{}:{}:{}'.format(
|
||||
config['credentials']['storage'][ssel]['account'],
|
||||
config['credentials']['storage'][ssel]['endpoint'],
|
||||
config['credentials']['storage'][ssel]['account_key'])
|
||||
)
|
||||
)
|
||||
del ssel
|
||||
if (dockeruser is not None and len(dockeruser) > 0 and
|
||||
dockerpw is not None and len(dockerpw) > 0):
|
||||
pool.start_task.environment_settings.append(
|
||||
|
|
Загрузка…
Ссылка в новой задаче