From e469330b4b676756071407405abe8bb80194ecef Mon Sep 17 00:00:00 2001 From: pierlauro Date: Wed, 18 Mar 2020 14:13:17 +0100 Subject: [PATCH 1/7] Added command syntax --- scompose/project/instance.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scompose/project/instance.py b/scompose/project/instance.py index 966253e..5bbfbf9 100644 --- a/scompose/project/instance.py +++ b/scompose/project/instance.py @@ -41,6 +41,7 @@ def __init__(self, name, working_dir, sudo=False, params=None): self.instance = None self.sudo = sudo self.set_name(name, params) + self.set_args(params) self.set_context(params) self.set_volumes(params) self.set_ports(params) @@ -139,6 +140,10 @@ def set_ports(self, params): # Commands + def set_args(self, params): + """set arguments to the startscript""" + self.args = params.get("command", "") + def _get_network_commands(self, ip_address=None): """take a list of ports, return the list of --network-args to ensure they are bound correctly. @@ -505,9 +510,9 @@ def create(self, ip_address=None, sudo=False, writable_tmpfs=False): options += ["--writable-tmpfs"] # Show the command to the user - commands = "%s %s %s" % (" ".join(options), image, self.name) + commands = "%s %s %s %s" % (" ".join(options), image, self.name, self.command) bot.debug("singularity instance start %s" % commands) self.instance = self.client.instance( - name=self.name, sudo=self.sudo, options=options, image=image + name=self.name, sudo=self.sudo, options=options, image=image, args=self.args ) From 9f06ed1fa671a693c3500d2323b23f409a8732fb Mon Sep 17 00:00:00 2001 From: pierlauro Date: Wed, 18 Mar 2020 14:17:27 +0100 Subject: [PATCH 2/7] Update changelog and version --- CHANGELOG.md | 1 + scompose/version.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae17680..4274526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are: The versions coincide with releases on pypi. ## [0.0.x](https://github.com/singularityhub/singularity-compose/tree/master) (0.0.x) + - command, ability to associate arguments to the instance's startscript (0.0.19) - depends\_on, check circular dependencies at startup and shutdown in reverse order (0.0.18) - resolv.conf, etc.hosts generated if needed, network disabled non-sudo users (0.0.17) - resolv.conf needs to bind by default (0.0.16) diff --git a/scompose/version.py b/scompose/version.py index e5dfa28..3f4a744 100644 --- a/scompose/version.py +++ b/scompose/version.py @@ -8,7 +8,7 @@ """ -__version__ = "0.0.18" +__version__ = "0.0.19" AUTHOR = "Vanessa Sochat" AUTHOR_EMAIL = "vsochat@stanford.edu" NAME = "singularity-compose" From 1ad17cb90b5434f4c45ed1932b2cce5054d96ec1 Mon Sep 17 00:00:00 2001 From: pierlauro Date: Wed, 18 Mar 2020 14:18:12 +0100 Subject: [PATCH 3/7] Reformatting --- scompose/project/instance.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scompose/project/instance.py b/scompose/project/instance.py index 5bbfbf9..f7816b5 100644 --- a/scompose/project/instance.py +++ b/scompose/project/instance.py @@ -510,9 +510,18 @@ def create(self, ip_address=None, sudo=False, writable_tmpfs=False): options += ["--writable-tmpfs"] # Show the command to the user - commands = "%s %s %s %s" % (" ".join(options), image, self.name, self.command) + commands = "%s %s %s %s" % ( + " ".join(options), + image, + self.name, + self.args, + ) bot.debug("singularity instance start %s" % commands) self.instance = self.client.instance( - name=self.name, sudo=self.sudo, options=options, image=image, args=self.args + name=self.name, + sudo=self.sudo, + options=options, + image=image, + args=self.args, ) From da7366b2d66ec230503860d849bdb28edba5c765 Mon Sep 17 00:00:00 2001 From: pierlauro Date: Wed, 18 Mar 2020 14:26:02 +0100 Subject: [PATCH 4/7] Update documentation --- docs/spec/spec-1.0.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/spec/spec-1.0.md b/docs/spec/spec-1.0.md index 3e894be..43b5cc6 100644 --- a/docs/spec/spec-1.0.md +++ b/docs/spec/spec-1.0.md @@ -48,6 +48,21 @@ Since Singularity does not (currently) have control over custom networking, all instance ports are mapped to the host (localhost) and we don't have any configuration settings to control this (how to handle ports?) +## Startscript arguments + +It is possible to use the `command` option to pass arguments to an instance's +startscript. + +The following example shows how to pass the arguments `arg0 arg1arg2` to the +startscript of instance `app`, + +```yaml + app: + build: + context: ./app + command: "arg0 arg1 arg2" +``` + ## Environment While Singularity compose doesn't currently have support for an environment From c86ddb02a02070d416b4f5cd5601cd701e113f11 Mon Sep 17 00:00:00 2001 From: pierlauro Date: Wed, 18 Mar 2020 14:26:31 +0100 Subject: [PATCH 5/7] Reformatting --- scompose/project/instance.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/scompose/project/instance.py b/scompose/project/instance.py index f7816b5..15eb6fe 100644 --- a/scompose/project/instance.py +++ b/scompose/project/instance.py @@ -510,12 +510,7 @@ def create(self, ip_address=None, sudo=False, writable_tmpfs=False): options += ["--writable-tmpfs"] # Show the command to the user - commands = "%s %s %s %s" % ( - " ".join(options), - image, - self.name, - self.args, - ) + commands = "%s %s %s %s" % (" ".join(options), image, self.name, self.args,) bot.debug("singularity instance start %s" % commands) self.instance = self.client.instance( From 20d9861a54fc5d2ad5c5b2b2284934eeffd11373 Mon Sep 17 00:00:00 2001 From: pierlauro Date: Wed, 18 Mar 2020 14:39:13 +0100 Subject: [PATCH 6/7] Testing command args --- scompose/tests/configs/cmd_args/Singularity | 5 ++ .../configs/cmd_args/singularity-compose.yml | 7 +++ scompose/tests/test_command_args.py | 59 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 scompose/tests/configs/cmd_args/Singularity create mode 100644 scompose/tests/configs/cmd_args/singularity-compose.yml create mode 100644 scompose/tests/test_command_args.py diff --git a/scompose/tests/configs/cmd_args/Singularity b/scompose/tests/configs/cmd_args/Singularity new file mode 100644 index 0000000..6a7038f --- /dev/null +++ b/scompose/tests/configs/cmd_args/Singularity @@ -0,0 +1,5 @@ +Bootstrap: docker +From: busybox + +%startscript +echo "Following arguments: $@" diff --git a/scompose/tests/configs/cmd_args/singularity-compose.yml b/scompose/tests/configs/cmd_args/singularity-compose.yml new file mode 100644 index 0000000..5f730cc --- /dev/null +++ b/scompose/tests/configs/cmd_args/singularity-compose.yml @@ -0,0 +1,7 @@ +version: "1.0" +instances: + echo: + build: + context: . + recipe: Singularity + command: "arg0 arg1 arg2" diff --git a/scompose/tests/test_command_args.py b/scompose/tests/test_command_args.py new file mode 100644 index 0000000..d554795 --- /dev/null +++ b/scompose/tests/test_command_args.py @@ -0,0 +1,59 @@ +#!/usr/bin/python + +# Copyright (C) 2019-2020 Vanessa Sochat. + +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed +# with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from scompose.logger import bot +from scompose.project import Project +from scompose.utils import run_command +from time import sleep +import shutil +import pytest +import os + +here = os.path.dirname(os.path.abspath(__file__)) + + +def test_command_args(tmp_path): + bot.clear() ## Clear previously logged messages + + cmd_args = os.path.join(here, "configs", "cmd_args") + for filename in os.listdir(cmd_args): + source = os.path.join(cmd_args, filename) + dest = os.path.join(tmp_path, filename) + print("Copying %s to %s" % (filename, dest)) + shutil.copyfile(source, dest) + + # Test the simple apache example + os.chdir(tmp_path) + + # Check for required files + assert "singularity-compose.yml" in os.listdir() + + print("Creating project...") + + # Loading project validates config + project = Project() + + print("Testing build") + project.build() + + assert "echo.sif" in os.listdir(tmp_path) + + print("Testing view config") + project.view_config() + + print("Testing up") + project.up() + + print("Waiting for instances to start") + sleep(10) + + print("Bringing down") + project.down() + + log = bot.get_logs() + assert "echo arg0 arg1 arg2" in log From acecae8a9469f00d0a693ae9e6afab5293a53f12 Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 09:51:06 -0600 Subject: [PATCH 7/7] fixing spacing issue in docs and adding test to run in circleci Signed-off-by: vsoch --- .circleci/config.yml | 1 + docs/spec/spec-1.0.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 06bc6ea..1ff1dd0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,6 +37,7 @@ test_scompose: &test_scompose pytest -sv scompose/tests/test_depends_on.py pytest -sv scompose/tests/test_client.py pytest -sv scompose/tests/test_utils.py + pytest -sv scompose/tests/test_command_args.py install_dependencies: &install_dependencies name: Install Python dependencies diff --git a/docs/spec/spec-1.0.md b/docs/spec/spec-1.0.md index 43b5cc6..806427a 100644 --- a/docs/spec/spec-1.0.md +++ b/docs/spec/spec-1.0.md @@ -53,7 +53,7 @@ configuration settings to control this (how to handle ports?) It is possible to use the `command` option to pass arguments to an instance's startscript. -The following example shows how to pass the arguments `arg0 arg1arg2` to the +The following example shows how to pass the arguments `arg0 arg1 arg2` to the startscript of instance `app`, ```yaml