Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-brooke committed Sep 12, 2017
2 parents 835dec0 + 948d718 commit 1f2bb0b
Show file tree
Hide file tree
Showing 17 changed files with 414 additions and 133 deletions.
30 changes: 28 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
FROM tomcat:alpine
COPY target/smeagol-*-standalone.war $CATALINA_HOME/webapps/smeagol.war
FROM alpine:3.6

MAINTAINER Simon Brooke <[email protected]>

ENV JAVA_HOME=/usr/lib/jvm/default-jvm

RUN apk add --no-cache openjdk8 && \
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/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

6 changes: 2 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject smeagol "1.0.0-rc3"
(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"
Expand All @@ -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"]
Expand Down Expand Up @@ -64,7 +62,7 @@
;; ["vcs" "tag"] -- not working, problems with secret key
["clean"]
["bower" "install"]
["ring" "uberwar"]
["ring" "uberjar"]
["docker" "build"]
["docker" "push"]
["change" "version" "leiningen.release/bump-version"]
Expand Down
16 changes: 12 additions & 4 deletions resources/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +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
:default-locale "en-GB" ;; default language used for messages
:formatters {"vega" smeagol.formatting/process-vega
:content-dir "resources/public/content"
;; where content is served from.
: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}
: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
}
2 changes: 1 addition & 1 deletion resources/passwd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{:admin {:admin true, :email "[email protected]", :password "admin"}, :jenny {:email "[email protected]", :admin false, :password "$s0$f0801$1uniQfftB37G5e5GklJANQ==$kQ0+/YcCuaz2x5iYjwhNlDlnWX/exE/8pSC+R4C0WvQ="}}
{:admin {:admin true, :email "[email protected]", :password "admin"}, :simon {:email "[email protected]", :admin true, :password "$s0$f0801$sqhbxtzK6nx9RnVUhwtQlg==$dMIUbof8esjsGyiB+zb3gMH21L/WSCR+wD3vIag4EVc="}}
37 changes: 25 additions & 12 deletions resources/public/content/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]].
28 changes: 21 additions & 7 deletions resources/public/content/Deploying Smeagol.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -6,19 +11,26 @@ 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:

### 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.

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.
### Environment variables
Alternatively, you can configure everything through [[Environment Variables]].

**NOTE** that `SMEAGOL_CONTENT_DIR` must contain at least the following files:
### 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 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:

Expand All @@ -32,7 +44,9 @@ 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

Expand Down
55 changes: 55 additions & 0 deletions resources/public/content/Docker Image.md
Original file line number Diff line number Diff line change
@@ -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. 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:
```
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.
23 changes: 23 additions & 0 deletions resources/public/content/Environment Variables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## 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.
8 changes: 8 additions & 0 deletions resources/public/content/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
}
Expand Down
Binary file removed resources/public/uploads/water.png
Binary file not shown.
11 changes: 6 additions & 5 deletions src/smeagol/authenticate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -37,8 +38,8 @@
;; the relative path to the password file.
(def password-file-path
(or
(env :smeagol-passwd)
(str (clojure.java.io/resource "passwd"))))
(:passwd config)
(str (io/resource-path) "../passwd")))


(defn- get-users
Expand Down Expand Up @@ -112,7 +113,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))))
Expand Down Expand Up @@ -162,7 +163,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)))))
Expand All @@ -179,7 +180,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))))
Loading

0 comments on commit 1f2bb0b

Please sign in to comment.