Browse Source

added support for secret files and spork lib, runner metadata

main
root 5 months ago
parent
commit
76a6432865
  1. 24
      README.md
  2. 11
      archetype.janet
  3. 17
      runner.janet

24
README.md

@ -29,7 +29,7 @@ This tool requires Janet lang, and has been tested using Janet 1.16.1
The build manifest is written in Janet for simplicity.
It works by defining the rules on top level.
You have access to the entirety of the Janet standard library, don't shy away from using it.
You have access to the entirety of the Janet standard library and the spork library, don't shy away from using it.
The build manifest file name should be `archetype.janet`.
@ -38,18 +38,32 @@ The build manifest file name should be `archetype.janet`.
This document is a pretty basic manifest example.
```
(def vars '(REMOTE)) # This marks the REMOTE environment variable as required for execution
(def pkgs '(go tar)) # This will install both packages before starting the build
(def runner 'alpine)
# This marks the REMOTE environment variable as required for execution
(def secrets '(REMOTE))
# This marks the REMOTE_KEY environment variable as the content of a file that will then be located at ~/.ssh/id_25519
# (typically, for ssh-based file transfer)
(def secret-files ~((REMOTE_KEY ,(string (os/getenv "HOME) "/.ssh/id_ed25519"))
(KNOWN_HOSTS ,(string (os/getenv "HOME") "/.ssh/known_hosts"))))
(def pkgs '(go tar openssh)) # This will install both packages before starting the build
(def build # This will run two commands, echo and date
~((:run "echo What day is it?")
(:run "date")))
```
Note that if you use SSH, it is recommended to set your own `known_hosts` file with your server keys.
### Top-level rules
- The `vars` symbol (optional) should contain a tuple of environment variables.
- The `runner` symbol (required) should contain the name of the runner you wish to use (dependent on your configuration).
- The `secrets` symbol (optional) should contain a tuple of environment variables.
Every environment variable inside this tuple will be verified for existence.
Example: `(def secrets '(HOME USER REMOTE_HOME))`.
- The `secret-files` symbol (optional) should contain a tuple of environment variables to filesystem paths.
Every environment variable inside this tuple will be verified for existence.
Example: `(def vars '(HOME USER REMOTE_HOME))`.
Example: `(def secret-files '((REMOTE_KEY "/home/runner/.ssh/id_25519")))`.
- The `pkgs` symbol (optional) should contain a tuple of package names.
Example: `(def pkgs '(go tar))`.
- The `build` symbol (required) should contain a list of action definitions, of the format `(:type args)`.

11
archetype.janet

@ -1,6 +1,11 @@
(def vars '(REMOTE))
(def runner 'alpine)
(def secrets '(REMOTE))
(def secret-files ~((REMOTE_KEY ,(string
(os/getenv "HOME")
"/.ssh/id_ed25519"))))
(def pkgs '(go tar))
(def build
~((:run "echo What day is it?")
(:run "date")))
'((:run "echo What day is it?")
(:run "date")))

17
runner.janet

@ -1,3 +1,5 @@
(require spork)
(def start-time (os/time))
(assert (= :linux (os/which)) "This tool can only run on a Linux-based system")
(def os-release
@ -11,12 +13,23 @@
"debian" "apt update; apt upgrade -y; apt install -y"))
(def rules (require "/archetype"))
(assert (get rules 'runner) "A runner must be defined in the archetype document")
(if-let (vars (get rules 'vars))
(if-let (secrets (get rules 'secrets))
(map (fn [var] (let (name (string var))
(assert (os/getenv name)
(string name ": Undefined environment variable"))))
(get vars :value)))
(get secrets :value)))
(if-let (secret-files (get rules 'secret-files))
(map (fn [var] (let ([name path] var
var (os/getenv (string name)))
(assert var (string name ": Undefined environment variable"))
(assert (os/shell (string "mkdir -p " (path/dirname path)))
"Impossible to create target directory")
(spit path var)
))
(get secret-files :value)))
(if-let (pkgs (get rules 'pkgs))
(assert (= 0 (os/shell (string/join ~(,pkg-install-command

Loading…
Cancel
Save