aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-05-22 20:46:09 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-05-22 20:51:47 +0100
commite00e2820e7d460b464965422aab284c6d3b56c70 (patch)
treed2ed189f2ddd2ec8f1d177b3451ec089bc9e0a9f
parent7230bf7945ace2fd974b2585065dc9aad95a3ef5 (diff)
Make template directory configurable
-rw-r--r--Dockerfile2
-rw-r--r--README.md7
-rw-r--r--cmd/cashierd/main.go3
-rw-r--r--exampleconfig.json3
-rw-r--r--server/config/config.go1
-rw-r--r--server/config/config_test.go1
-rw-r--r--testdata/config.go3
7 files changed, 17 insertions, 3 deletions
diff --git a/Dockerfile b/Dockerfile
index 944fffd..462af4d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,4 +3,6 @@ FROM golang:1.6
ADD . /go/src/github.com/nsheridan/cashier
RUN go install github.com/nsheridan/cashier/cmd/cashierd
+ONBUILD COPY . /cashier
+WORKDIR /cashier
ENTRYPOINT /go/bin/cashierd
diff --git a/README.md b/README.md
index 512e298..e62df25 100644
--- a/README.md
+++ b/README.md
@@ -53,6 +53,13 @@ go get github.com/cashier/cmd/...
2. Create a signing key with `ssh-keygen` and a [config.json](exampleconfig.json)
3. Run the cashier server with `cashierd` and the cli with `cashier`.
+## Using docker
+1. Create a signing key with `ssh-keygen` and a [config.json](exampleconfig.json)
+2. Run
+```
+docker run -it --rm -p 10000:10000 --name cashier -v $(pwd):/cashier nsheridan/cashier
+```
+
# Configuration
Configuration is divided into three sections: `server`, `auth`, and `ssh`.
diff --git a/cmd/cashierd/main.go b/cmd/cashierd/main.go
index bc460da..e482dde 100644
--- a/cmd/cashierd/main.go
+++ b/cmd/cashierd/main.go
@@ -13,6 +13,7 @@ import (
"log"
"net/http"
"os"
+ "path"
"strings"
"time"
@@ -221,7 +222,7 @@ func main() {
ctx := &appContext{
cookiestore: sessions.NewCookieStore([]byte(config.Server.CookieSecret)),
authprovider: authprovider,
- views: template.Must(template.ParseGlob("templates/*")),
+ views: template.Must(template.ParseGlob(path.Join(config.Server.TemplateDir, "*"))),
sshKeySigner: signer,
}
ctx.cookiestore.Options = &sessions.Options{
diff --git a/exampleconfig.json b/exampleconfig.json
index 683304e..eeb1453 100644
--- a/exampleconfig.json
+++ b/exampleconfig.json
@@ -4,7 +4,8 @@
"tls_key": "server.key",
"tls_cert": "server.crt",
"port": 443,
- "cookie_secret": "supersecret"
+ "cookie_secret": "supersecret",
+ "template_dir": "/go/src/github.com/nsheridan/cashier/templates"
},
"auth": {
"provider": "google",
diff --git a/server/config/config.go b/server/config/config.go
index 7598f0a..8922ff6 100644
--- a/server/config/config.go
+++ b/server/config/config.go
@@ -20,6 +20,7 @@ type Server struct {
TLSCert string `mapstructure:"tls_cert"`
Port int `mapstructure:"port"`
CookieSecret string `mapstructure:"cookie_secret"`
+ TemplateDir string `mapstructure:"template_dir"`
}
// Auth holds the configuration specific to the OAuth provider.
diff --git a/server/config/config_test.go b/server/config/config_test.go
index 6baf76d..e528e7d 100644
--- a/server/config/config_test.go
+++ b/server/config/config_test.go
@@ -22,6 +22,7 @@ func TestServerConfig(t *testing.T) {
a.Equal(server.TLSCert, "server.crt")
a.Equal(server.Port, 443)
a.Equal(server.CookieSecret, "supersecret")
+ a.Equal(server.TemplateDir, "templates")
}
func TestAuthConfig(t *testing.T) {
diff --git a/testdata/config.go b/testdata/config.go
index bb2f511..a64ebd5 100644
--- a/testdata/config.go
+++ b/testdata/config.go
@@ -6,7 +6,8 @@ var ServerConfig = []byte(`{
"tls_key": "server.key",
"tls_cert": "server.crt",
"port": 443,
- "cookie_secret": "supersecret"
+ "cookie_secret": "supersecret",
+ "template_dir": "templates"
}
}`)