-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
66 lines (63 loc) · 2.3 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(ns monkey.ci.core
"Core namespace for the Monkey CI app. This contains the entrypoint which
processes the configuration. This configuration determines whether the
application runs as a server, execute a single script, which type of runner
is enabled, etc..."
(:gen-class)
(:require [cli-matic.core :as cli]
[clojure.tools.logging :as log]
[config.core :refer [env]]
[monkey.ci
[artifacts]
[cache]
[cli :as mcli]
[config :as config]
[containers]
[git]
[listeners]
[logging]
[metrics]
[runtime :as rt]
[runners]
[sidecar]
[utils :as u]
[workspace]]
[monkey.ci.containers
[oci]]
[monkey.ci.events.core :as ec]
[monkey.ci.reporting.print]
[monkey.ci.runners.oci]
[monkey.ci.storage
[cached]
[file]
[oci]]))
(defn system-invoker
"The event invoker starts a subsystem according to the command requirements,
and posts the `command/invoked` event. This event should be picked up by a
handler in the system. When the command is complete, it should post a
`command/completed` event for the same command. By default it uses the base
system, but you can specify your own for testing purposes."
[{:keys [command app-mode] :as cmd} env]
(fn [args]
(log/debug "Invoking command with arguments:" args)
(let [config (config/app-config env args)]
(rt/with-runtime config app-mode runtime
(log/info "Executing command:" command)
(command runtime)))))
(defn make-cli-config [{:keys [cmd-invoker env] :or {cmd-invoker system-invoker}}]
(letfn [(invoker [cmd]
(cmd-invoker cmd env))]
;; Wrap the run functions in the invoker
(mcli/set-invoker mcli/base-config invoker)))
(defn -main
"Main entry point for the application."
[& args]
(try
(log/info "Starting MonkeyCI version" (config/version))
(cli/run-cmd args (make-cli-config {:env env}))
(catch Throwable ex
(log/error "Failed to run application" ex)
1)
(finally
;; Shutdown the agents otherwise the app will block for a while here
(shutdown-agents))))