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-24 14:32:19 +01:00
|
|
|
[app.common.data :as d]
|
2021-01-31 19:25:26 +01:00
|
|
|
[app.config :as cfg]
|
2020-12-24 14:32:19 +01:00
|
|
|
[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
|
2021-01-29 10:49:30 +01:00
|
|
|
{:sprops (ig/ref :app.sprops/props)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2021-01-29 23:56:11 +01:00
|
|
|
:app.storage/gc-deleted-task
|
2020-12-30 14:38:00 +01:00
|
|
|
{:pool (ig/ref :app.db/pool)
|
2021-01-25 15:22:39 +01:00
|
|
|
:storage (ig/ref :app.storage/storage)
|
|
|
|
:min-age (dt/duration {:hours 2})}
|
2020-12-30 14:38:00 +01:00
|
|
|
|
2021-01-29 23:56:11 +01:00
|
|
|
:app.storage/gc-touched-task
|
|
|
|
{:pool (ig/ref :app.db/pool)}
|
|
|
|
|
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-25 15:22:39 +01:00
|
|
|
:assets (ig/ref :app.http.assets/handlers)
|
2021-01-05 13:49:39 +01:00
|
|
|
:svgparse (ig/ref :app.svgparse/handler)
|
2021-01-25 09:30:07 +01:00
|
|
|
:storage (ig/ref :app.storage/storage)
|
|
|
|
:error-report-handler (ig/ref :app.error-reporter/handler)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2021-01-25 15:22:39 +01:00
|
|
|
:app.http.assets/handlers
|
2021-01-27 17:31:17 +01:00
|
|
|
{:metrics (ig/ref :app.metrics/metrics)
|
2021-02-02 14:31:25 +01:00
|
|
|
:assets-path (:assets-path config)
|
2021-01-27 17:31:17 +01:00
|
|
|
:storage (ig/ref :app.storage/storage)
|
2021-01-25 15:22:39 +01:00
|
|
|
:cache-max-age (dt/duration {:hours 24})
|
|
|
|
:signature-max-age (dt/duration {:hours 24 :minutes 5})}
|
|
|
|
|
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)}
|
|
|
|
|
2021-01-29 10:49:30 +01:00
|
|
|
:app.svgparse/svgc
|
|
|
|
{:metrics (ig/ref :app.metrics/metrics)}
|
|
|
|
|
|
|
|
;; HTTP Handler for SVG parsing
|
|
|
|
:app.svgparse/handler
|
|
|
|
{:metrics (ig/ref :app.metrics/metrics)
|
|
|
|
:svgc (ig/ref :app.svgparse/svgc)}
|
|
|
|
|
|
|
|
;; RLimit definition for password hashing
|
|
|
|
:app.rlimits/password
|
2021-02-02 14:31:25 +01:00
|
|
|
(:rlimits-password config)
|
2021-01-29 10:49:30 +01:00
|
|
|
|
|
|
|
;; RLimit definition for image processing
|
|
|
|
:app.rlimits/image
|
2021-02-02 14:31:25 +01:00
|
|
|
(:rlimits-image config)
|
2021-01-29 10:49:30 +01:00
|
|
|
|
|
|
|
;; A collection of rlimits as hash-map.
|
|
|
|
:app.rlimits/all
|
|
|
|
{:password (ig/ref :app.rlimits/password)
|
|
|
|
:image (ig/ref :app.rlimits/image)}
|
|
|
|
|
|
|
|
: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)
|
|
|
|
:storage (ig/ref :app.storage/storage)
|
|
|
|
:redis (ig/ref :app.redis/redis)
|
|
|
|
:rlimits (ig/ref :app.rlimits/all)
|
|
|
|
:svgc (ig/ref :app.svgparse/svgc)}
|
|
|
|
|
|
|
|
:app.notifications/handler
|
|
|
|
{:redis (ig/ref :app.redis/redis)
|
|
|
|
:pool (ig/ref :app.db/pool)
|
|
|
|
:session (ig/ref :app.http.session/session)
|
|
|
|
:metrics (ig/ref :app.metrics/metrics)}
|
|
|
|
|
2020-12-27 22:47:31 +01:00
|
|
|
: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-02-09 18:55:31 +01:00
|
|
|
:cron #app/cron "0 0 */1 * * ?" ;; hourly
|
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
|
|
|
|
2021-01-29 23:56:11 +01:00
|
|
|
{:id "storage-deleted-gc"
|
2021-02-09 16:15:19 +01:00
|
|
|
:cron #app/cron "0 0 1 */1 * ?" ;; daily (1 hour shift)
|
2021-01-29 23:56:11 +01:00
|
|
|
:fn (ig/ref :app.storage/gc-deleted-task)}
|
|
|
|
|
|
|
|
{:id "storage-touched-gc"
|
2021-02-09 16:15:19 +01:00
|
|
|
:cron #app/cron "0 0 2 */1 * ?" ;; daily (2 hour shift)
|
2021-01-29 23:56:11 +01:00
|
|
|
:fn (ig/ref :app.storage/gc-touched-task)}
|
2020-12-30 14:38:00 +01:00
|
|
|
|
2021-01-04 18:41:05 +01:00
|
|
|
{:id "storage-recheck"
|
2021-02-09 18:55:31 +01:00
|
|
|
:cron #app/cron "0 0 */1 * * ?" ;; hourly
|
2021-01-04 18:41:05 +01:00
|
|
|
: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)}
|
|
|
|
|
2021-02-02 14:31:25 +01:00
|
|
|
(when (:telemetry-enabled config)
|
2021-01-29 10:49:30 +01:00
|
|
|
{:id "telemetry"
|
|
|
|
:cron #app/cron "0 0 */6 * * ?" ;; every 6h
|
2021-02-02 14:31:25 +01:00
|
|
|
:uri (:telemetry-uri config)
|
2021-01-15 14:29:56 +01:00
|
|
|
: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)
|
2021-01-31 20:55:53 +01:00
|
|
|
:max-age (dt/duration {:hours 48})}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
:app.tasks.file-xlog-gc/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
2021-01-27 10:55:26 +01:00
|
|
|
:metrics (ig/ref :app.metrics/metrics)
|
2021-02-09 18:55:31 +01:00
|
|
|
:max-age (dt/duration {:hours 48})}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2020-12-28 13:03:12 +01:00
|
|
|
:app.tasks.telemetry/handler
|
|
|
|
{:pool (ig/ref :app.db/pool)
|
|
|
|
:version (:full cfg/version)
|
2021-02-02 14:31:25 +01:00
|
|
|
:uri (:telemetry-uri config)
|
2021-01-29 10:49:30 +01:00
|
|
|
:sprops (ig/ref :app.sprops/props)}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
|
|
|
:app.srepl/server
|
2021-02-02 14:31:25 +01:00
|
|
|
{:port (:srepl-port config)
|
|
|
|
:host (:srepl-host config)}
|
2020-12-28 13:10:35 +01:00
|
|
|
|
2021-01-29 10:49:30 +01:00
|
|
|
:app.sprops/props
|
|
|
|
{:pool (ig/ref :app.db/pool)}
|
|
|
|
|
2021-01-24 16:04:23 +01:00
|
|
|
:app.error-reporter/reporter
|
2021-02-02 14:31:25 +01:00
|
|
|
{:uri (:error-report-webhook config)
|
2021-01-24 16:04:23 +01:00
|
|
|
: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)
|
2021-02-02 14:31:25 +01:00
|
|
|
:backend (:storage-backend config :fs)
|
2021-01-30 11:28:11 +01:00
|
|
|
:backends {:s3 (ig/ref [::main :app.storage.s3/backend])
|
|
|
|
:db (ig/ref [::main :app.storage.db/backend])
|
|
|
|
:fs (ig/ref [::main :app.storage.fs/backend])
|
|
|
|
:tmp (ig/ref [::tmp :app.storage.fs/backend])}}
|
2021-01-04 18:41:05 +01:00
|
|
|
|
2021-01-30 11:28:11 +01:00
|
|
|
[::main :app.storage.s3/backend]
|
2021-02-02 14:31:25 +01:00
|
|
|
{:region (:storage-s3-region config)
|
|
|
|
:bucket (:storage-s3-bucket config)}
|
2021-01-04 18:41:05 +01:00
|
|
|
|
2021-01-30 11:28:11 +01:00
|
|
|
[::main :app.storage.fs/backend]
|
2021-02-02 14:31:25 +01:00
|
|
|
{:directory (:storage-fs-directory config)}
|
2021-01-04 18:41:05 +01:00
|
|
|
|
2021-01-30 11:28:11 +01:00
|
|
|
[::tmp :app.storage.fs/backend]
|
|
|
|
{:directory "/tmp/penpot"}
|
2021-01-04 18:41:05 +01:00
|
|
|
|
2021-01-30 11:28:11 +01:00
|
|
|
[::main :app.storage.db/backend]
|
|
|
|
{:pool (ig/ref :app.db/pool)}}
|
2020-12-27 22:47:31 +01:00
|
|
|
|
2021-02-02 14:31:25 +01:00
|
|
|
(when (:telemetry-server-enabled 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)
|
2021-01-25 09:29:41 +01:00
|
|
|
(defmethod ig/prep-key :default
|
|
|
|
[_ data]
|
|
|
|
(if (map? data)
|
|
|
|
(d/without-nils data)
|
|
|
|
data))
|
2020-12-24 14:32:19 +01:00
|
|
|
|
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))
|