Skip to content

Commit

Permalink
Merge pull request #104 from viash-io/develop
Browse files Browse the repository at this point in the history
Viash 0.5.9
  • Loading branch information
rcannood authored Mar 12, 2022
2 parents 8596736 + bea32a6 commit f5d2f22
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 50 deletions.
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
# Viash 0.5.9

## NEW FEATURES

* `viash run`: A long running Viash component can be interrupted by pressing
CTRL-C or by sending it an `INT` or `SIGINT` signal.

* `DockerPlatform`: Automatically add a few labels based on metadata to Dockerfile.

* `DockerPlatform`: Added value `target_image_source` for setting the source of
the target image. This is used for defining labels in the dockerfile.
Example:
```yaml
target_image_source: https://github.com/foo/bar
```
## MINOR CHANGES
* `viash ns list`: Added `--format yaml/json` argument to be able to return the
output as a json as well. Useful for when `jq` is installed but `yq` is not. Example:
```
viash ns list -p docker -f json | jq '.[] | .info.config'
```

* `viash config view`: Same as above.

## DEPRECATION

* `CLI`: Deprecated `-P` flag use `-p` intead.

* `DockerPlatform`: Deprecated `version` value.

# Viash 0.5.8

## NEW FUNCTIONALITY
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "viash"

version := "0.5.8"
version := "0.5.9"

scalaVersion := "2.12.10"

Expand Down
28 changes: 14 additions & 14 deletions src/main/scala/com/dataintuitive/viash/CLIConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ trait ViashCommand {
"In addition, the path to a platform yaml file can also be specified.",
required = false
)
val platformid = opt[String](
short = 'P',
default = None,
descr = "[deprecated] passthrough option for platform.",
required = false,
hidden = true
)
val config = trailArg[String](
descr = "A viash config file (example: config.vsh.yaml). This argument can also be a script with the config as a header.",
default = Some("config.vsh.yaml"),
Expand Down Expand Up @@ -86,13 +79,6 @@ trait ViashNs {
default = None,
required = false
)
val platformid = opt[String](
short = 'P',
descr = "[deprecated] passthrough option for platform.",
default = None,
required = false,
hidden = true
)
val parallel = opt[Boolean](
name = "parallel",
short = 'l',
Expand Down Expand Up @@ -231,6 +217,13 @@ class CLIConf(arguments: Seq[String]) extends ScallopConf(arguments) {
| viash config view config.vsh.yaml
|
|Arguments:""".stripMargin)
val format = choice(
name = "format",
short = 'f',
default = Some("yaml"),
choices = List("yaml", "json"),
descr = "Which output format to use."
)
}
val inject = new Subcommand("inject") with ViashCommand {
banner(
Expand Down Expand Up @@ -322,6 +315,13 @@ class CLIConf(arguments: Seq[String]) extends ScallopConf(arguments) {
| viash ns list [-n nmspc] [-s src] [-p docker]
|
|Arguments:""".stripMargin)
val format = choice(
name = "format",
short = 'f',
default = Some("yaml"),
choices = List("yaml", "json"),
descr = "Which output format to use."
)
}

addSubcommand(build)
Expand Down
13 changes: 7 additions & 6 deletions src/main/scala/com/dataintuitive/viash/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Main {
internalMain(args)
} catch {
case e: Exception =>
System.err.println(e.getMessage())
System.err.println(e)
System.exit(1)
}
}
Expand Down Expand Up @@ -88,16 +88,17 @@ object Main {
append = cli.namespace.test.append()
)
case List(cli.namespace, cli.namespace.list) =>
val configs = readConfigs(cli.namespace.test, modifyFun = false)
val configs = readConfigs(cli.namespace.list, modifyFun = false)
ViashNamespace.list(
configs = configs
configs = configs,
cli.namespace.list.format()
)
case List(cli.config, cli.config.view) =>
val config = Config.readOnly(
configPath = cli.config.view.config(),
configMods = cli.config.view.config_mods()
)
ViashConfig.view(config)
ViashConfig.view(config, cli.config.view.format())
case List(cli.config, cli.config.inject) =>
val config = Config.readOnly(
configPath = cli.config.inject.config(),
Expand All @@ -115,7 +116,7 @@ object Main {
): Config = {
Config.read(
configPath = subcommand.config(),
platform = subcommand.platform.toOption | subcommand.platformid.toOption,
platform = subcommand.platform.toOption,
modifyFun = modifyFun,
configMods = subcommand.config_mods()
)
Expand All @@ -132,7 +133,7 @@ object Main {
val sourceDir = Paths.get(source)

// create regex for filtering platform ids
val platformStr = (subcommand.platform.toOption | subcommand.platformid.toOption).getOrElse(".*")
val platformStr = (subcommand.platform.toOption).getOrElse(".*")

// find *.vsh.* files and parse as config
val scriptFiles = find(sourceDir, (path, attrs) => {
Expand Down
32 changes: 19 additions & 13 deletions src/main/scala/com/dataintuitive/viash/ViashConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,39 @@ import com.dataintuitive.viash.helpers.IO

import java.nio.file.{Files, Paths}
import io.circe.syntax.EncoderOps
import io.circe.yaml.Printer
import io.circe.{Json, Printer => JsonPrinter}
import io.circe.yaml.{Printer => YamlPrinter}

import scala.sys.process.Process
import com.dataintuitive.viash.platforms.DebugPlatform

object ViashConfig {
private val printer = Printer(
private val yamlPrinter = YamlPrinter(
preserveOrder = true,
dropNullKeys = true,
mappingStyle = Printer.FlowStyle.Block,
mappingStyle = YamlPrinter.FlowStyle.Block,
splitLines = true,
stringStyle = Printer.StringStyle.DoubleQuoted
stringStyle = YamlPrinter.StringStyle.DoubleQuoted
)
private val jsonPrinter = JsonPrinter.spaces2.copy(dropNullValues = true)

def view(config: Config) {
val json = config.asJson
val configYamlStr = printer.pretty(json)
println(configYamlStr)
private def printJson(json: Json, format: String): Unit = {
val str = format match {
case "yaml" => yamlPrinter.pretty(json)
case "json" => jsonPrinter.print(json)
}
println(str)
}

def view(config: Config, format: String): Unit = {
printJson(config.asJson, format)
}

def viewMany(configs: List[Config]) {
val json = configs.asJson
val configYamlStr = printer.pretty(json)
println(configYamlStr)
def viewMany(configs: List[Config], format: String): Unit = {
printJson(configs.asJson, format)
}

def inject(config: Config) {
def inject(config: Config): Unit = {
val fun = config.functionality

// check if config has a main script
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/dataintuitive/viash/ViashNamespace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ object ViashNamespace {
}
}

def list(configs: List[Config]) {
ViashConfig.viewMany(configs)
def list(configs: List[Config], format: String = "yaml") {
ViashConfig.viewMany(configs, format)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ case class DockerPlatform(
setup_strategy: DockerSetupStrategy = IfNeedBePullElseCachedBuild,
privileged: Boolean = false,
run_args: OneOrMore[String] = Nil,
target_image_source: Option[String] = None,
oType: String = "docker",

// setup variables
Expand All @@ -54,15 +55,10 @@ case class DockerPlatform(
yum: Option[YumRequirements] = None,
r: Option[RRequirements] = None,
python: Option[PythonRequirements] = None,
docker: Option[DockerRequirements] = None,

// deprecated
version: Option[Version] = None
docker: Option[DockerRequirements] = None
) extends Platform {
override val hasSetup = true

assert(version.isEmpty, "docker platform: attribute 'version' is deprecated")

override val requirements: List[Requirements] = {
val x =
setup :::
Expand Down Expand Up @@ -138,8 +134,26 @@ case class DockerPlatform(
}

private def processDockerSetup(functionality: Functionality) = {
// construct labels from metadata
val auth = functionality.authors match {
case Nil => Nil
case aut: List[Author] => List(s"""authors="${aut.mkString(", ")}"""")
}
/*val descr = functionality.description.map{ des =>
s"""org.opencontainers.image.description="${Bash.escape(des)}""""
}.toList*/

val descr = List(
s"""org.opencontainers.image.description="Companion container for running component ${functionality.namespace.map(_ + " ").getOrElse("")}${functionality.name}""""
)
val imageSource = target_image_source.map(des => s"""org.opencontainers.image.source="${Bash.escape(des)}"""").toList
val labelReq = DockerRequirements(label = auth ::: descr ::: imageSource)

val requirements2 = labelReq :: requirements

// get dependencies
val runCommands = requirements.flatMap(_.dockerCommands)
val runCommands = requirements2.flatMap(_.dockerCommands)


// don't draw defaults from functionality for the from image
val fromImageInfo = Docker.getImageInfo(
Expand Down
12 changes: 9 additions & 3 deletions src/main/scala/com/dataintuitive/viash/wrapper/BashWrapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,27 @@ object BashWrapper {

// check whether the script can be written to a temprorary location or
// whether it needs to be a specific path
val scriptSetup =
val scriptSetup =
s"""
|tempscript=\\$$(mktemp "$$VIASH_TEMP/viash-run-${functionality.name}-XXXXXX")
|function clean_up {
| rm "\\$$tempscript"
|}
|trap clean_up EXIT""".stripMargin
|function interrupt {
| echo -e "\\nCTRL-C Pressed..."
| exit 1
|}
|trap clean_up EXIT
|trap interrupt INT SIGINT""".stripMargin
val scriptPath = "\\$tempscript"

s"""
|set -e$scriptSetup
|cat > "$scriptPath" << 'VIASHMAIN'
|$escapedCode
|VIASHMAIN$cdToResources$resourcesToPath
|${res.meta.command(scriptPath)}
|${res.meta.command(scriptPath)} &
|wait "\\$$!"
|""".stripMargin

// if we want to debug our code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class MainBuildAuxiliaryDockerTag extends FunSuite with BeforeAndAfterAll {
val dockerout = Exec.run(Seq(executableBashTagFile.toString, "---dockerfile"))
// we expect something basic like
// FROM bash:5.0
//
// LABEL ...
// RUN :
// Allow for extra spaces just in case the format changes slightly format-wise but without functional differences
val regex = """^FROM bash:5\.0[\r\n\s]*RUN\s+:\s*$""".r
val regex = """^FROM bash:5\.0[\r\n\s]*.*""".r
assert(regex.findFirstIn(dockerout).isDefined, regex.toString)
}

Expand Down Expand Up @@ -75,10 +75,10 @@ class MainBuildAuxiliaryDockerTag extends FunSuite with BeforeAndAfterAll {
val dockerout = Exec.run(Seq(executableBashTagFile.toString, "---dockerfile"))
// we expect something basic like
// FROM bash:3.2
//
// LABEL ...
// RUN :
// Allow for extra spaces just in case the format changes slightly format-wise but without functional differences
val regex = """^FROM bash:3\.2[\r\n\s]*RUN\s+:\s*$""".r
val regex = """^FROM bash:3\.2[\r\n\s]*.*""".r
assert(regex.findFirstIn(dockerout).isDefined, regex.toString)
}

Expand Down

0 comments on commit f5d2f22

Please sign in to comment.