From f154c55862f395e56a42a8758f75d67435ab9ae7 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Tue, 1 May 2018 18:26:50 +0000 Subject: [PATCH 1/3] Catch spam bots on my contact form --- internal/forms/contact.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/forms/contact.go b/internal/forms/contact.go index 2cebbed..f2d543a 100644 --- a/internal/forms/contact.go +++ b/internal/forms/contact.go @@ -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 } From 107e5dd9638dc441cecee2dafc1701c2042a3bc1 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Thu, 7 Jun 2018 11:51:44 -0700 Subject: [PATCH 2/3] Add a Dockerfile --- Dockerfile | 32 ++++++++++++++++++++++++++++++++ Makefile | 12 +++++++++++- README.md | 31 +++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..db58c95 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# 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 fedora:latest + +RUN dnf -y update +RUN dnf -y install golang make + +WORKDIR /go/src/github.com/kirsle/blog +ADD . /go/src/github.com/kirsle/blog + +ENV GOPATH /go +RUN go get ./... +RUN make build + +EXPOSE 80 +CMD ["/go/src/github.com/kirsle/blog/bin/blog", "-a", ":80", "/data/www"] diff --git a/Makefile b/Makefile index 32b3d09..2af9e36 100644 --- a/Makefile +++ b/Makefile @@ -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 blog diff --git a/README.md b/README.md index 763e283..df1601d 100644 --- a/README.md +++ b/README.md @@ -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,33 @@ 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. + +### 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 From b31eb284f028fea2fb505b060fc38b1f7a3dc0ce Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Tue, 18 Sep 2018 11:21:11 -0700 Subject: [PATCH 3/3] Rebase Dockerfile on golang:1.10 --- Dockerfile | 14 +++++--------- Makefile | 2 +- README.md | 7 +++++++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index db58c95..ca5e224 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,17 +16,13 @@ # # # later... # docker start blog -FROM fedora:latest - -RUN dnf -y update -RUN dnf -y install golang make +FROM golang:1.10 WORKDIR /go/src/github.com/kirsle/blog -ADD . /go/src/github.com/kirsle/blog +COPY . . -ENV GOPATH /go -RUN go get ./... -RUN make build +RUN go get -d -v ./... +RUN go install -v ./... EXPOSE 80 -CMD ["/go/src/github.com/kirsle/blog/bin/blog", "-a", ":80", "/data/www"] +CMD ["blog", "-a", ":80", "/data/www"] diff --git a/Makefile b/Makefile index 2af9e36..b7e015c 100644 --- a/Makefile +++ b/Makefile @@ -47,4 +47,4 @@ docker.build: # `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 blog + docker run --rm --name blog_debug -p 8000:80 -v "$(CURDIR)/user-root:/data/www:z" blog diff --git a/README.md b/README.md index df1601d..32cdf0e 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,13 @@ make run 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