
* New pod stx-docker running "docker-in-docker" image * New optional env var STX_INSECURE_DOCKER_REGISTRIES to disable SSL validation for select registries in stx-docker * stx-builder: install docker client in POD image * stx-builder: add env vars that point docker client to the new docker service POD TESTS ===== * Rebuild all build images * Make sure docker works within "builder" pod: - docker pull - docker build - docker login - docker push - docker run with volume mounts under /localdisk/{loadbuild,designer}, make sure these location are visible and can be mounted by the docker service Story: 2009897 Task: 44691 Change-Id: I2b51c5f90bf2dee1ed6a159c60d76fc05e1f325a Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
128 lines
3.8 KiB
Python
128 lines
3.8 KiB
Python
#
|
|
# Copyright (c) 2022 Wind River Systems, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
import logging
|
|
import os
|
|
import re
|
|
|
|
from stx import stx_configparser
|
|
from stx import utils
|
|
|
|
logger = logging.getLogger('STX-Config')
|
|
utils.set_logger(logger)
|
|
|
|
|
|
def require_env(var):
|
|
value = os.getenv(var)
|
|
if value is None:
|
|
logger.error(
|
|
f'{var} not found in the environment')
|
|
logger.error(
|
|
'Please source the file \'import-stx\' to define the ' +
|
|
f'{var} variable and execute \'stx-init-env\' to start builder pods')
|
|
raise LookupError(f'{var} not found in the environment!')
|
|
return value
|
|
|
|
|
|
class Config:
|
|
"""Configuration interface.
|
|
|
|
This class provides a read-only interface to project
|
|
configuration.
|
|
|
|
Usage
|
|
=====
|
|
::
|
|
from stx import config
|
|
|
|
# load once
|
|
config = Config().load()
|
|
|
|
# use this instance throughout the app
|
|
value = config.get ('section', 'key')
|
|
|
|
# returns "minikube -p $PROFILE kubectl -n $NAMESPACE --"
|
|
# or similar
|
|
# kubectl_command = config.kubectl()
|
|
"""
|
|
|
|
def __init__(self):
|
|
"""Construct an empty instance; must call "load" explicitly before using"""
|
|
self.prjdir = require_env('PRJDIR')
|
|
self.config_filename = os.path.join(self.prjdir, 'stx.conf')
|
|
self.use_minikube = os.getenv('STX_PLATFORM', 'minikube') == 'minikube'
|
|
if self.use_minikube:
|
|
self.minikube_profile = require_env('MINIKUBENAME')
|
|
else:
|
|
self.k8s_namespace = os.getenv('STX_K8S_NAMESPACE')
|
|
|
|
self.build_home = require_env('STX_BUILD_HOME')
|
|
self.docker_tag = require_env('DOCKER_TAG_LOCAL')
|
|
self.kubectl_cmd = None
|
|
self.helm_cmd = None
|
|
|
|
reg_list_str = os.getenv('STX_INSECURE_DOCKER_REGISTRIES')
|
|
if reg_list_str:
|
|
self._insecure_docker_reg_list = re.split(r'[ \t;,]+', reg_list_str)
|
|
else:
|
|
self._insecure_docker_reg_list = []
|
|
|
|
def load(self):
|
|
"""Load stx.conf"""
|
|
self.data = stx_configparser.STXConfigParser(self.config_filename)
|
|
self._init_kubectl_cmd()
|
|
return self
|
|
|
|
def get(self, section, key):
|
|
"""Get a config value"""
|
|
assert self.data
|
|
return self.data.getConfig(section, key)
|
|
|
|
def impl(self):
|
|
"""Internal object that stores configuration"""
|
|
return self.data
|
|
|
|
def prjdir(self):
|
|
"""Path of starlingx/tools checkout"""
|
|
return self.prjdir
|
|
|
|
def kubectl(self):
|
|
"""Returns the command for invoking kubect"""
|
|
assert self.data
|
|
return self.kubectl_cmd
|
|
|
|
def helm(self):
|
|
"""Returns the command for invoking helm"""
|
|
assert self.data
|
|
return self.helm_cmd
|
|
|
|
@property
|
|
def insecure_docker_reg_list(self):
|
|
"""List of insecure docker registries we are allowed to access"""
|
|
return self._insecure_docker_reg_list
|
|
|
|
def _init_kubectl_cmd(self):
|
|
# helm
|
|
self.helm_cmd = 'helm'
|
|
# kubectl
|
|
if self.use_minikube:
|
|
self.kubectl_cmd = f'minikube -p {self.minikube_profile} kubectl --'
|
|
else:
|
|
self.kubectl_cmd = 'kubectl'
|
|
# Kubernetes namespace
|
|
if self.k8s_namespace:
|
|
self.kubectl_cmd += f' -n {self.k8s_namespace}'
|
|
self.helm_cmd += f' -n {self.k8s_namespace}'
|