Skip to content

Commit

Permalink
remove dependency to ResourceMaker
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Oct 17, 2023
1 parent 4e94a17 commit 5c67a04
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hello.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
with:
environment: DEV
command: |
zrb explain solid
zrb explain solid-principle
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ playground
.coverage.*
.env
.venv
.docker-dir
docker/._docker-compose.*.runtime.yml
htmlcov
File renamed without changes.
5 changes: 4 additions & 1 deletion docker-template/Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/zrb/task/docker_compose_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
106 changes: 69 additions & 37 deletions zrb_init.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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='',
Expand Down Expand Up @@ -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']
)
Expand All @@ -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']
)
Expand All @@ -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)
Expand All @@ -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']
)
Expand All @@ -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']
)
Expand All @@ -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']
)
Expand Down

0 comments on commit 5c67a04

Please sign in to comment.