Skip to content

Commit

Permalink
Adding Dockerfile and goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Lhussiez committed Sep 17, 2018
1 parent 09519cd commit 1ff65f2
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 39 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ _testmain.go
smallblog
pages/
conf.yml
releases
vendor
releases/
dist/
vendor/
coverage.txt
27 changes: 27 additions & 0 deletions .goreleaser.yml
@@ -0,0 +1,27 @@
builds:
- env:
- CGO_ENABLED=0
goos: [linux]
goarch: [amd64, arm, arm64, 386]
goarm: [6, 7]
archive:
wrap_in_directory: true
format: tar.gz
replacements:
386: i386
amd64: x86_64
files:
- examples/**/*
- templates/**/*
- assets/**/*
- pages/**/*
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
37 changes: 37 additions & 0 deletions Dockerfile
@@ -0,0 +1,37 @@
# Build Step
FROM golang:latest AS build

# Prerequisites and vendoring
RUN mkdir -p $GOPATH/src/github.com/Depado/smallblog
ADD . $GOPATH/src/github.com/Depado/smallblog
WORKDIR $GOPATH/src/github.com/Depado/smallblog
RUN go get -u github.com/golang/dep/cmd/dep
RUN dep ensure -vendor-only

# Build
ARG build
ARG version
RUN CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=${version} -X main.Build=${build}" -o /smallblog

# Final Step
FROM alpine

# Base packages
RUN apk update
RUN apk upgrade
RUN apk add ca-certificates && update-ca-certificates
RUN apk add --update tzdata
RUN rm -rf /var/cache/apk/*

# Copy binary from build step
COPY --from=build /smallblog /home/

# Define timezone
ENV TZ=Europe/Paris

# Define the ENTRYPOINT
WORKDIR /home
ENTRYPOINT ./smallblog

# Document that the service listens on port 8080.
EXPOSE 8080
47 changes: 28 additions & 19 deletions Makefile
@@ -1,23 +1,32 @@
version = 1.0.2
.PHONY: all clean test docker latest release

.PHONY: release clean
export CGO_ENABLED=0
export GOOS=linux
export GOARCH=amd64

release:
-mkdir -p releases/smallblog-linux-amd64-${version}/pages
-mkdir -p releases/smallblog-linux-arm-${version}/pages
cp -r assets/ releases/smallblog-linux-amd64-${version}
cp -r assets/ releases/smallblog-linux-arm-${version}
cp -r templates/ releases/smallblog-linux-amd64-${version}
cp -r templates/ releases/smallblog-linux-arm-${version}
cp examples/article.md.example releases/smallblog-linux-amd64-${version}/pages/article.md
cp examples/article.md.example releases/smallblog-linux-arm-${version}/pages/article.md
cp examples/conf.yml.example releases/smallblog-linux-amd64-${version}/conf.yml
cp examples/conf.yml.example releases/smallblog-linux-arm-${version}/conf.yml
go build -o releases/smallblog-linux-amd64-${version}/smallblog
GOARCH=arm go build -o releases/smallblog-linux-arm-${version}/smallblog
cd releases
tar czf smallblog-linux-amd64-${version}.tar.gz smallblog-linux-amd64-${version}
tar czf smallblog-linux-arm-${version}.tar.gz smallblog-linux-arm-${version}
BINARY=smallblog
VERSION=$(shell git describe --abbrev=0 --tags 2> /dev/null || echo "0.1.0")
BUILD=$(shell git rev-parse HEAD 2> /dev/null || echo "undefined")
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.Build=$(BUILD)"

all:
go build -o $(BINARY) $(LDFLAGS)

docker:
docker build \
-t $(BINARY):latest \
-t $(BINARY):$(VERSION) \
--build-arg build=$(BUILD) --build-arg version=$(VERSION) \
-f Dockerfile --no-cache .

latest:
docker build \
-t $(BINARY):latest \
--build-arg build=$(BUILD) --build-arg version=$(VERSION) \
-f Dockerfile --no-cache .

test:
go test ./...

clean:
-rm -r releases/
if [ -f $(BINARY) ] ; then rm $(BINARY) ; fi
12 changes: 0 additions & 12 deletions examples/article.md.example

This file was deleted.

6 changes: 0 additions & 6 deletions examples/conf.yml.example

This file was deleted.

0 comments on commit 1ff65f2

Please sign in to comment.