From 5c67a04641f8b9f195fedf1b8b06d748750aedb2 Mon Sep 17 00:00:00 2001 From: goFrendiAsgard Date: Wed, 18 Oct 2023 06:18:31 +0700 Subject: [PATCH] remove dependency to ResourceMaker --- .github/workflows/hello.yml | 2 +- .gitignore | 2 +- {docker-template => docker}/.dockerignore | 0 {docker-template => docker}/Dockerfile | 5 +- .../docker-compose.yml | 2 + src/zrb/task/docker_compose_task.py | 2 +- zrb_init.py | 106 ++++++++++++------ 7 files changed, 78 insertions(+), 41 deletions(-) rename {docker-template => docker}/.dockerignore (100%) rename {docker-template => docker}/Dockerfile (57%) rename {docker-template => docker}/docker-compose.yml (89%) diff --git a/.github/workflows/hello.yml b/.github/workflows/hello.yml index 7a351532..a8a29edd 100644 --- a/.github/workflows/hello.yml +++ b/.github/workflows/hello.yml @@ -8,4 +8,4 @@ jobs: with: environment: DEV command: | - zrb explain solid + zrb explain solid-principle diff --git a/.gitignore b/.gitignore index 9e3440d9..3a4b9395 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,5 @@ playground .coverage.* .env .venv -.docker-dir +docker/._docker-compose.*.runtime.yml htmlcov \ No newline at end of file diff --git a/docker-template/.dockerignore b/docker/.dockerignore similarity index 100% rename from docker-template/.dockerignore rename to docker/.dockerignore diff --git a/docker-template/Dockerfile b/docker/Dockerfile similarity index 57% rename from docker-template/Dockerfile rename to docker/Dockerfile index 542b581c..64c919b6 100644 --- a/docker-template/Dockerfile +++ b/docker/Dockerfile @@ -4,5 +4,8 @@ FROM python:3.10-bookworm RUN mkdir -p /project WORKDIR /project +# Define arguments +ARG ZRB_VERSION=latest + # Install zrb -RUN pip install zrb==ZRB_VERSION +RUN pip install zrb==${ZRB_VERSION} diff --git a/docker-template/docker-compose.yml b/docker/docker-compose.yml similarity index 89% rename from docker-template/docker-compose.yml rename to docker/docker-compose.yml index 85a74ce6..cc96716b 100644 --- a/docker-template/docker-compose.yml +++ b/docker/docker-compose.yml @@ -17,6 +17,8 @@ services: build: dockerfile: Dockerfile context: . + args: + ZRB_VERSION: ${ZRB_VERSION:-latest} image: ${ZRB_IMAGE:-docker.io/stalchmst/zrb} logging: *default-logging container_name: zrb diff --git a/src/zrb/task/docker_compose_task.py b/src/zrb/task/docker_compose_task.py index 130033c2..9ead401a 100644 --- a/src/zrb/task/docker_compose_task.py +++ b/src/zrb/task/docker_compose_task.py @@ -223,7 +223,7 @@ def _add_compose_envs(self): os_name = key if self._compose_env_prefix != '': os_name = f'{self._compose_env_prefix}_{os_name}' - self._envs.append(Env(name=key, os_name=os_name, default=value)) + self.add_envs(Env(name=key, os_name=os_name, default=value)) def _get_existing_env_map(self) -> Mapping[str, str]: env_map: Mapping[str, str] = {} diff --git a/zrb_init.py b/zrb_init.py index 7671dd0a..2fb8331c 100644 --- a/zrb_init.py +++ b/zrb_init.py @@ -1,6 +1,6 @@ from zrb import ( - runner, CmdTask, ResourceMaker, DockerComposeTask, FlowTask, - Env, BoolInput, StrInput, HTTPChecker, Group + runner, CmdTask, DockerComposeTask, FlowTask, HTTPChecker, + Env, Group, BoolInput, StrInput ) import os import sys @@ -33,6 +33,13 @@ # Input Definitions ############################################################################### +zrb_version_input = StrInput( + name='zrb-version', + description='Zrb version', + prompt='Zrb version', + default=VERSION +) + zrb_image_name_input = StrInput( name='zrb-image-name', description='Zrb image name', @@ -57,6 +64,12 @@ # Env Definitions ############################################################################### +zrb_version_env = Env( + name='ZRB_VERSION', + os_name='', + default='{{input.zrb_version}}' +) + zrb_image_env = Env( name='ZRB_IMAGE', os_name='', @@ -116,35 +129,28 @@ ) runner.register(publish_pip_test) -prepare_docker = ResourceMaker( - name='prepare-docker', - description='Create docker directory', - template_path=f'{CURRENT_DIR}/docker-template', - destination_path=f'{CURRENT_DIR}/.docker-dir', - replacements={ - 'ZRB_VERSION': VERSION - } -) -runner.register(prepare_docker) - check_pip = HTTPChecker( name='check-pip', + inputs=[zrb_version_input], is_https=True, host='pypi.org', - url=f'pypi/zrb/{VERSION}/json', + url='pypi/zrb/{{ input.zrb_version }}/json', port=443 ) build_image = DockerComposeTask( name='build-image', description='Build docker image', - upstreams=[ - prepare_docker, - check_pip, + upstreams=[check_pip], + inputs=[ + zrb_version_input, + zrb_image_name_input, ], - inputs=[zrb_image_name_input], - envs=[zrb_image_env], - cwd=f'{CURRENT_DIR}/.docker-dir', + envs=[ + zrb_version_env, + zrb_image_env, + ], + cwd=f'{CURRENT_DIR}/docker', compose_cmd='build', compose_args=['zrb'] ) @@ -154,13 +160,18 @@ name='build-latest-image', description='Build docker image', upstreams=[ - prepare_docker, check_pip, build_image, ], - inputs=[zrb_latest_image_name_input], - envs=[zrb_latest_image_env], - cwd=f'{CURRENT_DIR}/.docker-dir', + inputs=[ + zrb_version_input, + zrb_latest_image_name_input, + ], + envs=[ + zrb_version_env, + zrb_latest_image_env, + ], + cwd=f'{CURRENT_DIR}/docker', compose_cmd='build', compose_args=['zrb'] ) @@ -169,10 +180,13 @@ stop_container = DockerComposeTask( name='stop-container', description='remove docker container', - upstreams=[prepare_docker], - inputs=[zrb_image_name_input], - envs=[zrb_image_env], - cwd=f'{CURRENT_DIR}/.docker-dir', + inputs=[ + zrb_image_name_input + ], + envs=[ + zrb_image_env + ], + cwd=f'{CURRENT_DIR}/docker', compose_cmd='down' ) runner.register(stop_container) @@ -184,9 +198,15 @@ build_image, stop_container ], - inputs=[zrb_image_name_input], - envs=[zrb_image_env], - cwd=f'{CURRENT_DIR}/.docker-dir', + inputs=[ + zrb_version_input, + zrb_image_name_input, + ], + envs=[ + zrb_version_env, + zrb_image_env, + ], + cwd=f'{CURRENT_DIR}/docker', compose_cmd='up', compose_flags=['-d'] ) @@ -196,9 +216,15 @@ name='push-image', description='Push docker image', upstreams=[build_image], - inputs=[zrb_image_name_input], - envs=[zrb_image_env], - cwd=f'{CURRENT_DIR}/.docker-dir', + inputs=[ + zrb_version_input, + zrb_image_name_input, + ], + envs=[ + zrb_version_env, + zrb_image_env, + ], + cwd=f'{CURRENT_DIR}/docker', compose_cmd='push', compose_args=['zrb'] ) @@ -211,9 +237,15 @@ build_latest_image, push_image, ], - inputs=[zrb_latest_image_name_input], - envs=[zrb_latest_image_env], - cwd=f'{CURRENT_DIR}/.docker-dir', + inputs=[ + zrb_version_input, + zrb_latest_image_name_input, + ], + envs=[ + zrb_version_env, + zrb_latest_image_env, + ], + cwd=f'{CURRENT_DIR}/docker', compose_cmd='push', compose_args=['zrb'] )