Skip to content

Commit

Permalink
apps2.0 - port and entrypoint from app config (#5)
Browse files Browse the repository at this point in the history
* start

* start debug server app with virtual net and port

* preLaunchTask + postDebugTask

* debug tasks done

* entrypoint from app config
  • Loading branch information
mkolomeychenko authored Jan 19, 2022
1 parent 23e8fba commit e972085
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ __pycache__
.idea
venv
secret.env
supervisely_lib
supervisely_lib
start.sh
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"type": "python",
"request": "launch",
"program": "agent/main.py",
"console": "integratedTerminal"
"console": "integratedTerminal",
"preLaunchTask": "create-network",
"postDebugTask": "remove-network"
}
]
}
33 changes: 33 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "create-network",
"type": "shell",
"command": "bash",
"args": [
"-c",
"docker network create supervisely-net 2> /dev/null"
],
"presentation": {
"reveal": "silent",
"clear": true
}
},
{
"label": "remove-network",
"type": "shell",
"command": "bash",
"args": [
"-c",
"docker network rm supervisely-net"
],
"presentation": {
"reveal": "silent",
"clear": true
}
}
]
}
10 changes: 6 additions & 4 deletions agent/worker/task_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def find_or_run_container(self):

def get_spawn_entrypoint(self):
inf_command = "while true; do sleep 30; done;"
self.logger.info("Infinit command", extra={"command": inf_command})
self.logger.info("Infinite command", extra={"command": inf_command})
return ["sh", "-c", inf_command]

def _exec_command(self, command, add_envs=None, container_id=None):
Expand All @@ -259,17 +259,17 @@ def _exec_command(self, command, add_envs=None, container_id=None):
def exec_command(self, add_envs=None, command=None):
add_envs = sly.take_with_default(add_envs, {})
main_script_path = os.path.join(self.dir_task_src_container, self.app_config.get('main_script', 'src/main.py'))

if command is None:
command = "python {}".format(main_script_path)

if "entrypoint" in self.app_config:
command = f'bash -c "cd {self.dir_task_src_container} && {self.app_config["entrypoint"]}"'
self.logger.info("command to run", extra={"command": command})

self._exec_command(command, add_envs)

#change pulling progress to app progress
progress_dummy = sly.Progress('Application is started ...', 1, ext_logger=self.logger)
progress_dummy.iter_done_report()

self.logger.info("command is running", extra={"command": command})

def install_pip_requirements(self, container_id=None):
Expand Down Expand Up @@ -323,6 +323,8 @@ def main_step_envs(self):

if constants.DOCKER_NET() is not None:
envs['VIRTUAL_HOST'] = f'task-{self.info["task_id"]}.supervisely.local'
envs['VIRTUAL_PORT'] = self.app_config.get("port", 8000)

return envs

def process_logs(self):
Expand Down
1 change: 1 addition & 0 deletions agent/worker/task_dockerized.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def spawn_container(self, add_envs=None, add_labels=None, entrypoint_func=None):
if add_envs is None:
add_envs = {}
add_envs['VIRTUAL_HOST'] = f'task-{self.info["task_id"]}.supervisely.local'
add_envs['VIRTUAL_PORT'] = self.app_config.get("port", 8000)

try:
self._container = self._docker_api.containers.run(
Expand Down
3 changes: 2 additions & 1 deletion debug.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ DOCKER_REGISTRY="in secret.env"
DOCKER_LOGIN="in secret.env"
DOCKER_PASSWORD="in secret.env"
LOG_LEVEL="DEBUG"
# DISABLE_TELEMETRY="1"
DISABLE_TELEMETRY="1"
DOCKER_NET="supervisely-net"

0 comments on commit e972085

Please sign in to comment.