mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 04:49:03 -05:00
🎉 Add prepl support
And rename the current repl to urepl (user-repl).
This commit is contained in:
parent
3dd65db651
commit
8a5afefc1c
4 changed files with 63 additions and 28 deletions
|
@ -10,6 +10,11 @@ export PENPOT_FLAGS="\
|
||||||
enable-demo-users \
|
enable-demo-users \
|
||||||
disable-secure-session-cookies \
|
disable-secure-session-cookies \
|
||||||
enable-smtp \
|
enable-smtp \
|
||||||
|
enable-prepl-server \
|
||||||
|
enable-urepl-server \
|
||||||
|
enable-rpc-climit \
|
||||||
|
enable-rpc-rlimit \
|
||||||
|
enable-soft-rpc-rlimit \
|
||||||
enable-webhooks \
|
enable-webhooks \
|
||||||
enable-access-tokens";
|
enable-access-tokens";
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,6 @@
|
||||||
:tenant "default"
|
:tenant "default"
|
||||||
|
|
||||||
:redis-uri "redis://redis/0"
|
:redis-uri "redis://redis/0"
|
||||||
:srepl-host "127.0.0.1"
|
|
||||||
:srepl-port 6062
|
|
||||||
|
|
||||||
:assets-storage-backend :assets-fs
|
:assets-storage-backend :assets-fs
|
||||||
:storage-assets-fs-directory "assets"
|
:storage-assets-fs-directory "assets"
|
||||||
|
@ -197,8 +195,10 @@
|
||||||
(s/def ::smtp-ssl ::us/boolean)
|
(s/def ::smtp-ssl ::us/boolean)
|
||||||
(s/def ::smtp-tls ::us/boolean)
|
(s/def ::smtp-tls ::us/boolean)
|
||||||
(s/def ::smtp-username (s/nilable ::us/string))
|
(s/def ::smtp-username (s/nilable ::us/string))
|
||||||
(s/def ::srepl-host ::us/string)
|
(s/def ::urepl-host ::us/string)
|
||||||
(s/def ::srepl-port ::us/integer)
|
(s/def ::urepl-port ::us/integer)
|
||||||
|
(s/def ::prepl-host ::us/string)
|
||||||
|
(s/def ::prepl-port ::us/integer)
|
||||||
(s/def ::assets-storage-backend ::us/keyword)
|
(s/def ::assets-storage-backend ::us/keyword)
|
||||||
(s/def ::storage-assets-fs-directory ::us/string)
|
(s/def ::storage-assets-fs-directory ::us/string)
|
||||||
(s/def ::storage-assets-s3-bucket ::us/string)
|
(s/def ::storage-assets-s3-bucket ::us/string)
|
||||||
|
@ -310,8 +310,10 @@
|
||||||
::smtp-tls
|
::smtp-tls
|
||||||
::smtp-username
|
::smtp-username
|
||||||
|
|
||||||
::srepl-host
|
::urepl-host
|
||||||
::srepl-port
|
::urepl-port
|
||||||
|
::prepl-host
|
||||||
|
::prepl-port
|
||||||
|
|
||||||
::assets-storage-backend
|
::assets-storage-backend
|
||||||
::storage-assets-fs-directory
|
::storage-assets-fs-directory
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
[app.redis :as-alias rds]
|
[app.redis :as-alias rds]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.doc :as-alias rpc.doc]
|
[app.rpc.doc :as-alias rpc.doc]
|
||||||
|
[app.srepl :as-alias srepl]
|
||||||
[app.storage :as-alias sto]
|
[app.storage :as-alias sto]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[app.worker :as-alias wrk]
|
[app.worker :as-alias wrk]
|
||||||
|
@ -414,9 +415,13 @@
|
||||||
::http.client/client (ig/ref ::http.client/client)
|
::http.client/client (ig/ref ::http.client/client)
|
||||||
::props (ig/ref :app.setup/props)}
|
::props (ig/ref :app.setup/props)}
|
||||||
|
|
||||||
:app.srepl/server
|
[::srepl/urepl ::srepl/server]
|
||||||
{:port (cf/get :srepl-port)
|
{:port (cf/get :urepl-port 6062)
|
||||||
:host (cf/get :srepl-host)}
|
:host (cf/get :urepl-host "localhost")}
|
||||||
|
|
||||||
|
[::srepl/prepl ::srepl/server]
|
||||||
|
{:port (cf/get :prepl-port 6063)
|
||||||
|
:host (cf/get :prepl-host "localhost")}
|
||||||
|
|
||||||
:app.setup/builtin-templates
|
:app.setup/builtin-templates
|
||||||
{::http.client/client (ig/ref ::http.client/client)}
|
{::http.client/client (ig/ref ::http.client/client)}
|
||||||
|
|
|
@ -9,7 +9,10 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
|
[app.config :as cf]
|
||||||
[app.srepl.main]
|
[app.srepl.main]
|
||||||
|
[app.util.json :as json]
|
||||||
|
[app.util.locks :as locks]
|
||||||
[clojure.core.server :as ccs]
|
[clojure.core.server :as ccs]
|
||||||
[clojure.main :as cm]
|
[clojure.main :as cm]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
@ -20,39 +23,59 @@
|
||||||
(ccs/repl-init)
|
(ccs/repl-init)
|
||||||
(in-ns 'app.srepl.main))
|
(in-ns 'app.srepl.main))
|
||||||
|
|
||||||
(defn repl
|
(defn user-repl
|
||||||
[]
|
[]
|
||||||
(cm/repl
|
(cm/repl
|
||||||
:init repl-init
|
:init repl-init
|
||||||
:read ccs/repl-read))
|
:read ccs/repl-read))
|
||||||
|
|
||||||
|
(defn json-prepl
|
||||||
|
[]
|
||||||
|
(let [out *out*
|
||||||
|
lock (locks/create)]
|
||||||
|
(ccs/prepl *in*
|
||||||
|
(fn [m]
|
||||||
|
(binding [*out* out, *flush-on-newline* true, *print-readably* true]
|
||||||
|
(locks/locking lock
|
||||||
|
(println (json/encode-str m))))))))
|
||||||
|
|
||||||
;; --- State initialization
|
;; --- State initialization
|
||||||
|
|
||||||
(s/def ::name ::us/not-empty-string)
|
(s/def ::port ::us/integer)
|
||||||
(s/def ::port int?)
|
|
||||||
(s/def ::host ::us/not-empty-string)
|
(s/def ::host ::us/not-empty-string)
|
||||||
|
(s/def ::flag #{:urepl-server :prepl-server})
|
||||||
|
(s/def ::type #{::prepl ::urepl})
|
||||||
|
(s/def ::key (s/tuple ::type ::us/keyword))
|
||||||
|
|
||||||
(defmethod ig/pre-init-spec ::server
|
(defmethod ig/pre-init-spec ::server
|
||||||
[_]
|
[_]
|
||||||
(s/keys :opt-un [::port ::host ::name]))
|
(s/keys :req [::flag]
|
||||||
|
:req-un [::port ::host]))
|
||||||
|
|
||||||
(defmethod ig/prep-key ::server
|
(defmethod ig/prep-key ::server
|
||||||
[_ cfg]
|
[[type _] cfg]
|
||||||
(merge {:name "main"} cfg))
|
(assoc cfg ::flag (keyword (str (name type) "-server"))))
|
||||||
|
|
||||||
(defmethod ig/init-key ::server
|
(defmethod ig/init-key ::server
|
||||||
[_ {:keys [port host name] :as cfg}]
|
[[type _] {:keys [::flag port host] :as cfg}]
|
||||||
(when (and port host name)
|
(when (contains? cf/flags flag)
|
||||||
(l/info :msg "initializing server repl" :port port :host host :name name)
|
(let [accept (case type
|
||||||
(ccs/start-server {:address host
|
::prepl 'app.srepl/json-prepl
|
||||||
:port port
|
::urepl 'app.srepl/user-repl)
|
||||||
:name name
|
params {:address host
|
||||||
:accept 'app.srepl/repl})
|
:port port
|
||||||
cfg))
|
:name (name type)
|
||||||
|
:accept accept}]
|
||||||
|
|
||||||
|
(l/info :msg "initializing repl server"
|
||||||
|
:name (name type)
|
||||||
|
:port port
|
||||||
|
:host host)
|
||||||
|
|
||||||
|
(ccs/start-server params)
|
||||||
|
|
||||||
|
params)))
|
||||||
|
|
||||||
(defmethod ig/halt-key! ::server
|
(defmethod ig/halt-key! ::server
|
||||||
[_ cfg]
|
[_ params]
|
||||||
(when cfg
|
(some-> params :name ccs/stop-server))
|
||||||
(ccs/stop-server (:name cfg))))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue