Merge branch 'master' into events

This commit is contained in:
Noah 2018-12-15 16:42:56 -08:00
commit bddae00a1e
4 changed files with 83 additions and 1 deletions

28
Dockerfile Normal file
View File

@ -0,0 +1,28 @@
# Dockerfile for the blog.
#
# Building:
#
# docker build -t blog .
#
# Running:
#
# # listen on localhost:8000 and use /home/user/www as the user root
# docker run -p 8000:80 -v /home/user/www:/data/www blog
#
# Running and Backgrounding:
#
# # run it with a name to start with
# docker run -d --name blog -v /home/user/www:/data/www blog
#
# # later...
# docker start blog
FROM golang:1.10
WORKDIR /go/src/github.com/kirsle/blog
COPY . .
RUN go get -d -v ./...
RUN go install -v ./...
EXPOSE 80
CMD ["blog", "-a", ":80", "/data/www"]

View File

@ -2,7 +2,7 @@ SHELL := /bin/bash
VERSION=$(shell grep -e 'Version' blog.go | head -n 1 | cut -d '"' -f 2)
BUILD=$(shell git describe --always)
CURDIR=$(shell curdir)
CURDIR=$(shell pwd)
# Inject the build version (commit hash) into the executable.
LDFLAGS := -ldflags "-X main.Build=$(BUILD)"
@ -38,3 +38,13 @@ clean:
.PHONY: hardclean
hardclean: clean
rm -rf root/.private
# `make docker.build` to build the Docker image
.PHONY: docker.build
docker.build:
docker build -t blog .
# `make docker.run` to run the docker image
.PHONY: docker.run
docker.run:
docker run --rm --name blog_debug -p 8000:80 -v "$(CURDIR)/user-root:/data/www:z" blog

View File

@ -4,6 +4,8 @@ This is a web blog and personal homepage engine written in Go. It includes a
full-featured web blog (with tags, archive views, etc.) and can serve static
web assets, Go HTML templates and Markdown pages.
# Features
## Zero Configuration
Blog is designed to be extremely easy to run: just give it a path to your
@ -16,6 +18,8 @@ blog $HOME/www
See `blog -h` for command line arguments, for example to make it listen on a
different port number.
The blog database is kept on disk as JSON files under the document root.
## Dual Template System
Whenever a web request is handled by the Blog program, it checks your
@ -68,6 +72,40 @@ make run
./go-reload cmd/blog/main.go [options] [/path/to/document/root]
```
## Docker
This app includes a Dockerfile. Type `make docker.build` to build the
Docker image.
The Docker container uses the user document root at `/data/www`
```bash
docker build -t blog .
docker run --rm --name blog_debug -p 8000:80 -v $(CURDIR)/user-root:/data/www blog
```
### Quick Start
```bash
make docker.build
make docker.run
```
### Docker Image
* Exposes port 80 for the web server
* User document root is mounted at `/data/www`
So to run the Docker image and have it listen on `localhost:8000` on the
host and bind the user document root to `/home/user/www`:
```bash
docker run -p 8000:80 -v /home/user/www:/data/www blog
```
You may also run `make docker.run` to run the Docker image on port 8000 using
the `./user-root` directory
## Recommendation: Redis
It is recommended to use the [Redis](https://redis.io) caching server in

View File

@ -38,5 +38,11 @@ func (c Contact) Validate() error {
if len(c.Message) == 0 {
return errors.New("message is required")
}
// Spam bot traps.
if c.Trap1 != "" || c.Trap2 != "http://" {
return errors.New("message can't be delivered")
}
return nil
}