Skip to content

Commit

Permalink
reverted to working configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Neagu committed May 17, 2022
1 parent 3c39a03 commit 2c71811
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 84 deletions.
15 changes: 7 additions & 8 deletions src/docker_publisher_osparc_services/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from . import __version__
from .gitlab_ci_setup.commands import (
assemble_env_vars,
get_build_commands,
get_push_commands,
get_test_commands,
COMMANDS_BUILD,
COMMANDS_PUSH,
COMMANDS_TEST_BASE,
validate_commands_list,
)
from .gitlab_ci_setup.pipeline_config import PipelineConfig, PipelineGenerator
Expand Down Expand Up @@ -77,26 +77,25 @@ async def run_command(config: Path) -> None:
# build commands validation
env_vars = assemble_env_vars(
repo_model=repo_model,
image_name=image_name,
registries=cfg.registries,
tag=tag,
)
image_count = len(repo_model.registry.local_to_test)

build_commands = get_build_commands(image_count)
build_commands = COMMANDS_BUILD
validate_commands_list(build_commands, env_vars)

# check if test stage is required
test_commands = None
if repo_model.ci_stage_test_script is not None:
# test commands assembly and validation
test_commands = (
get_test_commands(image_count)
+ repo_model.ci_stage_test_script
COMMANDS_TEST_BASE + repo_model.ci_stage_test_script
)
validate_commands_list(test_commands, env_vars)

# deploy stage validation
push_commands = get_push_commands(image_count)
push_commands = COMMANDS_PUSH
validate_commands_list(push_commands, env_vars)

pipeline_config = PipelineConfig(
Expand Down
108 changes: 32 additions & 76 deletions src/docker_publisher_osparc_services/gitlab_ci_setup/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,107 +5,63 @@

from ..models import RegistryEndpointyModel, RepoModel

CommandList = List[str]

DOCKER_LOGIN: str = (
"echo ${SCCI_TARGET_REGISTRY_PASSWORD} | "
"docker login ${SCCI_TARGET_REGISTRY_ADDRESS} --username ${SCCI_TARGET_REGISTRY_USER} --password-stdin"
)

CommandList = List[str]

def get_build_commands(image_count: int) -> CommandList:
commands: CommandList = [
"git clone ${SCCI_REPO} ${SCCI_CLONE_DIR}",
"cd ${SCCI_CLONE_DIR}",
"ooil compose",
"docker-compose build",
DOCKER_LOGIN,
]

for k in range(image_count):
commands.append(
"docker tag ${SCCI_IMAGE_NAME_%s}:${SCCI_TAG} ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_TEST_IMAGE_%s}:${SCCI_TAG}"
% (k, k)
)
commands.append(
"docker push ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_TEST_IMAGE_%s}:${SCCI_TAG}"
% (k)
)

return commands


def get_test_commands(image_count: int) -> CommandList:
commands: CommandList = [
"git clone ${SCCI_REPO} ${SCCI_CLONE_DIR}",
"cd ${SCCI_CLONE_DIR}",
DOCKER_LOGIN,
"docker pull ${SCCI_CI_IMAGE_NAME}:${SCCI_TAG}",
]

for k in range(image_count):
commands.append("docker pull ${SCCI_CI_IMAGE_NAME_%s}:${SCCI_TAG}" % (k))

return commands


def get_push_commands(image_count: int) -> CommandList:
commands: CommandList = [
DOCKER_LOGIN,
]

for k in range(image_count):
commands.append(
"docker pull ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_TEST_IMAGE_%s}:${SCCI_TAG}"
% (k)
)

commands.append(
"docker tag ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_TEST_IMAGE_%s}:${SCCI_TAG} ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_RELEASE_IMAGE_%s}:${SCCI_TAG}"
% (k, k)
)
commands.append(
"docker push ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_RELEASE_IMAGE_%s}:${SCCI_TAG}"
% (k)
)

return commands
COMMANDS_BUILD: CommandList = [
"git clone ${SCCI_REPO} ${SCCI_CLONE_DIR}",
"cd ${SCCI_CLONE_DIR}",
"ooil compose",
"docker-compose build",
DOCKER_LOGIN,
"docker tag ${SCCI_IMAGE_NAME}:${SCCI_TAG} ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_TEST_IMAGE}:${SCCI_TAG}",
"docker push ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_TEST_IMAGE}:${SCCI_TAG}",
]

COMMANDS_TEST_BASE: CommandList = [
"git clone ${SCCI_REPO} ${SCCI_CLONE_DIR}",
"cd ${SCCI_CLONE_DIR}",
DOCKER_LOGIN,
"docker pull ${SCCI_CI_IMAGE_NAME}:${SCCI_TAG}",
# if user defines extra commands those will be append here
]

COMMANDS_PUSH: CommandList = [
DOCKER_LOGIN,
"docker pull ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_TEST_IMAGE}:${SCCI_TAG}",
"docker tag ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_TEST_IMAGE}:${SCCI_TAG} ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_RELEASE_IMAGE}:${SCCI_TAG}",
"docker push ${SCCI_TARGET_REGISTRY_ADDRESS}/${SCCI_RELEASE_IMAGE}:${SCCI_TAG}",
]


def assemble_env_vars(
repo_model: RepoModel,
registries: Dict[str, RegistryEndpointyModel],
image_name: str,
tag: str,
) -> Dict[str, str]:
clone_directory: Path = Path(TemporaryDirectory().name)

registry: RegistryEndpointyModel = registries[repo_model.registry.target]
test_image = repo_model.registry.local_to_test[image_name]
release_image = repo_model.registry.test_to_release[test_image]

env_vars: Dict[str, str] = {
return {
"SCCI_REPO": repo_model.escaped_repo,
"SCCI_CLONE_DIR": f"{clone_directory}",
"SCCI_IMAGE_NAME": image_name,
"SCCI_TAG": tag,
"SCCI_TEST_IMAGE": test_image,
"SCCI_RELEASE_IMAGE": release_image,
"SCCI_TARGET_REGISTRY_ADDRESS": registry.address,
"SCCI_TARGET_REGISTRY_PASSWORD": registry.password.get_secret_value(),
"SCCI_TARGET_REGISTRY_USER": registry.user,
}

# for multiple image builds
local_images: List[str] = list(repo_model.registry.local_to_test.keys())
test_images: List[str] = list(repo_model.registry.local_to_test.values())
release_images: List[str] = list(repo_model.registry.test_to_release.values())

for k, image_name in enumerate(local_images):
env_vars[f"SCCI_IMAGE_NAME_{k}"] = image_name

for k, image_name in enumerate(test_images):
env_vars[f"SCCI_TEST_IMAGE_{k}"] = image_name

for k, image_name in enumerate(release_images):
env_vars[f"SCCI_RELEASE_IMAGE_{k}"] = image_name

return env_vars


def validate_commands_list(
commands_list: CommandList, env_vars: Dict[str, str]
Expand Down

0 comments on commit 2c71811

Please sign in to comment.