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