mirror of
https://github.com/swarmpit/swarmpit.git
synced 2025-09-05 21:34:41 +08:00
cleanup, flow fixes
This commit is contained in:
parent
32831acb07
commit
0f52a43876
13 changed files with 76 additions and 33 deletions
|
@ -8,6 +8,7 @@
|
||||||
[swarmpit.registry.client :as rc]
|
[swarmpit.registry.client :as rc]
|
||||||
[swarmpit.registry.mapper.inbound :as rci]
|
[swarmpit.registry.mapper.inbound :as rci]
|
||||||
[swarmpit.couchdb.client :as cc]
|
[swarmpit.couchdb.client :as cc]
|
||||||
|
[swarmpit.couchdb.mapper.inbound :as cmi]
|
||||||
[swarmpit.couchdb.mapper.outbound :as cmo]))
|
[swarmpit.couchdb.mapper.outbound :as cmo]))
|
||||||
|
|
||||||
(defn create-database
|
(defn create-database
|
||||||
|
@ -55,8 +56,9 @@
|
||||||
|
|
||||||
(defn update-service
|
(defn update-service
|
||||||
[service-id service]
|
[service-id service]
|
||||||
(->> (dmo/->service service)
|
(let [service-version (:version service)]
|
||||||
(dc/update-service service-id)))
|
(->> (dmo/->service service)
|
||||||
|
(dc/update-service service-id service-version))))
|
||||||
|
|
||||||
;;; Network API
|
;;; Network API
|
||||||
|
|
||||||
|
@ -109,7 +111,8 @@
|
||||||
|
|
||||||
(defn registries
|
(defn registries
|
||||||
[]
|
[]
|
||||||
(cc/registries))
|
(->> (cc/registries)
|
||||||
|
(cmi/->registries)))
|
||||||
|
|
||||||
(defn registries-sum
|
(defn registries-sum
|
||||||
[]
|
[]
|
||||||
|
|
7
src/clj/swarmpit/couchdb/mapper/inbound.clj
Normal file
7
src/clj/swarmpit/couchdb/mapper/inbound.clj
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
(ns swarmpit.couchdb.mapper.inbound)
|
||||||
|
|
||||||
|
(defn ->registries
|
||||||
|
[registries]
|
||||||
|
(->> registries
|
||||||
|
(map #(assoc % :id (hash (:name %))))
|
||||||
|
(into [])))
|
|
@ -125,7 +125,8 @@
|
||||||
image (get-in service [:Spec :TaskTemplate :ContainerSpec :Image])
|
image (get-in service [:Spec :TaskTemplate :ContainerSpec :Image])
|
||||||
image-info (str/split image #"@")
|
image-info (str/split image #"@")
|
||||||
image-name (first image-info)
|
image-name (first image-info)
|
||||||
image-digest (second image-info)]
|
image-digest (second image-info)
|
||||||
|
image-segments (str/split image-name #":")]
|
||||||
(array-map
|
(array-map
|
||||||
:id service-id
|
:id service-id
|
||||||
:version (get-in service [:Version :Index])
|
:version (get-in service [:Version :Index])
|
||||||
|
@ -133,6 +134,8 @@
|
||||||
:updatedAt (date (get service :UpdatedAt))
|
:updatedAt (date (get service :UpdatedAt))
|
||||||
:image image-name
|
:image image-name
|
||||||
:imageDigest image-digest
|
:imageDigest image-digest
|
||||||
|
:imageName (first image-segments)
|
||||||
|
:imageTag (second image-segments)
|
||||||
:serviceName service-name
|
:serviceName service-name
|
||||||
:mode service-mode
|
:mode service-mode
|
||||||
:replicas replicas
|
:replicas replicas
|
||||||
|
|
|
@ -38,12 +38,16 @@
|
||||||
{:DriverConfig {}}}))
|
{:DriverConfig {}}}))
|
||||||
(into [])))
|
(into [])))
|
||||||
|
|
||||||
|
(defn ->service-image
|
||||||
|
[service]
|
||||||
|
(str (:imageName service) ":" (:imageTag service)))
|
||||||
|
|
||||||
(defn ->service
|
(defn ->service
|
||||||
[service]
|
[service]
|
||||||
{:Name (:serviceName service)
|
{:Name (:serviceName service)
|
||||||
:TaskTemplate
|
:TaskTemplate
|
||||||
{:ContainerSpec
|
{:ContainerSpec
|
||||||
{:Image (:image service)
|
{:Image (->service-image service)
|
||||||
:Mounts (->service-volumes service)
|
:Mounts (->service-volumes service)
|
||||||
:Env (->service-variables service)}}
|
:Env (->service-variables service)}}
|
||||||
:Mode (->service-mode service)
|
:Mode (->service-mode service)
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
"v1/registries/" {:get {[:registryName "/repo"] {"" handler/v1-repositories
|
"v1/registries/" {:get {[:registryName "/repo"] {"" handler/v1-repositories
|
||||||
"/tags" handler/v1-repository-tags}}}
|
"/tags" handler/v1-repository-tags}}}
|
||||||
"v2/registries/" {:get {[:registryName "/repo"] {"" handler/v2-repositories
|
"v2/registries/" {:get {[:registryName "/repo"] {"" handler/v2-repositories
|
||||||
"/tags" handler/v2-repository-tags}}}}
|
"/tags" handler/v2-repository-tags}}}
|
||||||
"/admin/" {"users" {:get handler/users}
|
"admin/" {:get {"users" {"" handler/users}
|
||||||
"registries" {:get handler/registries
|
"registries" {"" handler/registries}}
|
||||||
:post handler/registry-create}}])
|
:post {"registries" {"" handler/registry-create}}}}])
|
||||||
|
|
||||||
(def unsecure-api #{{:request-method :post
|
(def unsecure-api #{{:request-method :post
|
||||||
:uri "/login"}})
|
:uri "/login"}})
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
[:div.page
|
[:div.page
|
||||||
[:span
|
[:span
|
||||||
[:h1 "401"]
|
[:h1 "401"]
|
||||||
[:p "You are not authotized for selected action"]]]])
|
[:p "You are not authotized for selected action"]
|
||||||
|
[:p "Go to login " [:a {:href "/#/login"} "page"]]]]])
|
||||||
|
|
||||||
(defn mount!
|
(defn mount!
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
(defn- form-previous-button [index]
|
(defn- form-previous-button [index]
|
||||||
(comp/raised-button
|
(comp/raised-button
|
||||||
{:label "Previous"
|
{:label "Previous"
|
||||||
|
:key "fpb"
|
||||||
:style form-previous-button-style
|
:style form-previous-button-style
|
||||||
:disabled (= 0 index)
|
:disabled (= 0 index)
|
||||||
:onTouchTap (fn [] (step-previous index))}))
|
:onTouchTap (fn [] (step-previous index))}))
|
||||||
|
@ -64,6 +65,7 @@
|
||||||
(defn- form-next-button [index]
|
(defn- form-next-button [index]
|
||||||
(comp/raised-button
|
(comp/raised-button
|
||||||
{:label "Next"
|
{:label "Next"
|
||||||
|
:key "fnb"
|
||||||
:style form-next-button-style
|
:style form-next-button-style
|
||||||
:disabled (= (- (count steps) 1) index)
|
:disabled (= (- (count steps) 1) index)
|
||||||
:onTouchTap (fn [] (step-next index))}))
|
:onTouchTap (fn [] (step-next index))}))
|
||||||
|
@ -80,7 +82,7 @@
|
||||||
:onClick (fn [] (reset! step-index index))}
|
:onClick (fn [] (reset! step-index index))}
|
||||||
item)
|
item)
|
||||||
(comp/step-content
|
(comp/step-content
|
||||||
{}
|
{:key "step-context"}
|
||||||
(form-item index)
|
(form-item index)
|
||||||
(form-previous-button index)
|
(form-previous-button index)
|
||||||
(form-next-button index))))
|
(form-next-button index))))
|
||||||
|
@ -94,7 +96,8 @@
|
||||||
variables (state/get-value variables/cursor)
|
variables (state/get-value variables/cursor)
|
||||||
deployment (state/get-value deployment/cursor)]
|
deployment (state/get-value deployment/cursor)]
|
||||||
(ajax/POST "/services"
|
(ajax/POST "/services"
|
||||||
{:headers {"Authorization" (storage/get "token")}
|
{:format :json
|
||||||
|
:headers {"Authorization" (storage/get "token")}
|
||||||
:params (-> settings
|
:params (-> settings
|
||||||
(assoc :ports ports)
|
(assoc :ports ports)
|
||||||
(assoc :volumes volumes)
|
(assoc :volumes volumes)
|
||||||
|
@ -137,8 +140,8 @@
|
||||||
(defn- init-state
|
(defn- init-state
|
||||||
[registry registry-version repository]
|
[registry registry-version repository]
|
||||||
(settings/image-tags-handler registry registry-version repository)
|
(settings/image-tags-handler registry registry-version repository)
|
||||||
(state/set-value {:image repository
|
(state/set-value {:imageName repository
|
||||||
:imageTag nil
|
:imageTag ""
|
||||||
:tags []
|
:tags []
|
||||||
:serviceName ""
|
:serviceName ""
|
||||||
:mode "replicated"
|
:mode "replicated"
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
(dispatch! (str "/#/services/" service-id))
|
(dispatch! (str "/#/services/" service-id))
|
||||||
(message/mount! message)))
|
(message/mount! message)))
|
||||||
:error-handler (fn [{:keys [status response]}]
|
:error-handler (fn [{:keys [status response]}]
|
||||||
(let [error (get response "error")
|
(let [error (get-in response ["error" "message"])
|
||||||
message (str "Service update failed. Status: " status " Reason: " error)]
|
message (str "Service update failed. Status: " status " Reason: " error)]
|
||||||
(progress/unmount!)
|
(progress/unmount!)
|
||||||
(message/mount! message)))})))
|
(message/mount! message)))})))
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
|
|
||||||
(defn- init-state
|
(defn- init-state
|
||||||
[item]
|
[item]
|
||||||
(state/set-value (select-keys item [:image :version :serviceName :mode :replicas]) settings/cursor)
|
(state/set-value (select-keys item [:imageName :imageTag :version :serviceName :mode :replicas]) settings/cursor)
|
||||||
(state/set-value (:ports item) ports/cursor)
|
(state/set-value (:ports item) ports/cursor)
|
||||||
(state/set-value (:volumes item) volumes/cursor)
|
(state/set-value (:volumes item) volumes/cursor)
|
||||||
(state/set-value (:variables item) variables/cursor)
|
(state/set-value (:variables item) variables/cursor)
|
||||||
|
|
|
@ -32,13 +32,23 @@
|
||||||
:inputStyle form-image-style
|
:inputStyle form-image-style
|
||||||
:value value})))
|
:value value})))
|
||||||
|
|
||||||
(defn- form-image-tags [tags]
|
(defn- form-image-tag-ac [tags]
|
||||||
(comp/form-comp
|
(comp/form-comp
|
||||||
"IMAGE TAG"
|
"IMAGE TAG"
|
||||||
(comp/autocomplete {:id "imageTag"
|
(comp/autocomplete {:id "imageTag"
|
||||||
:onUpdateInput (fn [v] (state/update-value :imageTag v cursor))
|
:onUpdateInput (fn [v] (state/update-value :imageTag v cursor))
|
||||||
:dataSource tags})))
|
:dataSource tags})))
|
||||||
|
|
||||||
|
(defn- form-image-tag [value]
|
||||||
|
"Temporary solution. Will be fixed with persistence. There is no way to get tags without context during update"
|
||||||
|
(comp/form-comp
|
||||||
|
"IMAGE TAG"
|
||||||
|
(comp/text-field
|
||||||
|
{:id "imageTag"
|
||||||
|
:value value
|
||||||
|
:onChange (fn [_ v]
|
||||||
|
(state/update-value :imageTag v cursor))})))
|
||||||
|
|
||||||
(defn- form-name [value update-form?]
|
(defn- form-name [value update-form?]
|
||||||
(comp/form-comp
|
(comp/form-comp
|
||||||
"SERVICE NAME"
|
"SERVICE NAME"
|
||||||
|
@ -92,14 +102,17 @@
|
||||||
(state/update-value :tags response cursor))}))
|
(state/update-value :tags response cursor))}))
|
||||||
|
|
||||||
(rum/defc form < rum/reactive [update-form?]
|
(rum/defc form < rum/reactive [update-form?]
|
||||||
(let [{:keys [image
|
(let [{:keys [imageName
|
||||||
|
imageTag
|
||||||
serviceName
|
serviceName
|
||||||
mode
|
mode
|
||||||
replicas
|
replicas
|
||||||
tags]} (state/react cursor)]
|
tags]} (state/react cursor)]
|
||||||
[:div.form-edit
|
[:div.form-edit
|
||||||
(form-image image)
|
(form-image imageName)
|
||||||
(form-image-tags tags)
|
(if update-form?
|
||||||
|
(form-image-tag imageTag)
|
||||||
|
(form-image-tag-ac tags))
|
||||||
(form-name serviceName update-form?)
|
(form-name serviceName update-form?)
|
||||||
(form-mode mode update-form?)
|
(form-mode mode update-form?)
|
||||||
(if (= "replicated" mode)
|
(if (= "replicated" mode)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(:require [material.component :as comp]
|
(:require [material.component :as comp]
|
||||||
[material.icon :as icon]
|
[material.icon :as icon]
|
||||||
[swarmpit.url :refer [dispatch!]]
|
[swarmpit.url :refer [dispatch!]]
|
||||||
|
[swarmpit.storage :as storage]
|
||||||
[swarmpit.component.service.form-ports :as ports]
|
[swarmpit.component.service.form-ports :as ports]
|
||||||
[swarmpit.component.service.form-volumes :as volumes]
|
[swarmpit.component.service.form-volumes :as volumes]
|
||||||
[swarmpit.component.service.form-variables :as variables]
|
[swarmpit.component.service.form-variables :as variables]
|
||||||
|
@ -15,7 +16,8 @@
|
||||||
(defn- delete-service-handler
|
(defn- delete-service-handler
|
||||||
[service-id]
|
[service-id]
|
||||||
(ajax/DELETE (str "/services/" service-id)
|
(ajax/DELETE (str "/services/" service-id)
|
||||||
{:handler (fn [_]
|
{:headers {"Authorization" (storage/get "token")}
|
||||||
|
:handler (fn [_]
|
||||||
(let [message (str "Service " service-id " has been removed.")]
|
(let [message (str "Service " service-id " has been removed.")]
|
||||||
(dispatch! "/#/services")
|
(dispatch! "/#/services")
|
||||||
(message/mount! message)))
|
(message/mount! message)))
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
(case value
|
(case value
|
||||||
"preparing" (comp/label-yellow value)
|
"preparing" (comp/label-yellow value)
|
||||||
"starting" (comp/label-yellow value)
|
"starting" (comp/label-yellow value)
|
||||||
|
"pending" (comp/label-yellow value)
|
||||||
|
|
||||||
"new" (comp/label-blue value)
|
"new" (comp/label-blue value)
|
||||||
"ready" (comp/label-blue value)
|
"ready" (comp/label-blue value)
|
||||||
"assigned" (comp/label-blue value)
|
"assigned" (comp/label-blue value)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
[cemerick.url :refer [query->map]]
|
[cemerick.url :refer [query->map]]
|
||||||
[swarmpit.storage :as storage]
|
[swarmpit.storage :as storage]
|
||||||
[swarmpit.component.page-login :as page-login]
|
[swarmpit.component.page-login :as page-login]
|
||||||
|
[swarmpit.component.page-401 :as page-401]
|
||||||
[swarmpit.component.page-404 :as page-404]
|
[swarmpit.component.page-404 :as page-404]
|
||||||
[swarmpit.component.page-error :as page-error]
|
[swarmpit.component.page-error :as page-error]
|
||||||
[swarmpit.component.service.create :as screate]
|
[swarmpit.component.service.create :as screate]
|
||||||
|
@ -33,18 +34,14 @@
|
||||||
(-> resp api-resp-fx)))
|
(-> resp api-resp-fx)))
|
||||||
:error-handler (fn [{:keys [status]}]
|
:error-handler (fn [{:keys [status]}]
|
||||||
(if (= status 401)
|
(if (= status 401)
|
||||||
(dispatch! "/#/login")
|
(page-401/mount!)
|
||||||
(dispatch! "/#/error")))}))
|
(page-error/mount!)))}))
|
||||||
|
|
||||||
(defmulti dispatch (fn [location] (:handler location)))
|
(defmulti dispatch (fn [location] (:handler location)))
|
||||||
|
|
||||||
(defmethod dispatch :index
|
(defmethod dispatch :index
|
||||||
[_]
|
[_]
|
||||||
(print "index"))
|
(print "TO-DO"))
|
||||||
|
|
||||||
(defmethod dispatch :error
|
|
||||||
[_]
|
|
||||||
(page-error/mount!))
|
|
||||||
|
|
||||||
(defmethod dispatch nil
|
(defmethod dispatch nil
|
||||||
[_]
|
[_]
|
||||||
|
@ -141,7 +138,7 @@
|
||||||
|
|
||||||
(defmethod dispatch :user-list
|
(defmethod dispatch :user-list
|
||||||
[_]
|
[_]
|
||||||
(fetch "/users"
|
(fetch "/admin/users"
|
||||||
(fn [response]
|
(fn [response]
|
||||||
(tlist/mount! response))))
|
(tlist/mount! response))))
|
||||||
|
|
||||||
|
@ -149,7 +146,7 @@
|
||||||
|
|
||||||
(defmethod dispatch :registry-list
|
(defmethod dispatch :registry-list
|
||||||
[_]
|
[_]
|
||||||
(fetch "/registries"
|
(fetch "/admin/registries"
|
||||||
(fn [response]
|
(fn [response]
|
||||||
(reglist/mount! response))))
|
(reglist/mount! response))))
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
(defonce location (atom nil))
|
(defonce location (atom nil))
|
||||||
|
|
||||||
(def resource
|
(def location-domains
|
||||||
{:index "Home"
|
{:index "Home"
|
||||||
:service-list "Services"
|
:service-list "Services"
|
||||||
:service-create "Services / Wizard"
|
:service-create "Services / Wizard"
|
||||||
|
@ -26,6 +26,9 @@
|
||||||
:repository-v1-list "Services / Wizard"
|
:repository-v1-list "Services / Wizard"
|
||||||
:repository-v2-list "Services / Wizard"})
|
:repository-v2-list "Services / Wizard"})
|
||||||
|
|
||||||
|
(def location-page
|
||||||
|
#{:login nil})
|
||||||
|
|
||||||
(def routes ["" {"/" :index
|
(def routes ["" {"/" :index
|
||||||
"/login" :login
|
"/login" :login
|
||||||
"/error" :error
|
"/error" :error
|
||||||
|
@ -48,6 +51,11 @@
|
||||||
|
|
||||||
;;; Router config
|
;;; Router config
|
||||||
|
|
||||||
|
(defn- is-layout?
|
||||||
|
"Check whether `loc` belong to layout. Not single page!"
|
||||||
|
[loc]
|
||||||
|
(not (contains? location-page loc)))
|
||||||
|
|
||||||
(defn- route
|
(defn- route
|
||||||
"Route to given `loc`"
|
"Route to given `loc`"
|
||||||
[loc]
|
[loc]
|
||||||
|
@ -57,9 +65,9 @@
|
||||||
(defn- route-to-loc
|
(defn- route-to-loc
|
||||||
"Route to given `loc` and update state domain"
|
"Route to given `loc` and update state domain"
|
||||||
[loc]
|
[loc]
|
||||||
(let [domain (get resource (:handler loc))]
|
(let [domain (get location-domains (:handler loc))]
|
||||||
(state/update-value :domain domain [:menu])
|
(state/update-value :domain domain [:menu])
|
||||||
(if (some? domain)
|
(if (is-layout? loc)
|
||||||
(layout/mount!))
|
(layout/mount!))
|
||||||
(route loc)))
|
(route loc)))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue