Add a Dockerfile

This commit is contained in:
Noah 2018-06-07 11:51:44 -07:00
parent f154c55862
commit 107e5dd963
3 changed files with 74 additions and 1 deletions

32
Dockerfile Normal file
View File

@ -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"]

View File

@ -2,7 +2,7 @@ SHELL := /bin/bash
VERSION=$(shell grep -e 'Version' blog.go | head -n 1 | cut -d '"' -f 2) VERSION=$(shell grep -e 'Version' blog.go | head -n 1 | cut -d '"' -f 2)
BUILD=$(shell git describe --always) BUILD=$(shell git describe --always)
CURDIR=$(shell curdir) CURDIR=$(shell pwd)
# Inject the build version (commit hash) into the executable. # Inject the build version (commit hash) into the executable.
LDFLAGS := -ldflags "-X main.Build=$(BUILD)" LDFLAGS := -ldflags "-X main.Build=$(BUILD)"
@ -38,3 +38,13 @@ clean:
.PHONY: hardclean .PHONY: hardclean
hardclean: clean hardclean: clean
rm -rf root/.private 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

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 full-featured web blog (with tags, archive views, etc.) and can serve static
web assets, Go HTML templates and Markdown pages. web assets, Go HTML templates and Markdown pages.
# Features
## Zero Configuration ## Zero Configuration
Blog is designed to be extremely easy to run: just give it a path to your 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 See `blog -h` for command line arguments, for example to make it listen on a
different port number. different port number.
The blog database is kept on disk as JSON files under the document root.
## Dual Template System ## Dual Template System
Whenever a web request is handled by the Blog program, it checks your 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] ./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 ## Recommendation: Redis
It is recommended to use the [Redis](https://redis.io) caching server in It is recommended to use the [Redis](https://redis.io) caching server in