mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Improve foreman image src selection
This commit is contained in:
parent
87eca24969
commit
d5b340cc43
1 changed files with 38 additions and 7 deletions
|
@ -4,6 +4,7 @@
|
||||||
from __future__ import absolute_import, print_function
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
CloudProvider,
|
CloudProvider,
|
||||||
|
@ -31,7 +32,26 @@ class ForemanProvider(CloudProvider):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DOCKER_SIMULATOR_NAME = 'foreman-stub'
|
DOCKER_SIMULATOR_NAME = 'foreman-stub'
|
||||||
DOCKER_SIMULATOR_IMAGE_NAME = 'foreman-simulator'
|
DOCKER_SIMULATOR_IMAGE_NAME = 'ansible/foreman-test-container'
|
||||||
|
DOCKER_SIMULATOR_IMAGE_TAG = '1.0.0'
|
||||||
|
|
||||||
|
DOCKER_IMAGES = {
|
||||||
|
'hub': {
|
||||||
|
'registry_url': 'registry.hub.docker.com',
|
||||||
|
'img_name': DOCKER_SIMULATOR_IMAGE_NAME,
|
||||||
|
'img_tag': DOCKER_SIMULATOR_IMAGE_TAG,
|
||||||
|
},
|
||||||
|
'quay': {
|
||||||
|
'registry_url': 'quay.io',
|
||||||
|
'img_name': DOCKER_SIMULATOR_IMAGE_NAME,
|
||||||
|
'img_tag': DOCKER_SIMULATOR_IMAGE_TAG,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
"""Image registry to pull Foreman stub from.
|
||||||
|
|
||||||
|
It's source source itself resides at:
|
||||||
|
https://github.com/ansible/foreman-test-container
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
"""Set up container references for provider.
|
"""Set up container references for provider.
|
||||||
|
@ -41,12 +61,23 @@ class ForemanProvider(CloudProvider):
|
||||||
super(ForemanProvider, self).__init__(args)
|
super(ForemanProvider, self).__init__(args)
|
||||||
|
|
||||||
self.__container_from_env = os.getenv('ANSIBLE_FRMNSIM_CONTAINER')
|
self.__container_from_env = os.getenv('ANSIBLE_FRMNSIM_CONTAINER')
|
||||||
self.image = self.__container_from_env or (
|
"""Overrides target container, might be used for development.
|
||||||
'ansible/ansible:%s'
|
|
||||||
|
Use ANSIBLE_FRMNSIM_CONTAINER={hub|quay|whatever_you_want} if you want
|
||||||
|
to be explicit. Omit/empty otherwise.
|
||||||
|
"""
|
||||||
|
|
||||||
|
image_src = self.DOCKER_IMAGES.get(self.__container_from_env, {})
|
||||||
|
if not image_src and self.__container_from_env:
|
||||||
|
self.image = self.__container_from_env
|
||||||
|
else:
|
||||||
|
self.image = (
|
||||||
# The simulator must be pinned to a specific version
|
# The simulator must be pinned to a specific version
|
||||||
# to guarantee CI passes with the version used:
|
# to guarantee CI passes with the version used:
|
||||||
'@sha256:soooomeinvaaalidddshaaa'
|
'{registry_url}/{img_name}:{img_tag}'
|
||||||
) % self.DOCKER_SIMULATOR_IMAGE_NAME
|
).format(
|
||||||
|
**(image_src or random.choice(self.DOCKER_IMAGES))
|
||||||
|
)
|
||||||
self.container_name = ''
|
self.container_name = ''
|
||||||
|
|
||||||
def filter(self, targets, exclude):
|
def filter(self, targets, exclude):
|
||||||
|
|
Loading…
Reference in a new issue