diff --git a/src/k16/kl/api/executor.clj b/src/k16/kl/api/executor.clj index ca71d22..045c538 100644 --- a/src/k16/kl/api/executor.clj +++ b/src/k16/kl/api/executor.clj @@ -26,9 +26,9 @@ (cond-> base (seq containers) (assoc :services containers)))) -(defn- exec-configuration! [{:keys [group-name module direction]}] +(defn- exec-configuration! [{:keys [module-name module direction]}] (let [compose-data (build-docker-compose module) - compose-file (api.fs/from-submodule-work-dir group-name "docker-compose.yaml") + compose-file (api.fs/from-module-work-dir module-name "docker-compose.yaml") direction (if (:services compose-data) direction :down) @@ -41,7 +41,7 @@ (try (proc/shell (concat ["docker" "compose" - "--project-name" (str "kl-" group-name)] + "--project-name" (str "kl-" module-name)] args)) (catch Exception _)))) diff --git a/src/k16/kl/api/fs.clj b/src/k16/kl/api/fs.clj index 6d2a744..c9e64ca 100644 --- a/src/k16/kl/api/fs.clj +++ b/src/k16/kl/api/fs.clj @@ -24,11 +24,11 @@ (defn get-lock-file ^java.io.File [group-name] (from-modules-dir group-name "module.lock.edn")) -(defn from-submodule-work-dir ^java.io.File [group-name & segments] - (from-modules-dir group-name ".kl" (flatten segments))) +(defn from-module-work-dir ^java.io.File [module-name & segments] + (from-modules-dir module-name ".kl" (flatten segments))) -(defn from-submodule-dir ^java.io.File [group-name module-name & segments] - (from-submodule-work-dir group-name ".modules" (name module-name) (flatten segments))) +(defn from-submodule-dir ^java.io.File [module-name submodule-name & segments] + (from-module-work-dir module-name ".modules" (name submodule-name) (flatten segments))) (defn read-edn [^java.io.File file] (try @@ -39,7 +39,7 @@ (let [contents (with-out-str (pprint/pprint data))] (spit file contents))) -(defn list-configuration-groups [] +(defn list-modules [] (let [dir (from-modules-dir)] (->> (.listFiles dir) (filter (fn [^java.io.File file] diff --git a/src/k16/kl/api/module.clj b/src/k16/kl/api/module.clj index 79b3696..27f3222 100644 --- a/src/k16/kl/api/module.clj +++ b/src/k16/kl/api/module.clj @@ -6,12 +6,12 @@ (set! *warn-on-reflection* true) -(defn- merge-modules [group-name root-module sub-modules] - (let [state (api.state/get-state group-name) +(defn- merge-modules [module-name root-module sub-modules] + (let [state (api.state/get-state module-name) merged (->> sub-modules - (reduce (fn [acc [module-name]] - (let [module-file (api.fs/from-submodule-dir group-name module-name "module.edn") + (reduce (fn [acc [submodule-name]] + (let [module-file (api.fs/from-submodule-dir module-name submodule-name "module.edn") module (api.fs/read-edn module-file)] (metamerge/meta-merge acc module))) {}))] @@ -20,6 +20,6 @@ root-module (select-keys state [:network :containers])))) -(defn get-resolved-module [group-name modules] - (let [root-module (api.fs/read-edn (api.fs/get-root-module-file group-name))] - (dissoc (merge-modules group-name root-module modules) :modules))) +(defn get-resolved-module [module-name modules] + (let [root-module (api.fs/read-edn (api.fs/get-root-module-file module-name))] + (dissoc (merge-modules module-name root-module modules) :modules))) diff --git a/src/k16/kl/api/proxy.clj b/src/k16/kl/api/proxy.clj index 1dd81bd..560cc7c 100644 --- a/src/k16/kl/api/proxy.clj +++ b/src/k16/kl/api/proxy.clj @@ -4,8 +4,8 @@ [k16.kl.api.fs :as api.fs] [meta-merge.core :as metamerge])) -(defn- get-proxies-projection-file [group-name] - (api.fs/from-config-dir "proxy/" (str group-name ".yaml"))) +(defn- get-proxies-projection-file [module-name] + (api.fs/from-config-dir "proxy/" (str module-name ".yaml"))) (defn- route->traefik-rule [{:keys [host path-prefix]}] (cond-> (str "Host(`" host "`)") @@ -43,7 +43,7 @@ (metamerge/meta-merge services routes))) -(defn write-proxy-config! [{:keys [group-name module]}] +(defn write-proxy-config! [{:keys [module-name module]}] (let [routes (build-routes module) - file (get-proxies-projection-file group-name)] + file (get-proxies-projection-file module-name)] (spit file (yaml/generate-string routes)))) diff --git a/src/k16/kl/api/resolver.clj b/src/k16/kl/api/resolver.clj index 232444b..ef24947 100644 --- a/src/k16/kl/api/resolver.clj +++ b/src/k16/kl/api/resolver.clj @@ -34,28 +34,28 @@ (defn- resolve-modules [{:keys [module lock force-resolve?]}] (->> (:modules module) - (map (fn [[module-name module]] + (map (fn [[submodule-name location]] (p/vthread - (let [lock-entry (get lock module-name) + (let [lock-entry (get lock submodule-name) should-resolve? (or (not (:sha lock-entry)) - (and (:sha module) (not= (:sha module) (:sha lock-entry))) - (and (:ref module) (not= (:ref module) (:ref lock-entry))) - (and (:subdir module) (not= (:subdir module) (:subdir lock-entry))) + (and (:sha location) (not= (:sha location) (:sha lock-entry))) + (and (:ref location) (not= (:ref location) (:ref lock-entry))) + (and (:subdir location) (not= (:subdir location) (:subdir lock-entry))) force-resolve?)] (if should-resolve? - [module-name (resolve-module-sha module)] - [module-name lock-entry]))))) + [submodule-name (resolve-module-sha location)] + [submodule-name lock-entry]))))) doall (map (fn [promise] @promise)) (into {}))) -(defn pull! [group-name {:keys [update-lockfile? force?]}] - (let [module (api.fs/read-edn (api.fs/get-root-module-file group-name)) - lock (api.fs/read-edn (api.fs/get-lock-file group-name)) +(defn pull! [module-name {:keys [update-lockfile? force?]}] + (let [module (api.fs/read-edn (api.fs/get-root-module-file module-name)) + lock (api.fs/read-edn (api.fs/get-lock-file module-name)) modules (resolve-modules {:module module :lock lock @@ -65,17 +65,17 @@ downloads (when (or lockfile-updated? force?) (->> modules - (map (fn [[module-name module]] + (map (fn [[submodule-name module]] (p/vthread (resolver.downloader/download-remote-module! - {:group-name group-name - :module-name (name module-name) + {:module-name module-name + :submodule-name (name submodule-name) :module module})))) doall))] (when lockfile-updated? - (api.fs/write-edn (api.fs/get-lock-file group-name) modules)) + (api.fs/write-edn (api.fs/get-lock-file module-name) modules)) (when downloads (doseq [download downloads] diff --git a/src/k16/kl/api/resolver/downloader.clj b/src/k16/kl/api/resolver/downloader.clj index 875c88d..463aa7a 100644 --- a/src/k16/kl/api/resolver/downloader.clj +++ b/src/k16/kl/api/resolver/downloader.clj @@ -31,12 +31,12 @@ (str/replace acc (str "{{" (name key) "}}") value)) contents))) -(defn download-remote-module! [{:keys [group-name module-name module]}] +(defn download-remote-module! [{:keys [module-name submodule-name module]}] (let [{:keys [sha url subdir] :or {subdir ".kl"}} module sha-short (subs sha 0 7) - submodule-dir (-> (api.fs/from-submodule-dir group-name module-name) + submodule-dir (-> (api.fs/from-submodule-dir module-name submodule-name) .toString) vars {:SHA sha @@ -53,9 +53,9 @@ (->> (:include config) (map (fn [file] (p/vthread - (log/info (str "Downloading " file " [" module-name "]")) + (log/info (str "Downloading " file " [" submodule-name "]")) (let [contents (-> (read-repo-file url sha (relative-to subdir file)) (replace-vars vars))] - (spit (api.fs/from-submodule-dir group-name module-name file) contents))))))) + (spit (api.fs/from-submodule-dir module-name submodule-name file) contents))))))) - (api.fs/write-edn (api.fs/from-submodule-dir group-name module-name "module.edn") config)))) + (api.fs/write-edn (api.fs/from-submodule-dir module-name submodule-name "module.edn") config)))) diff --git a/src/k16/kl/api/state.clj b/src/k16/kl/api/state.clj index d1191e5..7273271 100644 --- a/src/k16/kl/api/state.clj +++ b/src/k16/kl/api/state.clj @@ -2,11 +2,11 @@ (:require [k16.kl.api.fs :as api.fs])) -(defn get-state-file [group-name] - (api.fs/from-submodule-work-dir group-name "state.edn")) +(defn get-state-file [module-name] + (api.fs/from-module-work-dir module-name "state.edn")) -(defn get-state [group-name] - (api.fs/read-edn (get-state-file group-name))) +(defn get-state [module-name] + (api.fs/read-edn (get-state-file module-name))) -(defn save-state [group-name state] - (api.fs/write-edn (get-state-file group-name) state)) +(defn save-state [module-name state] + (api.fs/write-edn (get-state-file module-name) state)) diff --git a/src/k16/kl/commands/containers.clj b/src/k16/kl/commands/containers.clj index 219ba29..ba36f1c 100644 --- a/src/k16/kl/commands/containers.clj +++ b/src/k16/kl/commands/containers.clj @@ -17,17 +17,17 @@ {:command "list" :description "Select containers to run" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] :runs (fn [props] - (let [group-name (prompt.config/get-group-name props) + (let [module-name (prompt.config/get-module-name props) - {:keys [modules]} (api.resolver/pull! group-name {}) - module (api.module/get-resolved-module group-name modules) + {:keys [modules]} (api.resolver/pull! module-name {}) + module (api.module/get-resolved-module module-name modules) - state (api.state/get-state group-name) + state (api.state/get-state module-name) containers (->> (:containers module) (map (fn [[container-name container]] @@ -41,17 +41,17 @@ {:command "run" :description "Select containers to run" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] :runs (fn [props] - (let [group-name (prompt.config/get-group-name props) + (let [module-name (prompt.config/get-module-name props) - {:keys [modules]} (api.resolver/pull! group-name {}) - module (api.module/get-resolved-module group-name modules) + {:keys [modules]} (api.resolver/pull! module-name {}) + module (api.module/get-resolved-module module-name modules) - state (api.state/get-state group-name) + state (api.state/get-state module-name) options (->> (:containers module) (map (fn [[container-name]] @@ -71,27 +71,28 @@ [container-name {:enabled enabled}]))) (into {})))] - (api.state/save-state group-name updated-state) + (api.state/save-state module-name updated-state) (let [module (metamerge/meta-merge module updated-state)] - (api.proxy/write-proxy-config! {:group-name group-name + (api.proxy/write-proxy-config! {:module-name module-name :module module}) - (api.executor/start-configuration! {:group-name group-name + (api.executor/start-configuration! {:module-name module-name :module module}))))}) (def ^:private stop-cmd {:command "down" :description "Stop all running containers " - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] :runs (fn [props] - (let [group-name (prompt.config/get-group-name props) - services (api.fs/read-edn (api.fs/get-root-module-file group-name))] - (api.executor/stop-configuration! {:group-name group-name - :services services})))}) + (let [module-name (prompt.config/get-module-name props) + {:keys [modules]} (api.resolver/pull! module-name {}) + module (api.module/get-resolved-module module-name modules)] + (api.executor/stop-configuration! {:module-name module-name + :module module})))}) (def cmd {:command "containers" diff --git a/src/k16/kl/commands/endpoints.clj b/src/k16/kl/commands/endpoints.clj index dfd91f6..7881574 100644 --- a/src/k16/kl/commands/endpoints.clj +++ b/src/k16/kl/commands/endpoints.clj @@ -6,10 +6,10 @@ [k16.kl.prompt.config :as prompt.config])) (defn- list-endpoints [props] - (let [group-name (prompt.config/get-group-name props) + (let [module-name (prompt.config/get-module-name props) - {:keys [modules]} (api.resolver/pull! group-name {}) - module (api.module/get-resolved-module group-name modules) + {:keys [modules]} (api.resolver/pull! module-name {}) + module (api.module/get-resolved-module module-name modules) selected-service-name (keyword (:service props)) @@ -37,7 +37,7 @@ :subcommands [{:command "list" :description "List all endpoints" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string} diff --git a/src/k16/kl/commands/modules.clj b/src/k16/kl/commands/modules.clj index 0e4a3c6..104ac37 100644 --- a/src/k16/kl/commands/modules.clj +++ b/src/k16/kl/commands/modules.clj @@ -8,16 +8,16 @@ (set! *warn-on-reflection* true) (defn- pull! [{:keys [update force] :as props}] - (let [group-name (prompt.config/get-group-name props) - updated? (api.resolver/pull! group-name {:update-lockfile? update - :force? force})] + (let [module-name (prompt.config/get-module-name props) + updated? (api.resolver/pull! module-name {:update-lockfile? update + :force? force})] (if updated? (log/info "Services updated") (log/info "Services are all up to date")))) (defn- set-default-module! [props] - (let [group-name (prompt.config/get-group-name (assoc props :skip-default? true))] - (api.fs/write-edn (api.fs/get-config-file) {:default-module group-name}))) + (let [module-name (prompt.config/get-module-name (assoc props :skip-default? true))] + (api.fs/write-edn (api.fs/get-config-file) {:default-module module-name}))) (def cmd {:command "module" @@ -25,7 +25,7 @@ :subcommands [{:command "set-default" :description "Set the default module" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] :runs set-default-module!} @@ -33,7 +33,7 @@ {:command "pull" :description "Pull down changes to a module" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string} @@ -50,7 +50,7 @@ {:command "update" :description "Resolve the latest sha's of a module. This is the same as `pull --update`" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string} diff --git a/src/k16/kl/commands/routes.clj b/src/k16/kl/commands/routes.clj index 9e4d545..71c1f7b 100644 --- a/src/k16/kl/commands/routes.clj +++ b/src/k16/kl/commands/routes.clj @@ -7,12 +7,12 @@ [k16.kl.prompt.config :as prompt.config])) (defn- list-routes [props] - (let [group-name (prompt.config/get-group-name props) + (let [module-name (prompt.config/get-module-name props) - {:keys [modules]} (api.resolver/pull! group-name {}) - module (api.module/get-resolved-module group-name modules) + {:keys [modules]} (api.resolver/pull! module-name {}) + module (api.module/get-resolved-module module-name modules) - state (api.state/get-state group-name) + state (api.state/get-state module-name) routes (->> (get-in module [:network :routes]) (map (fn [[route-name route]] @@ -29,7 +29,7 @@ :subcommands [{:command "list" :description "List all routes" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] @@ -38,7 +38,7 @@ {:command "configure" :description "Select which routes are enabled or disabled" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] @@ -47,14 +47,14 @@ {:command "set-service" :description "Set the service for a route" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] :runs (fn [_])} {:command "set-endpoint" :description "Set the endpoint for a route" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] diff --git a/src/k16/kl/commands/services.clj b/src/k16/kl/commands/services.clj index de06952..68bf84b 100644 --- a/src/k16/kl/commands/services.clj +++ b/src/k16/kl/commands/services.clj @@ -10,12 +10,12 @@ [pretty.cli.prompt :as prompt])) (defn- set-default-service-endpoint! [props] - (let [group-name (prompt.config/get-group-name props) + (let [module-name (prompt.config/get-module-name props) - {:keys [modules]} (api.resolver/pull! group-name {}) - module (api.module/get-resolved-module group-name modules) + {:keys [modules]} (api.resolver/pull! module-name {}) + module (api.module/get-resolved-module module-name modules) - state (api.state/get-state group-name) + state (api.state/get-state module-name) service-name (-> (prompt/list-select "Select Service" @@ -39,17 +39,17 @@ (assoc-in state [:network :services service-name :default-endpoint] endpoint-name)] - (api.state/save-state group-name updated-state) + (api.state/save-state module-name updated-state) (let [module (metamerge/meta-merge module updated-state)] - (api.proxy/write-proxy-config! {:group-name group-name + (api.proxy/write-proxy-config! {:module-name module-name :module module})))) (defn- list-services [props] - (let [group-name (prompt.config/get-group-name props) + (let [module-name (prompt.config/get-module-name props) - {:keys [modules]} (api.resolver/pull! group-name {}) - module (api.module/get-resolved-module group-name modules) + {:keys [modules]} (api.resolver/pull! module-name {}) + module (api.module/get-resolved-module module-name modules) services (->> (get-in module [:network :services]) (map (fn [[service-name service]] @@ -64,7 +64,7 @@ :subcommands [{:command "list" :description "List all services" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] @@ -73,7 +73,7 @@ {:command "set-endpoint" :description "Set the default endpoint for a service" - :opts [{:option "group" + :opts [{:option "module" :short 0 :type :string}] diff --git a/src/k16/kl/prompt/config.clj b/src/k16/kl/prompt/config.clj index 5369b92..d1ca93f 100644 --- a/src/k16/kl/prompt/config.clj +++ b/src/k16/kl/prompt/config.clj @@ -5,12 +5,12 @@ (set! *warn-on-reflection* true) -(defn get-group-name [{:keys [group skip-default?]}] +(defn get-module-name [{:keys [module skip-default?]}] (let [{:keys [default-module]} (api.fs/read-edn (api.fs/get-config-file))] (cond - group group + module module (and default-module (not skip-default?)) default-module - :else (let [groups (api.fs/list-configuration-groups)] - (prompt/list-select "Select Configuration Group" groups))))) + :else (let [modules (api.fs/list-modules)] + (prompt/list-select "Select Module" modules)))))