From 9f3c16a3482b0f57665571ddc10943de61fe7da1 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Mon, 11 Sep 2017 08:05:20 +0100 Subject: [PATCH 01/12] Set version to 0.99.10-SNAPSHOT --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index eb2ad78..b3e3f82 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject smeagol "1.0.0-rc3" +(defproject smeagol "0.99.10-SNAPSHOT" :description "A simple Git-backed Wiki inspired by Gollum" :url "https://github.com/simon-brooke/smeagol" :license {:name "GNU General Public License,version 2.0 or (at your option) any later version" From 2f6f9286a329b9d9733a4733dc151aa34be19fed Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 11 Sep 2017 13:04:51 +0100 Subject: [PATCH 02/12] Tidy-up and robustness; no major functional change. --- project.clj | 2 - resources/passwd | 2 +- resources/public/content/stylesheet.css | 8 + src/smeagol/authenticate.clj | 8 +- src/smeagol/configuration.clj | 3 +- src/smeagol/handler.clj | 2 +- src/smeagol/routes/admin.clj | 2 +- src/smeagol/routes/wiki.clj | 11 +- src/smeagol/sanity.clj | 185 +++++++++++++++--------- src/smeagol/util.clj | 22 ++- 10 files changed, 147 insertions(+), 98 deletions(-) diff --git a/project.clj b/project.clj index b3e3f82..4159363 100644 --- a/project.clj +++ b/project.clj @@ -8,9 +8,7 @@ [com.cemerick/url "0.1.1"] [com.fzakaria/slf4j-timbre "0.3.7"] [com.taoensso/encore "2.92.0"] - [com.cemerick/url "0.1.1"] [com.taoensso/timbre "4.10.0"] - [com.fzakaria/slf4j-timbre "0.3.7"] [com.taoensso/tower "3.0.2" :exclusions [com.taoensso/encore]] [crypto-password "0.2.0"] [environ "1.1.0"] diff --git a/resources/passwd b/resources/passwd index 6b5e6ac..fe61aaf 100644 --- a/resources/passwd +++ b/resources/passwd @@ -1 +1 @@ -{:admin {:admin true, :email "info@weft.scot", :password "admin"}, :jenny {:email "jenny@auchencairn.org", :admin false, :password "$s0$f0801$1uniQfftB37G5e5GklJANQ==$kQ0+/YcCuaz2x5iYjwhNlDlnWX/exE/8pSC+R4C0WvQ="}} \ No newline at end of file +{:admin {:admin true, :email "info@weft.scot", :password "admin"}} diff --git a/resources/public/content/stylesheet.css b/resources/public/content/stylesheet.css index 187b346..81a661c 100644 --- a/resources/public/content/stylesheet.css +++ b/resources/public/content/stylesheet.css @@ -265,6 +265,14 @@ th { padding: 0 2em 0 0; } +.sanity-cause .sanity-stacktrace { + display: none; +} + +.sanity-cause:hover .sanity-stacktrace { + display: block; +} + .vega-bindings, .vega-actions { font-size: 66%; } diff --git a/src/smeagol/authenticate.clj b/src/smeagol/authenticate.clj index 8f83703..c65b5ad 100644 --- a/src/smeagol/authenticate.clj +++ b/src/smeagol/authenticate.clj @@ -38,7 +38,7 @@ (def password-file-path (or (env :smeagol-passwd) - (str (clojure.java.io/resource "passwd")))) + (str (io/resource-path) "../passwd"))) (defn- get-users @@ -112,7 +112,7 @@ (timbre/info (str "Successfully changed password for user " username)) true)) (catch Exception any - (timbre/error + (timbre/error any (format "Changing password failed for user %s failed: %s (%s)" username (.getName (.getClass any)) (.getMessage any))) false)))) @@ -162,7 +162,7 @@ (timbre/info "Successfully added user " username) true) (catch Exception any - (timbre/error + (timbre/error any (format "Adding user %s failed: %s (%s)" username (.getName (.getClass any)) (.getMessage any))) false))))) @@ -179,7 +179,7 @@ (timbre/info (str "Successfully deleted user " username)) true) (catch Exception any - (timbre/error + (timbre/error any (format "Deleting user %s failed: %s (%s)" username (.getName (.getClass any)) (.getMessage any))) false)))) diff --git a/src/smeagol/configuration.clj b/src/smeagol/configuration.clj index d630adc..0f9bcd4 100644 --- a/src/smeagol/configuration.clj +++ b/src/smeagol/configuration.clj @@ -37,7 +37,6 @@ ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (def config-file-path "The relative path to the config file." (or @@ -50,5 +49,5 @@ (try (read-string (slurp config-file-path)) (catch Exception any - (timbre/error "Could not load configuration" any) + (timbre/error any "Could not load configuration") {}))) diff --git a/src/smeagol/handler.clj b/src/smeagol/handler.clj index 2b2c0f9..d44dfc8 100644 --- a/src/smeagol/handler.clj +++ b/src/smeagol/handler.clj @@ -76,7 +76,7 @@ (timbre/info "\n-=[ smeagol started successfully" (when (env :dev) "using the development profile") "]=-") (catch Exception any - (timbre/error "Failure during startup" any) + (timbre/error any "Failure during startup") (destroy)))) ;; timeout sessions after 30 minutes diff --git a/src/smeagol/routes/admin.clj b/src/smeagol/routes/admin.clj index 9491116..106ca35 100644 --- a/src/smeagol/routes/admin.clj +++ b/src/smeagol/routes/admin.clj @@ -98,7 +98,7 @@ :details details :users (auth/list-users)}))) (catch Exception any - (timbre/error (.getMessage any)) + (timbre/error any) (layout/render "edit-user.html" (merge (util/standard-params request) {:title (str (:edit-title-prefix (util/get-messages request)) " " (:target params)) diff --git a/src/smeagol/routes/wiki.clj b/src/smeagol/routes/wiki.clj index 15b3a68..fe80349 100644 --- a/src/smeagol/routes/wiki.clj +++ b/src/smeagol/routes/wiki.clj @@ -45,13 +45,6 @@ ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defn get-git-repo - "Get the git repository for my content, creating it if necessary" - [] - (hist/load-or-init-repo util/content-dir)) - - (defn process-source "Process `source-text` and save it to the specified `file-path`, committing it to Git and finally redirecting to wiki-page." @@ -61,7 +54,7 @@ file-name (str page suffix) file-path (cjio/file util/content-dir file-name) exists? (.exists (cjio/as-file file-path)) - git-repo (get-git-repo) + git-repo (hist/load-or-init-repo util/content-dir) user (session/get :user) email (auth/get-email user) summary (format "%s: %s" user (or (:summary params) "no summary"))] @@ -157,7 +150,7 @@ [request] (let [params (keywordize-keys (:params request)) data-path (str (io/resource-path) "/content/uploads/") - git-repo (get-git-repo) + git-repo (hist/load-or-init-repo util/content-dir) upload (:upload params) uploaded (if upload (ul/store-upload params data-path)) user (session/get :user) diff --git a/src/smeagol/sanity.clj b/src/smeagol/sanity.clj index 02f7b2d..e7c0503 100644 --- a/src/smeagol/sanity.clj +++ b/src/smeagol/sanity.clj @@ -252,13 +252,28 @@ (as-hiccup [this dictionary] "") clojure.lang.Keyword - (as-hiccup [this dictionary] (str (or (this dictionary)(string/replace (name this) "-" " ")) " ")) + (as-hiccup [this dictionary] + (str + (or + (this dictionary) + (string/replace (name this) "-" " ")) + " ")) clojure.lang.PersistentList - (as-hiccup [this dictionary] (apply vector (cons :div (map #(as-hiccup % dictionary) this)))) + (as-hiccup [this dictionary] + (apply + vector + (cons + :div + (map #(as-hiccup % dictionary) this)))) clojure.lang.PersistentVector - (as-hiccup [this dictionary] (apply vector (cons :div (map #(as-hiccup % dictionary) this)))) + (as-hiccup [this dictionary] + (apply + vector + (cons + :div + (map #(as-hiccup % dictionary) this)))) clojure.lang.PersistentArrayMap (as-hiccup [this dictionary] @@ -296,66 +311,94 @@ vector (cons :div - (cons - {:class "sanity-exception"} - (map - (fn [x] - [:div - {:class "sanity-cause"} - (.getMessage x) - [:div {:class "sanity-stacktrace"} - (apply - vector - (cons - :ol - (map - as-hiccup - (.getStackTrace x) - dictionary)))]]) - (get-causes this)))))) + (cons + {:class "sanity-exception"} + (map + (fn [x] + [:div + {:class "sanity-cause"} + [:h2 (.getMessage x)] + [:div {:class "sanity-stacktrace"} + (apply + vector + (cons + :ol + (map + as-hiccup + (.getStackTrace x) + dictionary)))]]) + (get-causes this)))))) java.lang.Object (as-hiccup [this dictionary] (str this " "))) -(defn sanity-check-report - [problems] +(defn get-locale-messages + "Get messages for the server-side locale." + [] (let [locale (Locale/getDefault) - locale-specifier (str (.getLanguage locale) "-" (.getCountry locale)) - messages (try - (i18n/get-messages locale-specifier "i18n" "en-GB") - (catch Exception any {}))] + locale-specifier (str (.getLanguage locale) "-" (.getCountry locale))] + (try + (i18n/get-messages locale-specifier "i18n" "en-GB") + (catch Exception any {})))) + + +;; Prepackaged hiccup sub-units +(defn as-hiccup-head + [messages] + [:head + [:title (as-hiccup :smeagol-not-initialised messages)] + [:link {:href "/content/stylesheet.css" :rel "stylesheet"}]]) + + +(defn as-hiccup-header + [messages] + [:header + [:div {:id "nav"} " "] + [:h1 (as-hiccup :smeagol-not-initialised messages)] + [:p " "]]) + + +(defn as-hiccup-see-doc + [messages] + [:p (as-hiccup :see-documentation messages) + [:a + {:href + "https://github.com/journeyman-cc/smeagol/wiki/Deploying-Smeagol"} + (as-hiccup :here messages)] "."]) + + +(defn as-hiccup-footer + [messages] + [:footer + [:div {:id "credits"} + [:div + [:img {:height "16" :width "16" :alt "one wiki to rule them all" :src "img/smeagol.png"}] + " One Wiki to rule them all || Smeagol wiki engine || " + [:img + {:height "16" :width "16" + :alt "The Web Engineering Factory & Toolworks" + :src "http://www.weft.scot/images/weft.logo.64.png"}] + " Developed by " + [:a {:href "http://www.weft.scot/"}"WEFT"]]]]) + + +(defn sanity-check-report + "Convert this `problem` report into a nicely formatted HTML page" + [problems] + (let [messages (get-locale-messages)] (html [:html - [:head - [:title (as-hiccup :smeagol-not-initialised messages)] - [:link {:href "/content/stylesheet.css" :rel "stylesheet"}]] + (as-hiccup-head messages) [:body - [:header - [:div {:id "nav"} " "] - [:h1 (as-hiccup :smeagol-not-initialised messages)] - [:p " "]] - [:div {:id "error" :class "error"} - [:div {:class "error"} - (as-hiccup [(count (keys problems)) :problems-found] messages)]] + (as-hiccup-header messages) + [:div {:id "error"} + [:p {:class "error"} + (rest (as-hiccup [(count (keys problems)) :problems-found] messages))]] [:div {:id "main-container" :class "sanity-check-report"} [:p (as-hiccup :smeagol-misconfiguration messages)] (as-hiccup problems messages) - [:p (as-hiccup :see-documentation messages) - [:a - {:href - "https://github.com/journeyman-cc/smeagol/blob/master/resources/public/content/Deploying%20Smeagol.md"} - (as-hiccup :here messages)]]] - [:footer - [:div {:id "credits"} - [:div - [:img {:height "16" :width "16" :alt "one wiki to rule them all" :src "img/smeagol.png"}] - " One Wiki to rule them all || Smeagol wiki engine || " - [:img - {:height "16" :width "16" - :alt "The Web Engineering Factory & Toolworks" - :src "http://www.weft.scot/images/weft.logo.64.png"}] - " Developed by " - [:a {:href "http://www.weft.scot/"}"WEFT"]]]]]]))) + (as-hiccup-see-doc messages)] + (as-hiccup-footer messages)]]))) (defn- raw-sanity-check-installation @@ -383,26 +426,26 @@ If no argument is passed, run the sanity check and if it fails return page contents; if `error` is passed, just return page content describing the error." ([error] - (html - [:html - [:head - [:title "Smeagol is not initialised correctly"] - [:link {:href "/content/stylesheet.css" :rel "stylesheet"}]] - [:body - [:header - [:h1 "Smeagol is not initialised correctly"]] - [:div {:id "error"} - [:p {:class "error"} (.getMessage error)]] - [:p "There was a problem launching Smeagol probably because of misconfiguration:"] - (apply - vector - (cons :ol - (map #(vector :li (.getMessage %)) - (get-causes error)))) - [:p :see-documentation - [:a {:href "https://github.com/journeyman-cc/smeagol/blob/develop/resources/public/content/Deploying%20Smeagol.md"} "here"]]]])) + (let [messages (get-locale-messages)] + (html + [:html + (as-hiccup-head messages) + [:body + (as-hiccup-header messages) + [:div {:id "error"} + [:p {:class "error"} (.getMessage error)]] + [:div {:id "main-container" :class "sanity-check-report"} + [:p (as-hiccup :smeagol-misconfiguration messages)] + (as-hiccup error messages) + (as-hiccup-see-doc messages)] + (as-hiccup-footer messages)]]))) ([] (try (sanity-check-installation) - (catch Exception any (show-sanity-check-error any))))) + (catch Exception any + (timbre/error any "Failure during sanity check") + (show-sanity-check-error any))))) + +(show-sanity-check-error (Exception. "That's insane!")) + diff --git a/src/smeagol/util.clj b/src/smeagol/util.clj index 69cce68..902e377 100644 --- a/src/smeagol/util.clj +++ b/src/smeagol/util.clj @@ -8,7 +8,8 @@ [scot.weft.i18n.core :as i18n] [smeagol.authenticate :as auth] [smeagol.configuration :refer [config]] - [smeagol.formatting :refer [md->html]])) + [smeagol.formatting :refer [md->html]] + [taoensso.timbre :as timbre])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; @@ -55,12 +56,19 @@ "Return the most acceptable messages collection we have given the `Accept-Language` header in this `request`." [request] - (merge - (i18n/get-messages - ((:headers request) "accept-language") - "i18n" - "en-GB") - config)) + (let [specifier ((:headers request) "accept-language") + messages (try + (i18n/get-messages specifier "i18n" "en-GB") + (catch Exception any + (timbre/error + any + (str + "Failed to parse accept-language header " + specifier)) + {}))] + (merge + messages + config))) (def get-messages (memoize raw-get-messages)) From f3883c6b07f1b62ad96e35c9edc81d2fee592080 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 11 Sep 2017 13:25:10 +0100 Subject: [PATCH 03/12] Experimental changes to Dockerfile --- Dockerfile | 26 ++++++++++++++++++++++++-- resources/public/uploads/water.png | Bin 15083 -> 0 bytes 2 files changed, 24 insertions(+), 2 deletions(-) delete mode 100644 resources/public/uploads/water.png diff --git a/Dockerfile b/Dockerfile index 0dfae96..87bfd0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,25 @@ -FROM tomcat:alpine -COPY target/smeagol-*-standalone.war $CATALINA_HOME/webapps/smeagol.war +FROM alpine:3.6 + +MAINTAINER Simon Brooke + +ENV JAVA_HOME=/usr/lib/jvm/default-jvm + +RUN apk add --no-cache openjdk7 && \ + ln -sf "${JAVA_HOME}/bin/"* "/usr/bin/" + +# ensure the directories I'm going to write to actually exist! +RUN mkdir -p /usr/local/bin +RUN mkdir -p /usr/local/etc + +COPY target/smeagol-*-standalone.jar /usr/local/bin/smeagol.jar +COPY resources/passwd /usr/local/etc/passwd +COPY resources/config.edn /usr/local/etc/config.edn +COPY resources/pubilc/content /usr/local/etc/content + +ENV SMEAGOL_CONFIG=/usr/local/etc/config.edn +ENV SMEAGOL_CONTENT_DIR=/usr/local/etc/content +ENV SMEAGOL_PASSWD=/usr/local/etc/passwd +ENV TIMBRE_DEFAULT_STACKTRACE_FONTS="{}" + +CMD java -jar /usr/local/bin/smeagol.jar diff --git a/resources/public/uploads/water.png b/resources/public/uploads/water.png deleted file mode 100644 index e97d1ed9eda34a1c3d5ecff8007d20537590de9d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15083 zcmVKLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8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)?laIN4t!yh2`BPlfxO@7)|Z6`j*YLP#l+-Qh!9gXGj>?h8>GeNLIr5>6 z4->rlMXkK;JdoX(VZS*A$3f|LX0r8Ihrd%%G$S8-VR{_TKmPf~MW)@=a74#~{xIsV z4{1}IRE_Gpk9jEe-kv7I*W$a@@bvhNn#r3NP8$zk%xHFNr5jNYqu#gf-Tw>!zWm*v z*(mr@co{@Rj>|+px45*QKIaC+zSX^>p&rw*MkCsd+0ek2YB=Ek9{_F-6{8$OuLA%8 N002ovPDHLkV1lJl!a)E4 From 2f4f7aa1c5793ead5c85bc4c63d27bcf3d8834ca Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Tue, 12 Sep 2017 00:49:16 +0100 Subject: [PATCH 04/12] #33: Fix --- Dockerfile | 8 ++- resources/public/content/Deploying Smeagol.md | 23 +------- resources/public/content/Docker Image.md | 55 +++++++++++++++++++ 3 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 resources/public/content/Docker Image.md diff --git a/Dockerfile b/Dockerfile index 87bfd0e..c546620 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ MAINTAINER Simon Brooke ENV JAVA_HOME=/usr/lib/jvm/default-jvm -RUN apk add --no-cache openjdk7 && \ +RUN apk add --no-cache openjdk8 && \ ln -sf "${JAVA_HOME}/bin/"* "/usr/bin/" # ensure the directories I'm going to write to actually exist! @@ -14,12 +14,16 @@ RUN mkdir -p /usr/local/etc COPY target/smeagol-*-standalone.jar /usr/local/bin/smeagol.jar COPY resources/passwd /usr/local/etc/passwd COPY resources/config.edn /usr/local/etc/config.edn -COPY resources/pubilc/content /usr/local/etc/content +COPY resources/public/content /usr/local/etc/content ENV SMEAGOL_CONFIG=/usr/local/etc/config.edn ENV SMEAGOL_CONTENT_DIR=/usr/local/etc/content ENV SMEAGOL_PASSWD=/usr/local/etc/passwd ENV TIMBRE_DEFAULT_STACKTRACE_FONTS="{}" +ENV TIMBRE_LEVEL=':info' +ENV PORT=80 + +EXPOSE 80 CMD java -jar /usr/local/bin/smeagol.jar diff --git a/resources/public/content/Deploying Smeagol.md b/resources/public/content/Deploying Smeagol.md index 653831a..009d610 100644 --- a/resources/public/content/Deploying Smeagol.md +++ b/resources/public/content/Deploying Smeagol.md @@ -36,25 +36,4 @@ The problem with this is that unless the environment variables (see above) were ## Experimental Docker image -You can now run Smeagol as a [Docker](http://www.docker.com) image. Read more about [[Using the Docker Image]]. - -To run my Docker image, use - - docker run simonbrooke/smeagol - -Smeagol will run, obviously, on the IP address of your Docker image, on port 8080. To find the IP address, start the image using the command above and then use - - docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q) - -Suppose this prints '10.10.10.10', then the URL to browse to will be http://10.10.10.10:8080/smeagol/ - -This image is _experimental_, but it does seem to work fairly well. What it does **not** yet do, however, is push the git repository to a remote location, so when you tear the Docker image down your edits will be lost. My next objective for this image is for it to have a cammand line parameter being the git address of a repository from which it can initialise the Wiki content, and to which it will periodically push local changes to the Wiki content. - -To build your own Docker image, run: - - lein clean - lein bower install - lein ring uberwar - lein docker build - -This will build a new Docker image locally; you can, obviously, push it to your own Docker repository if you wish. +You can now run Smeagol as a [Docker](http://www.docker.com) image. Read more about using the [[Docker Image]]. diff --git a/resources/public/content/Docker Image.md b/resources/public/content/Docker Image.md new file mode 100644 index 0000000..4bfc58f --- /dev/null +++ b/resources/public/content/Docker Image.md @@ -0,0 +1,55 @@ +Smeagol is available as a Docker image + +To run my Docker image, use + + docker run -p 127.0.0.1:80:80 simonbrooke/smeagol + +Where 127.0.0.1 is the IP address through which you want to forward port 80 (in real life it wouldn't be 127.0.0.1, but that's safe for testing). + +You can then browse to Smeagol by pointing your browser at http://localhost/. + +As of version 0.99.10, the Docker image is now based on the Jetty, rather than the Tomcat, deployment of Smeagol (that is to say, it runs the executable jar file). This makes for a lighter weight Docker image, but there are still some problems which need to be addressed. + +The `config.edn` and `passwd` files and the `content` directory are copied into `/usr/local/etc` in the Docker image, and the appropriate environment variables are set up to point to them: +``` +COPY resources/passwd /usr/local/etc/passwd +COPY resources/config.edn /usr/local/etc/config.edn +COPY resources/public/content /usr/local/etc/content + +ENV SMEAGOL_CONFIG=/usr/local/etc/config.edn +ENV SMEAGOL_CONTENT_DIR=/usr/local/etc/content +ENV SMEAGOL_PASSWD=/usr/local/etc/passwd +``` +This works for play purposes. However, it means that any edits made to either the `passwd` file or the `content` directory will be lost when the Docker image is shut down. You really need to have these resources copied to a place in a real file system which is mounted by the image. While I intend that by the 1.1.0 release of Smeagol it will be possible to configure a remote origin repository to which changes are periodically pushed, which will backup and preserve the content, this won't save the `passwd` file, as this is deliberately not stored in the git repository for security reasons. + +## Mounting real file systems + +It's possible to mount external file systems, and to override environment variables, with arguments to Docker's extraordinarily complex [run command](https://docs.docker.com/engine/reference/commandline/run/). + +I'm currently working with a recipe: + + docker run -p 127.0.0.1:80:80 -v ~/tmp/etc:/usr/local/etc simonbrooke/smeagol + +Where: + +1. `127.0.0.1` is the IP address on the real host on which you wish to serve; +2. `:80:80` maps port 80 on the image to port 80 on the specified IP address; +3. `~/tmp/etc` is the directory on the file system of the real host where files are stored; +4. `/usr/local/etc` is the directory within the image file system to which that will be mounted; + +This works, and uses the default values of the environment variables which are set up in the Docker image. However, I'm very much prepared to believe there are better recipes. + +## Status + +This image is _experimental_, but it does seem to work fairly well. What it does **not** yet do, however, is push the git repository to a remote location, so when you tear the Docker image down your edits will be lost. My next objective for this image is for it to have a cammand line parameter being the git address of a repository from which it can initialise the Wiki content, and to which it will periodically push local changes to the Wiki content. + +## Building the Docker image + +To build your own Docker image, run: + + lein clean + lein bower install + lein ring uberjar + lein docker build + +This will build a new Docker image locally; you can, obviously, push it to your own Docker repository if you wish. From 3a4d177923196bd83dab675e4eca094801e53f28 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Tue, 12 Sep 2017 01:03:18 +0100 Subject: [PATCH 05/12] Version 0.99.10 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index d599bae..36f3ba6 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject smeagol "0.99.10-SNAPSHOT" +(defproject smeagol "0.99.10" :description "A simple Git-backed Wiki inspired by Gollum" :url "https://github.com/simon-brooke/smeagol" :license {:name "GNU General Public License,version 2.0 or (at your option) any later version" From 9152d1fe6d5beb3428832cb155c89555174bb3b5 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Tue, 12 Sep 2017 01:14:45 +0100 Subject: [PATCH 06/12] Version 0.99.11-SNAPSHOT --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 36f3ba6..0645d57 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject smeagol "0.99.10" +(defproject smeagol "0.99.11-SNAPSHOT" :description "A simple Git-backed Wiki inspired by Gollum" :url "https://github.com/simon-brooke/smeagol" :license {:name "GNU General Public License,version 2.0 or (at your option) any later version" From ee0453e395a3b26dffd3e92bc59a7a98ece99842 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 12 Sep 2017 11:29:42 +0100 Subject: [PATCH 07/12] Allow configuration to be overridden by environment variables This is (I think) the final piece in enabling Smeagol to be run neatly from Docker and, indeed, from a pre-packaged jar file. --- src/smeagol/configuration.clj | 52 +++++++++++++++++++++++++++++++++-- src/smeagol/handler.clj | 10 ++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/smeagol/configuration.clj b/src/smeagol/configuration.clj index 0f9bcd4..7b14ed6 100644 --- a/src/smeagol/configuration.clj +++ b/src/smeagol/configuration.clj @@ -44,10 +44,58 @@ (str (io/resource-path) "../config.edn"))) +(defn- from-env-vars + "Read a map from those of these environment variables which have values" + [& vars] + (reduce + #(let [v (env %2)] + (if v (assoc %1 %2 v) %1)) + {} + vars)) + + +(defn transform-map + "transform this map `m` by applying these `transforms`. Each transforms + is expected to comprise a map with the keys :from and :to, whose values + are respectively a key to match and a key to replace that match with, + and optionally a key :transform, whose value is a function of one + argument to be used to transform the value of that key." + [m tuples] + (reduce + (fn [m tuple] + (if + (and (map? tuple) (map? m) (m (:from tuple))) + (let [old-val (m (:from tuple)) + t (:transform tuple) + new-val (if t (apply t (list old-val)) old-val)] + (assoc (dissoc m (:from tuple)) (:to tuple) new-val)) + m)) + m + tuples)) + + +(def config-env-transforms + "Transforms to use with `transform-map` to convert environment + variable names (which need to be specific) into the shorter names + used internally" + '( {:from :smeagol-site-title :to :site-title} + {:from :smeagol-default-locale :to :default-locale} + {:from :smeagol-formatters :to :formatters :transform read-string})) + + (def config - "The actual configuration, as a map." + "The actual configuration, as a map. The idea here is that the config + file is read (if it is specified and present), but that individual + values " (try - (read-string (slurp config-file-path)) + (let [file-contents (try + (read-string (slurp config-file-path)) + (catch Exception _ {}))] + (merge + file-contents + (transform-map + (from-env-vars :smeagol-site-title :smeagol-default-locale) + config-env-transforms))) (catch Exception any (timbre/error any "Could not load configuration") {}))) diff --git a/src/smeagol/handler.clj b/src/smeagol/handler.clj index d44dfc8..dfcf187 100644 --- a/src/smeagol/handler.clj +++ b/src/smeagol/handler.clj @@ -2,6 +2,7 @@ :author "Simon Brooke"} smeagol.handler (:require [clojure.java.io :as cjio] + [clojure.string :refer [lower-case]] [compojure.core :refer [defroutes]] [compojure.route :as route] [cronj.core :as cronj] @@ -43,6 +44,7 @@ (defn user-access [request] (session/get :user)) + (defroutes base-routes (route/resources "/") (route/not-found "Not Found")) @@ -69,7 +71,13 @@ {:rotor (rotor/rotor-appender {:path "smeagol.log" :max-size (* 512 1024) - :backlog 10})}}) + :backlog 10})} + :level (or + (read-string (env :timbre-level)) + (let [level (read-string (env :log-level))] + (if (string? level) (lower-case (keyword level)))) + (if (env :dev) :debug) + :info)}) (cronj/start! session-manager/cleanup-job) (if (env :dev) (parser/cache-off!)) ;;start the expired session cleanup job From a7aca5fab21f92533036486fc96fb30ee2205dfa Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 12 Sep 2017 12:26:34 +0100 Subject: [PATCH 08/12] Documentation of new configuration. --- resources/config.edn | 12 ++++-- resources/public/content/Configuration.md | 37 +++++++++++++------ resources/public/content/Deploying Smeagol.md | 14 +++++-- resources/public/content/Docker Image.md | 2 +- .../public/content/Environment Variables.md | 11 ++++++ src/smeagol/authenticate.clj | 3 +- src/smeagol/configuration.clj | 5 ++- src/smeagol/handler.clj | 5 +-- src/smeagol/util.clj | 2 +- 9 files changed, 65 insertions(+), 26 deletions(-) create mode 100644 resources/public/content/Environment Variables.md diff --git a/resources/config.edn b/resources/config.edn index 27c6a8b..0b86bc2 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -26,9 +26,15 @@ ;; ; ; ; ; ; ; ; ; ; { - :site-title "Smeagol" ;; overall title of the site, used in page headings - :default-locale "en-GB" ;; default language used for messages - :formatters {"vega" smeagol.formatting/process-vega + :site-title "Smeagol" ;; overall title of the site, used in page headings + :default-locale "en-GB" ;; default language used for messages +;; :content-dir "/home/simon/tmp/test-content" + ;; where content is served from + :passwd "/home/simon/tmp/passwd" + ;; where the password file is stored + :log-level :info ;; the minimum logging level; one of + ;; TRACE DEBUG INFO WARN ERROR FATAL + :formatters {"vega" smeagol.formatting/process-vega "vis" smeagol.formatting/process-vega "mermaid" smeagol.formatting/process-mermaid "backticks" smeagol.formatting/process-backticks} diff --git a/resources/public/content/Configuration.md b/resources/public/content/Configuration.md index fd29caf..4e5d987 100644 --- a/resources/public/content/Configuration.md +++ b/resources/public/content/Configuration.md @@ -2,19 +2,32 @@ Smeagol reads a configuration file, whose content should be formatted as a cloju The default content is as follows: - { - :site-title "Smeagol" ;; overall title of the site, used in page headings - :default-locale "en-GB" ;; default language used for messages - :formatters {"vega" smeagol.formatting/process-vega - "vis" smeagol.formatting/process-vega - "mermaid" smeagol.formatting/process-mermaid - "backticks" smeagol.formatting/process-backticks} - } +``` +{ + :site-title "Smeagol" ;; overall title of the site, used in page headings + :default-locale "en-GB" ;; default language used for messages + :content-dir "/usr/local/etc/content" + ;; where content is served from + :passwd "/usr/local/etc/passwd" + ;; where the password file is stored + :log-level :info ;; the minimum logging level; one of + ;; :trace :debug :info :warn :error :fatal + :formatters {"vega" smeagol.formatting/process-vega + "vis" smeagol.formatting/process-vega + "mermaid" smeagol.formatting/process-mermaid + "backticks" smeagol.formatting/process-backticks} +} +``` -The three keys given above should be present. The values should be: +The values should be: -* **:site-title** The title for your wiki -* **:default-locale** A string comprising a lower-case [ISO 639](https://en.wikipedia.org/wiki/ISO_639) code specifying a language, optionally followed by a hyphen and an upper-case [ISO 3166](https://en.wikipedia.org/wiki/ISO_3166) specifying a country. -* **:formatters** A map of formatters used in [[Extensible Markup]], q.v. +* `:content-dir` The directory in which your editable content is stored; +* `:default-locale` A string comprising a lower-case [ISO 639](https://en.wikipedia.org/wiki/ISO_639) code specifying a language, optionally followed by a hyphen and an upper-case [ISO 3166](https://en.wikipedia.org/wiki/ISO_3166) specifying a country. +* `:formatters` A map of formatters used in [[Extensible Markup]], q.v. +* `:log-level` The minimum level of log messages to be logged; one of `:trace :debug :info :warn :error :fatal` +* `:passwd` The path to your `passwd` file - see [[Security and authentication]]; +* `:site-title` The title for your wiki. The default file is at `resources/config.edn`; this default can be overridden by providing an environment variable, `SMEAGOL_CONFIG`, whose value is the full or relative pathname of a suitable file. + +Note that all the values in the configuration can be overridden with [[Environment Variables]]. diff --git a/resources/public/content/Deploying Smeagol.md b/resources/public/content/Deploying Smeagol.md index 009d610..65c8eae 100644 --- a/resources/public/content/Deploying Smeagol.md +++ b/resources/public/content/Deploying Smeagol.md @@ -6,12 +6,18 @@ To deploy Smeagol as a stand-alone application, either download the jar file for This will create a jar file in the `target` directory, named `smeagol-`*VERSION*`-standalone.jar`. -Smeagol cannot access either its configuration or its content from the jar file, as otherwise they would not be editable. Consequently you should set up three environment variables: +Smeagol cannot access either its configuration or its content from the jar file, as otherwise they would not be editable. There are three solutions to this: -1. `SMEAGOL_CONFIG` should be the full or relative pathname of a Smeagol [[Configuration]] file; -2. `SMEAGOL_CONTENT_DIR` should be the full or relative pathname of the directory from which Smeagol should serve content (which may initially be empty, but must be writable by the process which runs Smeagol)' -3. `SMEAGOL_PASSWD` should be the full or relative pathname of a Smeagol Passwd file - see [[Security and authentication]]. This file must contain an entry for at least your initial user, and, if you want to administer users through the user interface, must be writable by the process which runs Smeagol. +### Custom configuration file +You can copy the standard [[Configuration]] file `resources/config.edn` to somewhere outside the jar file, edit it to suit your installation, and set up a single environment variable, `SMEAGOL_CONFIG`, whose value is the path to your new configuration file. +### Environment variables +Alternatively, you can configure everything through [[Environment Variables]]. + +### Hybrid strategy +You can have both a configuration file and environment variables. If you do this, the environment variables override the values in the configuration file. + +### Necessary content **NOTE** that `SMEAGOL_CONTENT_DIR` must contain at least the following files: 1. `_edit-side-bar.md` - the side-bar that should be displayed when editing pages; diff --git a/resources/public/content/Docker Image.md b/resources/public/content/Docker Image.md index 4bfc58f..c4e4b9a 100644 --- a/resources/public/content/Docker Image.md +++ b/resources/public/content/Docker Image.md @@ -8,7 +8,7 @@ Where 127.0.0.1 is the IP address through which you want to forward port 80 (in You can then browse to Smeagol by pointing your browser at http://localhost/. -As of version 0.99.10, the Docker image is now based on the Jetty, rather than the Tomcat, deployment of Smeagol (that is to say, it runs the executable jar file). This makes for a lighter weight Docker image, but there are still some problems which need to be addressed. +As of version 0.99.10, the Docker image is now based on the Jetty, rather than the Tomcat, deployment of Smeagol (that is to say, it runs the executable jar file). This makes for a lighter weight Docker image. All configuration can be overridden with [[Environment Variables]], which can be passed into the Docker container when the image is invoked, or from a [[Configuration]] file. The `config.edn` and `passwd` files and the `content` directory are copied into `/usr/local/etc` in the Docker image, and the appropriate environment variables are set up to point to them: ``` diff --git a/resources/public/content/Environment Variables.md b/resources/public/content/Environment Variables.md new file mode 100644 index 0000000..cca8a0b --- /dev/null +++ b/resources/public/content/Environment Variables.md @@ -0,0 +1,11 @@ +Smeagol can be configured entirely with environment variables. The variables are: + +1. `SMEAGOL_CONFIG` (optional but advised) should be the full or relative pathname of a Smeagol [[Configuration]] file; +2. `SMEAGOL_CONTENT_DIR` should be the full or relative pathname of the directory from which Smeagol should serve content (which may initially be empty, but must be writable by the process which runs Smeagol); +3. `SMEAGOL_DEFAULT_LOCALE` which should be a locale specification in the form "en-GB", "fr-FR", or whatever to suit your users; +4. `SMEAGOL_FORMATTERS` should be an [edn](https://github.com/edn-format/edn)-formatted map of formatter directives (this would be pretty hard to do from an environment variable); +5. `SMEAGOL_LOG_LEVEL` which should be one of `TRACE DEBUG INFO WARN ERROR FATAL` +6. `SMEAGOL_PASSWD` should be the full or relative pathname of a Smeagol Passwd file - see [[Security and authentication]]. This file must contain an entry for at least your initial user, and, if you want to administer users through the user interface, must be writable by the process which runs Smeagol. +7. `SMEAGOL_SITE_TITLE` which should be the title you want shown on the header of all pages. + +You can have both a configuration file and environment variables; if you do, the values of the environment variables take precedence over the values in the config file. diff --git a/src/smeagol/authenticate.clj b/src/smeagol/authenticate.clj index c65b5ad..e4219e9 100644 --- a/src/smeagol/authenticate.clj +++ b/src/smeagol/authenticate.clj @@ -4,6 +4,7 @@ (:require [crypto.password.scrypt :as password] [environ.core :refer [env]] [noir.io :as io] + [smeagol.configuration :refer [config]] [taoensso.timbre :as timbre])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -37,7 +38,7 @@ ;; the relative path to the password file. (def password-file-path (or - (env :smeagol-passwd) + (:passwd config) (str (io/resource-path) "../passwd"))) diff --git a/src/smeagol/configuration.clj b/src/smeagol/configuration.clj index 7b14ed6..9c67d91 100644 --- a/src/smeagol/configuration.clj +++ b/src/smeagol/configuration.clj @@ -80,7 +80,10 @@ used internally" '( {:from :smeagol-site-title :to :site-title} {:from :smeagol-default-locale :to :default-locale} - {:from :smeagol-formatters :to :formatters :transform read-string})) + {:from :smeagol-formatters :to :formatters :transform read-string} + {:from :smeagol-content-dir :to :content-dir} + {:from :smeagol-passwd :to :passwd} + {:from :smeagol-log-level :to :log-level :transform (fn [s] (keyword (lower-case s)))})) (def config diff --git a/src/smeagol/handler.clj b/src/smeagol/handler.clj index dfcf187..d25e415 100644 --- a/src/smeagol/handler.clj +++ b/src/smeagol/handler.clj @@ -12,6 +12,7 @@ [noir.util.middleware :refer [app-handler]] [ring.middleware.defaults :refer [site-defaults]] [selmer.parser :as parser] + [smeagol.configuration :refer [config]] [smeagol.routes.wiki :refer [wiki-routes]] [smeagol.middleware :refer [load-middleware]] [smeagol.session-manager :as session-manager] @@ -73,9 +74,7 @@ :max-size (* 512 1024) :backlog 10})} :level (or - (read-string (env :timbre-level)) - (let [level (read-string (env :log-level))] - (if (string? level) (lower-case (keyword level)))) + (:log-level config) (if (env :dev) :debug) :info)}) (cronj/start! session-manager/cleanup-job) diff --git a/src/smeagol/util.clj b/src/smeagol/util.clj index 902e377..015a5db 100644 --- a/src/smeagol/util.clj +++ b/src/smeagol/util.clj @@ -37,7 +37,7 @@ (def content-dir (or - (env :smeagol-content-dir) + (:content-dir config) (cjio/file (io/resource-path) "content"))) From 009ae30a08d35f7f9f5cb3952daed3695ea3fb37 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 12 Sep 2017 16:29:23 +0100 Subject: [PATCH 09/12] Making new config more robust --- resources/config.edn | 18 +++--- resources/passwd | 2 +- resources/public/content/Deploying Smeagol.md | 39 ++++++++++-- .../public/content/Environment Variables.md | 34 ++++++---- src/smeagol/configuration.clj | 63 ++++++++++++++----- src/smeagol/sanity.clj | 5 +- 6 files changed, 119 insertions(+), 42 deletions(-) diff --git a/resources/config.edn b/resources/config.edn index 0b86bc2..0fcb152 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -22,20 +22,22 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; config.edn: a simple configuration map for Smeagol; inspired by Cryogen. -;;; This is top-level configuration. +;;; This is top-level configuration. All values can be overridden with +;;; environment variables. ;; ; ; ; ; ; ; ; ; ; { - :site-title "Smeagol" ;; overall title of the site, used in page headings + :content-dir "resources/public/content" + ;; where content is served from. :default-locale "en-GB" ;; default language used for messages -;; :content-dir "/home/simon/tmp/test-content" - ;; where content is served from - :passwd "/home/simon/tmp/passwd" - ;; where the password file is stored - :log-level :info ;; the minimum logging level; one of - ;; TRACE DEBUG INFO WARN ERROR FATAL :formatters {"vega" smeagol.formatting/process-vega "vis" smeagol.formatting/process-vega "mermaid" smeagol.formatting/process-mermaid "backticks" smeagol.formatting/process-backticks} + :log-level :info ;; the minimum logging level; one of + ;; :trace :debug :info :warn :error :fatal + :passwd "resources/passwd" + ;; where the password file is stored + :site-title "Smeagol" ;; overall title of the site, used in + ;; page headings } diff --git a/resources/passwd b/resources/passwd index fe61aaf..07bf1d9 100644 --- a/resources/passwd +++ b/resources/passwd @@ -1 +1 @@ -{:admin {:admin true, :email "info@weft.scot", :password "admin"}} +{:admin {:admin true, :email "info@weft.scot", :password "admin"}, :simon {:email "simon@journeyman.cc", :admin true, :password "$s0$f0801$sqhbxtzK6nx9RnVUhwtQlg==$dMIUbof8esjsGyiB+zb3gMH21L/WSCR+wD3vIag4EVc="}} \ No newline at end of file diff --git a/resources/public/content/Deploying Smeagol.md b/resources/public/content/Deploying Smeagol.md index 65c8eae..4bcd304 100644 --- a/resources/public/content/Deploying Smeagol.md +++ b/resources/public/content/Deploying Smeagol.md @@ -1,3 +1,8 @@ +## Choosing a deployment mechanism +There are currently three ways you can deploy Smeagol: as an executable Jar file, as a Docker image, and as a web-app in a [Servlet container](https://en.wikipedia.org/wiki/Web_container). Each method has advantages and disadvantages. + +The Jar file is extremely easy to deploy and to configure, but cannot currently serve [HTTPS](https://en.wikipedia.org/wiki/HTTPS), which, on the modern web, is a significant disadvantage. The Docker image is just a wrapper around the Jar file; it's particularly suitable for automated deployment. The web-app solution offloads responsibility for things like HTTPS to the Servlet container, and consequently can be much more secure; but it can really only be configured at compile time. + ## Deploying as a stand-alone application To deploy Smeagol as a stand-alone application, either download the jar file for the release you want to deploy, or clone the source and compile it with: @@ -9,7 +14,7 @@ This will create a jar file in the `target` directory, named `smeagol-`*VERSION* Smeagol cannot access either its configuration or its content from the jar file, as otherwise they would not be editable. There are three solutions to this: ### Custom configuration file -You can copy the standard [[Configuration]] file `resources/config.edn` to somewhere outside the jar file, edit it to suit your installation, and set up a single environment variable, `SMEAGOL_CONFIG`, whose value is the path to your new configuration file. +You can copy the standard configuration file `resources/config.edn` to somewhere outside the jar file, edit it to suit your installation, and set up a single environment variable, `SMEAGOL_CONFIG`, whose value is the path to your new configuration file. ### Environment variables Alternatively, you can configure everything through [[Environment Variables]]. @@ -18,13 +23,14 @@ Alternatively, you can configure everything through [[Environment Variables]]. You can have both a configuration file and environment variables. If you do this, the environment variables override the values in the configuration file. ### Necessary content -**NOTE** that `SMEAGOL_CONTENT_DIR` must contain at least the following files: + +**NOTE** that the directory at `SMEAGOL_CONTENT_DIR` must contain at least the following files: 1. `_edit-side-bar.md` - the side-bar that should be displayed when editing pages; 2. `_header.md` - the header to be displayed on all pages; 3. `_side-bar.md` - the side-bar that should be displayed when not editing pages. -Standard versions of these files can be found in the [source repository](https://github.com/journeyman-cc/smeagol/tree/master/resources/public/content). All these files should be in markdown format - see [[Extensible Markup]]. +Standard versions of these files can be found in the [source repository](https://github.com/journeyman-cc/smeagol/tree/master/resources/public/content). You can run the jar file with: @@ -38,8 +44,31 @@ To deploy Smeagol within a servlet container, either download the jar file for t This will create a war file in the `target` directory, named `smeagol-`*VERSION*`-standalone.war`. Deploy this to your servlet container in the normal way; details will depend on your container. Instructions for Tomcat are [here](https://tomcat.apache.org/tomcat-8.0-doc/deployer-howto.html). -The problem with this is that unless the environment variables (see above) were already set up in the environment of the servlet container at the time when the servlet container were launched, Smeagol will run with its built-in defaults. This will run perfectly satisfactorily provided your servlet container is configured to unpack war files, which most are. +The problem with this is that unless the environment variables (see above) were already set up in the environment of the servlet container at the time when the servlet container were launched, Smeagol will run with its built-in defaults. If you want to change the defaults, you would have to edit the `resources/config.edn` file and recompile the war file. + +Smeagol will run as a web-app with the default configuration perfectly satisfactorily. ## Experimental Docker image -You can now run Smeagol as a [Docker](http://www.docker.com) image. Read more about using the [[Docker Image]]. +You can now run Smeagol as a [Docker](http://www.docker.com) image. Read more about [[Using the Docker Image]]. + +To run my Docker image, use + + docker run simonbrooke/smeagol + +Smeagol will run, obviously, on the IP address of your Docker image, on port 8080. To find the IP address, start the image using the command above and then use + + docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q) + +Suppose this prints '10.10.10.10', then the URL to browse to will be http://10.10.10.10:8080/smeagol/ + +This image is _experimental_, but it does seem to work fairly well. What it does **not** yet do, however, is push the git repository to a remote location, so when you tear the Docker image down your edits will be lost. My next objective for this image is for it to have a cammand line parameter being the git address of a repository from which it can initialise the Wiki content, and to which it will periodically push local changes to the Wiki content. + +To build your own Docker image, run: + + lein clean + lein bower install + lein ring uberwar + lein docker build + +This will build a new Docker image locally; you can, obviously, push it to your own Docker repository if you wish. diff --git a/resources/public/content/Environment Variables.md b/resources/public/content/Environment Variables.md index cca8a0b..6f95178 100644 --- a/resources/public/content/Environment Variables.md +++ b/resources/public/content/Environment Variables.md @@ -1,11 +1,23 @@ -Smeagol can be configured entirely with environment variables. The variables are: - -1. `SMEAGOL_CONFIG` (optional but advised) should be the full or relative pathname of a Smeagol [[Configuration]] file; -2. `SMEAGOL_CONTENT_DIR` should be the full or relative pathname of the directory from which Smeagol should serve content (which may initially be empty, but must be writable by the process which runs Smeagol); -3. `SMEAGOL_DEFAULT_LOCALE` which should be a locale specification in the form "en-GB", "fr-FR", or whatever to suit your users; -4. `SMEAGOL_FORMATTERS` should be an [edn](https://github.com/edn-format/edn)-formatted map of formatter directives (this would be pretty hard to do from an environment variable); -5. `SMEAGOL_LOG_LEVEL` which should be one of `TRACE DEBUG INFO WARN ERROR FATAL` -6. `SMEAGOL_PASSWD` should be the full or relative pathname of a Smeagol Passwd file - see [[Security and authentication]]. This file must contain an entry for at least your initial user, and, if you want to administer users through the user interface, must be writable by the process which runs Smeagol. -7. `SMEAGOL_SITE_TITLE` which should be the title you want shown on the header of all pages. - -You can have both a configuration file and environment variables; if you do, the values of the environment variables take precedence over the values in the config file. +## Smeagol-specific environment variables +Smeagol can be configured entirely with environment variables. The variables are: + +1. `SMEAGOL_CONFIG` (optional but advised) should be the full or relative pathname of a Smeagol [[Configuration]] file; +2. `SMEAGOL_CONTENT_DIR` should be the full or relative pathname of the directory from which Smeagol should serve content (which may initially be empty, but must be writable by the process which runs Smeagol); +3. `SMEAGOL_DEFAULT_LOCALE` which should be a locale specification in the form "en-GB", "fr-FR", or whatever to suit your users; +4. `SMEAGOL_FORMATTERS` should be an [edn](https://github.com/edn-format/edn)-formatted map of formatter directives (this would be pretty hard to do from an environment variable); +5. `SMEAGOL_LOG_LEVEL` which should be one of `TRACE DEBUG INFO WARN ERROR FATAL` +6. `SMEAGOL_PASSWD` should be the full or relative pathname of a Smeagol Passwd file - see [[Security and authentication]]. This file must contain an entry for at least your initial user, and, if you want to administer users through the user interface, must be writable by the process which runs Smeagol. +7. `SMEAGOL_SITE_TITLE` which should be the title you want shown on the header of all pages. + +You can have both a configuration file and environment variables; if you do, the values of the environment variables take precedence over the values in the config file. + +## Other environment variables + +If Smeagol is compiled as an executable jar file, the actual web server component is [Ring server](https://github.com/weavejester/ring-server). This recognises the `PORT` environment variable, and, if this is present and its value is a positive integer, will listen on the specified port (otherwise its default is 3000, which is... unusual). + +Smeagol uses the [Timbre](https://github.com/ptaoussanis/timbre) logging library. This recognises the following environment variables: + +1. `TIMBRE_DEFAULT_STACKTRACE_FONTS` Timbre by default colourises stacktrace dumps using ANSI terminal codes. This can be quite useful in a console, but is a real pain in a log file. To turn colourised stacktraces off, set the value of this to an empty string; +2. `TIMBRE_LEVEL` Sets the minimum logging level; but there are two problems with this. The first is that the environment variable is only read at compile time not at run time, and the second is that the syntax is a bit odd, which is why I've implemented `SMEAGOL_LOG_LEVEL` (above); +3. `TIMBRE_NS_WHITELIST` Sets a list of [Clojure namespaces](https://clojure.org/reference/namespaces) from which messages should be logged; however this is only read at compile time so isn't much use in practice; +4. `TIMBRE_NS_BLACKLIST` As above, but sets a list of namespaces from which messages should **not** be logged. \ No newline at end of file diff --git a/src/smeagol/configuration.clj b/src/smeagol/configuration.clj index 9c67d91..f4631f9 100644 --- a/src/smeagol/configuration.clj +++ b/src/smeagol/configuration.clj @@ -1,7 +1,9 @@ (ns ^{:doc "Read and make available configuration." :author "Simon Brooke"} smeagol.configuration - (:require [environ.core :refer [env]] + (:require [clojure.pprint :refer [pprint]] + [clojure.string :as s] + [environ.core :refer [env]] [noir.io :as io] [taoensso.timbre :as timbre])) @@ -54,6 +56,16 @@ vars)) +(defn to-keyword + "Convert this argument into an idiomatic clojure keyword." + [arg] + (if (and arg (not (keyword? arg))) + (keyword + (s/lower-case + (s/replace (str arg) #"[^A-Za-z0-9]+" "-"))) + arg)) + + (defn transform-map "transform this map `m` by applying these `transforms`. Each transforms is expected to comprise a map with the keys :from and :to, whose values @@ -61,14 +73,21 @@ and optionally a key :transform, whose value is a function of one argument to be used to transform the value of that key." [m tuples] + (timbre/debug + "transform-map:\n" + (with-out-str (clojure.pprint/pprint m))) (reduce (fn [m tuple] (if (and (map? tuple) (map? m) (m (:from tuple))) (let [old-val (m (:from tuple)) - t (:transform tuple) - new-val (if t (apply t (list old-val)) old-val)] - (assoc (dissoc m (:from tuple)) (:to tuple) new-val)) + t (:transform tuple)] + (assoc + (dissoc m (:from tuple)) + (:to tuple) + (if-not + (nil? t) + (eval (list t old-val)) old-val))) m)) m tuples)) @@ -78,27 +97,41 @@ "Transforms to use with `transform-map` to convert environment variable names (which need to be specific) into the shorter names used internally" - '( {:from :smeagol-site-title :to :site-title} + '( {:from :smeagol-content-dir :to :content-dir} {:from :smeagol-default-locale :to :default-locale} {:from :smeagol-formatters :to :formatters :transform read-string} - {:from :smeagol-content-dir :to :content-dir} + {:from :smeagol-log-level :to :log-level :transform to-keyword} {:from :smeagol-passwd :to :passwd} - {:from :smeagol-log-level :to :log-level :transform (fn [s] (keyword (lower-case s)))})) + {:from :smeagol-site-title :to :site-title})) -(def config +(defn build-config + [] "The actual configuration, as a map. The idea here is that the config file is read (if it is specified and present), but that individual - values " + values can be overridden by environment variables." (try (let [file-contents (try (read-string (slurp config-file-path)) - (catch Exception _ {}))] - (merge - file-contents - (transform-map - (from-env-vars :smeagol-site-title :smeagol-default-locale) - config-env-transforms))) + (catch Exception _ {})) + config (merge + file-contents + (transform-map + (from-env-vars + :smeagol-content-dir + :smeagol-default-locale + :smeagol-formatters + :smeagol-log-level + :smeagol-passwd + :smeagol-site-title) + config-env-transforms))] + (if (env :dev) + (timbre/debug + "Loaded configuration\n" + (with-out-str (clojure.pprint/pprint config)))) + config) (catch Exception any (timbre/error any "Could not load configuration") {}))) + +(def config (build-config)) diff --git a/src/smeagol/sanity.clj b/src/smeagol/sanity.clj index e7c0503..1e3430e 100644 --- a/src/smeagol/sanity.clj +++ b/src/smeagol/sanity.clj @@ -1,4 +1,5 @@ -(ns ^{:doc "Functions related to sanity checks and error reporting in conditions where the environment may not be sane." +(ns ^{:doc "Functions related to sanity checks and error reporting in conditions + where the environment may not be sane." :author "Simon Brooke"} smeagol.sanity (:import (java.util Locale)) @@ -412,7 +413,7 @@ (timbre/warn "Sanity check completed; " (count (keys result)) " problem(s) found") (sanity-check-report result)) (do - (timbre/info "Sanity check completed; no problem(s) found") + (timbre/info "Sanity check completed; no problems found") nil)))) From 0194ff477f71abf765e884fdc8980f1a770b341c Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Tue, 12 Sep 2017 16:44:54 +0100 Subject: [PATCH 10/12] Version 0.99.11 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 0645d57..2bb78a0 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject smeagol "0.99.11-SNAPSHOT" +(defproject smeagol "0.99.11" :description "A simple Git-backed Wiki inspired by Gollum" :url "https://github.com/simon-brooke/smeagol" :license {:name "GNU General Public License,version 2.0 or (at your option) any later version" From a509cadd82a4c5bab419a29d4acc560d87886dfa Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Tue, 12 Sep 2017 16:58:04 +0100 Subject: [PATCH 11/12] Version 0.99.12-SNAPSHOT --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 2bb78a0..73b870e 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject smeagol "0.99.11" +(defproject smeagol "0.99.12-SNAPSHOT" :description "A simple Git-backed Wiki inspired by Gollum" :url "https://github.com/simon-brooke/smeagol" :license {:name "GNU General Public License,version 2.0 or (at your option) any later version" From 948d718b3d97cf71556b8ff155543b8a68f15211 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 12 Sep 2017 17:02:27 +0100 Subject: [PATCH 12/12] Upversion to 1.0.0 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 73b870e..38c96f5 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject smeagol "0.99.12-SNAPSHOT" +(defproject smeagol "1.0.0" :description "A simple Git-backed Wiki inspired by Gollum" :url "https://github.com/simon-brooke/smeagol" :license {:name "GNU General Public License,version 2.0 or (at your option) any later version"