2016-11-20 20:04:52 +01:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
2020-01-13 23:52:31 +01:00
|
|
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
|
|
;; defined by the Mozilla Public License, v. 2.0.
|
|
|
|
;;
|
2020-12-27 23:37:51 +01:00
|
|
|
;; Copyright (c) 2020-2021 UXBOX Labs SL
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2020-08-18 19:26:37 +02:00
|
|
|
(ns app.main
|
2020-01-23 17:53:26 +01:00
|
|
|
(:require
|
2020-12-04 16:01:33 +01:00
|
|
|
[app.config :as cfg]
|
2020-12-24 14:32:19 +01:00
|
|
|
[app.common.data :as d]
|
|
|
|
[app.util.time :as dt]
|
2021-01-19 16:33:32 +01:00
|
|
|
[clojure.pprint :as pprint]
|
2020-12-04 16:01:33 +01:00
|
|
|
[clojure.tools.logging :as log]
|
2020-12-24 14:32:19 +01:00
|
|
|
[integrant.core :as ig]))
|
2020-01-31 19:12:58 +01:00
|
|
|
|
|
|
|
;; Set value for all new threads bindings.
|
2021-01-19 16:33:32 +01:00
|
|
|
(alter-var-root #'*assert* (constantly (:asserts-enabled cfg/config)))
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
(derive :app.telemetry/server :app.http/server)
|
2020-02-01 01:13:50 +01:00
|
|
|
|
2020-01-23 17:53:26 +01:00
|
|
|
;; --- Entry point
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2020-12-24 14:32:19 +01:00
|
|
|
(defn build-system-config
|
|
|
|
[config]
|
2021-01-04 18:41:05 +01:00
|
|
|
(d/deep-merge
|
2020-12-27 22:47:31 +01:00
|
|
|
{:app.db/pool
|
|
|
|
{:uri (:database-uri config)
|
|
|
|
:username (:database-username config)
|
|
|
|
:password (:database-password config)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)
|
|
|
|
:migrations (ig/ref :app.migrations/all)
|
|
|
|
:name "main"
|
|
|
|
:min-pool-size 0
|
2020-12-30 14:40:54 +01:00
|
|
|
:max-pool-size 20}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
:app.metrics/metrics
|
|
|
|
{}
|
|
|
|
|
|
|
|
:app.migrations/all
|
2021-01-07 17:07:36 +01:00
|
|
|
{:main (ig/ref :app.migrations/migrations)
|
2020-12-27 22:47:31 +01:00
|
|
|
:telemetry (ig/ref :app.telemetry/migrations)}
|
|
|
|
|
|
|
|
:app.migrations/migrations
|
|
|
|
{}
|
|
|
|
|
|
|
|
:app.telemetry/migrations
|
|
|
|
{}
|
|
|
|
|
|
|
|
:app.redis/redis
|
|
|
|
{:uri (:redis-uri config)}
|
|
|
|
|
|
|
|
:app.tokens/tokens
|
|
|
|
{:secret-key (:secret-key config)}
|
|
|
|
|
2020-12-30 14:38:00 +01:00
|
|
|
:app.storage/gc-task
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:storage (ig/ref :app.storage/storage)}
|
|
|
|
|
2021-01-04 18:41:05 +01:00
|
|
|
:app.storage/recheck-task
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:storage (ig/ref :app.storage/storage)}
|
2020-12-30 14:38:00 +01:00
|
|
|
|
2020-12-27 22:47:31 +01:00
|
|
|
:app.http.session/session
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:cookie-name "auth-token"}
|
|
|
|
|
|
|
|
:app.http/server
|
|
|
|
{:port (:http-server-port config)
|
|
|
|
:handler (ig/ref :app.http/router)
|
2021-01-19 14:45:49 +01:00
|
|
|
:metrics (ig/ref :app.metrics/metrics)
|
2020-12-27 22:47:31 +01:00
|
|
|
:ws {"/ws/notifications" (ig/ref :app.notifications/handler)}}
|
|
|
|
|
|
|
|
:app.http/router
|
|
|
|
{:rpc (ig/ref :app.rpc/rpc)
|
|
|
|
:session (ig/ref :app.http.session/session)
|
|
|
|
:tokens (ig/ref :app.tokens/tokens)
|
|
|
|
:public-uri (:public-uri config)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)
|
|
|
|
:google-auth (ig/ref :app.http.auth/google)
|
|
|
|
:gitlab-auth (ig/ref :app.http.auth/gitlab)
|
2021-01-06 11:54:37 +01:00
|
|
|
:github-auth (ig/ref :app.http.auth/github)
|
2020-12-30 14:38:00 +01:00
|
|
|
:ldap-auth (ig/ref :app.http.auth/ldap)
|
2021-01-05 13:49:39 +01:00
|
|
|
:svgparse (ig/ref :app.svgparse/handler)
|
2021-01-24 16:04:23 +01:00
|
|
|
|
|
|
|
:error-reporter-handler (ig/ref :app.error-reporter/handler)
|
|
|
|
|
2020-12-30 14:38:00 +01:00
|
|
|
:storage (ig/ref :app.storage/storage)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2021-01-10 19:14:52 +01:00
|
|
|
:app.svgparse/svgc
|
|
|
|
{:metrics (ig/ref :app.metrics/metrics)}
|
|
|
|
|
2021-01-05 13:49:39 +01:00
|
|
|
;; HTTP Handler for SVG parsing
|
|
|
|
:app.svgparse/handler
|
2021-01-10 19:14:52 +01:00
|
|
|
{:metrics (ig/ref :app.metrics/metrics)
|
|
|
|
:svgc (ig/ref :app.svgparse/svgc)}
|
2021-01-05 13:49:39 +01:00
|
|
|
|
2020-12-27 22:47:31 +01:00
|
|
|
:app.rpc/rpc
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:session (ig/ref :app.http.session/session)
|
|
|
|
:tokens (ig/ref :app.tokens/tokens)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)
|
2021-01-04 18:41:05 +01:00
|
|
|
:storage (ig/ref :app.storage/storage)
|
2021-01-13 11:40:33 +01:00
|
|
|
:redis (ig/ref :app.redis/redis)
|
|
|
|
:svgc (ig/ref :app.svgparse/svgc)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
:app.notifications/handler
|
|
|
|
{:redis (ig/ref :app.redis/redis)
|
|
|
|
:pool (ig/ref :app.db/pool)
|
2021-01-19 13:58:03 +01:00
|
|
|
:session (ig/ref :app.http.session/session)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
:app.http.auth/google
|
|
|
|
{:rpc (ig/ref :app.rpc/rpc)
|
|
|
|
:session (ig/ref :app.http.session/session)
|
|
|
|
:tokens (ig/ref :app.tokens/tokens)
|
|
|
|
:public-uri (:public-uri config)
|
|
|
|
:client-id (:google-client-id config)
|
|
|
|
:client-secret (:google-client-secret config)}
|
|
|
|
|
2021-01-06 11:54:37 +01:00
|
|
|
:app.http.auth/github
|
|
|
|
{:rpc (ig/ref :app.rpc/rpc)
|
|
|
|
:session (ig/ref :app.http.session/session)
|
|
|
|
:tokens (ig/ref :app.tokens/tokens)
|
|
|
|
:public-uri (:public-uri config)
|
|
|
|
:client-id (:github-client-id config)
|
|
|
|
:client-secret (:github-client-secret config)}
|
|
|
|
|
2020-12-27 22:47:31 +01:00
|
|
|
:app.http.auth/gitlab
|
|
|
|
{:rpc (ig/ref :app.rpc/rpc)
|
|
|
|
:session (ig/ref :app.http.session/session)
|
|
|
|
:tokens (ig/ref :app.tokens/tokens)
|
|
|
|
:public-uri (:public-uri config)
|
|
|
|
:base-uri (:gitlab-base-uri config)
|
|
|
|
:client-id (:gitlab-client-id config)
|
|
|
|
:client-secret (:gitlab-client-secret config)}
|
|
|
|
|
|
|
|
:app.http.auth/ldap
|
|
|
|
{:host (:ldap-auth-host config)
|
|
|
|
:port (:ldap-auth-port config)
|
|
|
|
:ssl (:ldap-auth-ssl config)
|
|
|
|
:starttls (:ldap-auth-starttls config)
|
|
|
|
:user-query (:ldap-auth-user-query config)
|
|
|
|
:username-attribute (:ldap-auth-username-attribute config)
|
|
|
|
:email-attribute (:ldap-auth-email-attribute config)
|
|
|
|
:fullname-attribute (:ldap-auth-fullname-attribute config)
|
|
|
|
:avatar-attribute (:ldap-auth-avatar-attribute config)
|
|
|
|
:base-dn (:ldap-auth-base-dn config)
|
|
|
|
:session (ig/ref :app.http.session/session)
|
|
|
|
:rpc (ig/ref :app.rpc/rpc)}
|
|
|
|
|
|
|
|
:app.worker/executor
|
|
|
|
{:name "worker"}
|
|
|
|
|
|
|
|
:app.worker/worker
|
|
|
|
{:executor (ig/ref :app.worker/executor)
|
|
|
|
:pool (ig/ref :app.db/pool)
|
|
|
|
:tasks (ig/ref :app.tasks/all)}
|
|
|
|
|
|
|
|
:app.worker/scheduler
|
|
|
|
{:executor (ig/ref :app.worker/executor)
|
|
|
|
:pool (ig/ref :app.db/pool)
|
2020-12-28 13:03:12 +01:00
|
|
|
:schedule
|
2021-01-04 18:41:05 +01:00
|
|
|
[{:id "file-media-gc"
|
|
|
|
:cron #app/cron "0 0 0 */1 * ? *" ;; daily
|
|
|
|
:fn (ig/ref :app.tasks.file-media-gc/handler)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2020-12-28 13:03:12 +01:00
|
|
|
{:id "file-xlog-gc"
|
2021-01-22 17:53:34 +01:00
|
|
|
:cron #app/cron "0 0 */2 * * ?" ;; every 2 hours
|
2020-12-28 13:03:12 +01:00
|
|
|
:fn (ig/ref :app.tasks.file-xlog-gc/handler)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2020-12-30 14:38:00 +01:00
|
|
|
{:id "storage-gc"
|
|
|
|
:cron #app/cron "0 0 0 */1 * ?" ;; daily
|
|
|
|
:fn (ig/ref :app.storage/gc-task)}
|
|
|
|
|
2021-01-04 18:41:05 +01:00
|
|
|
{:id "storage-recheck"
|
|
|
|
:cron #app/cron "0 0 0 */1 * ?" ;; daily
|
|
|
|
:fn (ig/ref :app.storage/recheck-task)}
|
|
|
|
|
2020-12-28 13:03:12 +01:00
|
|
|
{:id "tasks-gc"
|
|
|
|
:cron #app/cron "0 0 0 */1 * ?" ;; daily
|
|
|
|
:fn (ig/ref :app.tasks.tasks-gc/handler)}
|
|
|
|
|
|
|
|
(when (:telemetry-enabled cfg/config)
|
|
|
|
{:id "telemetry"
|
|
|
|
:cron #app/cron "0 0 */3 * * ?" ;; every 3h
|
2021-01-15 14:29:56 +01:00
|
|
|
:uri (:telemetry-uri cfg/config)
|
|
|
|
:fn (ig/ref :app.tasks.telemetry/handler)})]}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
:app.tasks/all
|
|
|
|
{"sendmail" (ig/ref :app.tasks.sendmail/handler)
|
|
|
|
"delete-object" (ig/ref :app.tasks.delete-object/handler)
|
|
|
|
"delete-profile" (ig/ref :app.tasks.delete-profile/handler)}
|
|
|
|
|
|
|
|
:app.tasks.sendmail/handler
|
2021-01-04 18:41:05 +01:00
|
|
|
{:host (:smtp-host config)
|
|
|
|
:port (:smtp-port config)
|
|
|
|
:ssl (:smtp-ssl config)
|
|
|
|
:tls (:smtp-tls config)
|
|
|
|
:enabled (:smtp-enabled config)
|
|
|
|
:username (:smtp-username config)
|
|
|
|
:password (:smtp-password config)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)
|
2020-12-27 22:47:31 +01:00
|
|
|
:default-reply-to (:smtp-default-reply-to config)
|
|
|
|
:default-from (:smtp-default-from config)}
|
|
|
|
|
|
|
|
:app.tasks.tasks-gc/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:max-age (dt/duration {:hours 24})
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)}
|
|
|
|
|
|
|
|
:app.tasks.delete-object/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)}
|
|
|
|
|
2021-01-04 18:41:05 +01:00
|
|
|
:app.tasks.delete-storage-object/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:storage (ig/ref :app.storage/storage)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)}
|
|
|
|
|
2020-12-27 22:47:31 +01:00
|
|
|
:app.tasks.delete-profile/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)}
|
|
|
|
|
|
|
|
:app.tasks.file-media-gc/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
2021-01-04 18:41:05 +01:00
|
|
|
:metrics (ig/ref :app.metrics/metrics)
|
|
|
|
:storage (ig/ref :app.storage/storage)
|
|
|
|
:max-age (dt/duration {:hours 72})}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
:app.tasks.file-xlog-gc/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
2021-01-22 17:53:34 +01:00
|
|
|
:max-age (dt/duration {:hours 6})
|
2020-12-27 22:47:31 +01:00
|
|
|
:metrics (ig/ref :app.metrics/metrics)}
|
|
|
|
|
2020-12-28 13:03:12 +01:00
|
|
|
:app.tasks.telemetry/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:version (:full cfg/version)
|
|
|
|
:uri (:telemetry-uri cfg/config)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
:app.srepl/server
|
2020-12-28 13:10:35 +01:00
|
|
|
{:port 6062}
|
|
|
|
|
2021-01-24 16:04:23 +01:00
|
|
|
:app.error-reporter/reporter
|
|
|
|
{:uri (:error-report-webhook cfg/config)
|
|
|
|
:pool (ig/ref :app.db/pool)
|
2021-01-04 18:41:05 +01:00
|
|
|
:executor (ig/ref :app.worker/executor)}
|
|
|
|
|
2021-01-24 16:04:23 +01:00
|
|
|
:app.error-reporter/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)}
|
|
|
|
|
2021-01-04 18:41:05 +01:00
|
|
|
:app.storage/storage
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:executor (ig/ref :app.worker/executor)
|
|
|
|
:backends {:s3 (ig/ref :app.storage.s3/backend)
|
|
|
|
:fs (ig/ref :app.storage.fs/backend)
|
|
|
|
:db (ig/ref :app.storage.db/backend)}}
|
|
|
|
|
|
|
|
:app.storage.s3/backend
|
|
|
|
{:region (:storage-s3-region cfg/config)
|
|
|
|
:bucket (:storage-s3-bucket cfg/config)}
|
|
|
|
|
|
|
|
:app.storage.fs/backend
|
|
|
|
{:directory (:storage-fs-directory cfg/config)
|
|
|
|
:uri (:storage-fs-uri cfg/config)}
|
|
|
|
|
|
|
|
:app.storage.db/backend
|
|
|
|
{:pool (ig/ref :app.db/pool)}}
|
|
|
|
|
2021-01-11 14:29:38 +01:00
|
|
|
(let [backend (:storage-backend cfg/config :fs)]
|
2021-01-04 18:41:05 +01:00
|
|
|
{:app.storage/storage {:backend backend}})
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2020-12-28 13:03:12 +01:00
|
|
|
(when (:telemetry-server-enabled cfg/config)
|
2020-12-27 22:47:31 +01:00
|
|
|
{:app.telemetry/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:executor (ig/ref :app.worker/executor)}
|
|
|
|
|
|
|
|
:app.telemetry/server
|
|
|
|
{:port (:telemetry-server-port config 6063)
|
2020-12-27 23:37:51 +01:00
|
|
|
:handler (ig/ref :app.telemetry/handler)
|
|
|
|
:name "telemetry"}})))
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2020-12-24 14:32:19 +01:00
|
|
|
(defmethod ig/init-key :default [_ data] data)
|
|
|
|
(defmethod ig/prep-key :default [_ data] (d/without-nils data))
|
|
|
|
|
2021-01-05 12:31:16 +01:00
|
|
|
(def system nil)
|
2020-12-24 14:32:19 +01:00
|
|
|
|
|
|
|
(defn start
|
|
|
|
[]
|
2020-12-27 22:47:31 +01:00
|
|
|
(let [system-config (build-system-config cfg/config)]
|
2020-12-24 14:32:19 +01:00
|
|
|
(ig/load-namespaces system-config)
|
|
|
|
(alter-var-root #'system (fn [sys]
|
|
|
|
(when sys (ig/halt! sys))
|
|
|
|
(-> system-config
|
|
|
|
(ig/prep)
|
|
|
|
(ig/init))))
|
|
|
|
(log/infof "Welcome to penpot! Version: '%s'."
|
2020-12-27 22:47:31 +01:00
|
|
|
(:full cfg/version))))
|
2020-12-24 14:32:19 +01:00
|
|
|
|
|
|
|
(defn stop
|
|
|
|
[]
|
|
|
|
(alter-var-root #'system (fn [sys]
|
|
|
|
(when sys (ig/halt! sys))
|
|
|
|
nil)))
|
2020-08-18 18:46:39 +02:00
|
|
|
|
2021-01-19 16:33:32 +01:00
|
|
|
(prefer-method print-method
|
|
|
|
clojure.lang.IRecord
|
|
|
|
clojure.lang.IDeref)
|
|
|
|
|
|
|
|
(prefer-method pprint/simple-dispatch
|
|
|
|
clojure.lang.IPersistentMap
|
|
|
|
clojure.lang.IDeref)
|
|
|
|
|
2020-08-18 18:46:39 +02:00
|
|
|
(defn -main
|
2020-12-02 12:36:08 +01:00
|
|
|
[& _args]
|
2020-12-24 14:32:19 +01:00
|
|
|
(start))
|