Genspio

An EDSL to Generate POSIX Shell Garbage

Seb Mondet
Compose Conference, Mon, 24 Jun 2019

Who is this already?

I'm Seb Mondet:

Computational Biology / Cancer Immuno

  • Run big computational pipelines.
    • Servers with WebUIs, databases.
    • HPC scheduling (Torque, YARN, Google Cloud, AWS, …).
  • Deal with precious human data.
    • HDFS, (broken) disks, S3, Gcloud Buckets, NFSs.
  • Interactive exploration.
    • Direct access for the users (IPython, R, awk | wc, …).

Infrastructure

  • Need to setup local/cloud/datacenter-ish infrastructure for the lab.
  • It's nobody's job.
  • Nothing seems there for the “long term.”

→ Make composable tools that allow people to setup/monitor/clean-up their own infrastructure.
(+ it's more fun, + a better use of software people's time)

It always looks easy at first …

What's wrong with Unix.execve?

👍 … but then,

Who failed?

Ketrew's SSH Call

Ketrew's source screenshot

🤦 After 🤦

Some piece of bio-software works only with the Oracle JDK

DevOps 101: Install The Oracle JDK

Everybody ends-up reading some Stack-overflow answer

Stack Overflow screenshot on installing Oracle JDK in debian

Bash Minus C

It's all strings after all:

Biokepi's docker-file

What Could Go Wrong?

gcloud compute create deprecates the already dysfunctional --wait option

Crazy inline piece of shell

Write Once – Debug Everywhere™

sudo in some Debian version erases new lines …

Fix for su call in Secotrec

Nix: Purely Inlined Bash Scripts ☺

Nixos Inline Shell Script

Typed/Functional Step Back

  1. Start writing simple combinators.
  2. Add more typing info.
  3. Hit portability / representation problems.
  4. Go full-blown EDSL that compiles to pure POSIX shell.

Genspio 0.0.2

  • Simple, typed EDSL.
  • Based-on a “classic” GADT + constructs built on top.
  • Two Compilers to POSIX shell:
    • “Main:” Either one-liners, or multi-line scripts.
    • “Slow-flow” one: Output less complex but slower scripts; more portable to buggy shells (MacOSX's bash).
  • Couple of Optimization Passes:
    • Classic Object-based Extensible AST Visitor.
    • Some constant propagation & involution elimination.

API

API Screenshot

Example 0: Basic Exec

Example 0: Basic Exec

Example 1: Pipes

Example 1: Pipes

Example 2: Feeding NULs

Example 2: Feeding NULs

Example 3: Compilation Error On Wrong String

Example 3: Compilation Error On Wrong String

Example 4: Loops, Conditionals, Tmp-files

Example 4: Loops, Conditionals, Tmp-files

Example 5: EDSL-Lists

Example 5: EDSL-Lists

Under The Hood ☠

  • Crazy internal representations: handle arbitrary strings.
  • Proper fail escaping (trap + kill).
  • POSIX-only use of sed, od, …
  • Two “string” types: Byte-arrays and C-Strings.
  • Focus on readability & testability, not much performance.

Two String Types

In the beginning there was C.

Insert Vuln Here
  • In “Future Work” for Genspio 0.0.0.
  • Two types accessible but only one (with conversions) in module EDSL.
  • Optmization pass available.

Compiler Sample 0: Octal String Representation

Compiler Sample 0: Octal String Representation

Compiler Sample 1: Exec-based Redirections

Compiler Sample 1: Exec-based Redirections

Compiler Sample 2: String-to-Int Proper Failures

Compiler Sample 2: String-to-Int Proper Failures

Compiler Sample 3: Arbitrary Getenv

Compiler Sample 3: Arbitrary Getenv

Testing on Ubuntu & OSX (I)

Travis CI Screenshot

Testing & Docs With Gitlab-CI (II)

CI Pipeline

(Some) Test Results → Docs

GIF of the docs' test results

Testing With Custom Hardware/VMs

Tests Generate a directory: Makefile + set of scripts

⇒ easy to tar c | ssh

OpenWRT Setup

One of The Tests is a Testing Tool ♲

Screenshot of vm_tester code

Other “bigger” tests/demos/examples.

Cosc --helpMulti-git github description

Multi-git metastatus

git mst page 1  git mst page 2

Doc in the CI

Documentation website built by GitlabCI

  • (Re-)builds for a given number of TREE-ISH.
  • Re-run the tests.
  • Builds the “Genspio Web Demo” for corresponding TREE-ISH.

Webdemo-GIF 0: The 3 tabs

The 3 tabs

Webdemo-GIF 1: Type and Syntax Errors

Type and Syntax Errors

Future

  • More library functions
    • SSH client integration.
    • Types over POSIX tools: Awk, Sed, …)
  • Tests on MS-Windows.
  • Webdemo:
    • Parse & display better error messages.
    • ReasonML “switch.”
    • Examples menu.

Thanks 🙏 — We welcome any contributions ☺