Skip to content
Permalink
Browse files

Adding Dockerfile and goreleaser

  • Loading branch information...
Depado committed Sep 17, 2018
1 parent 09519cd commit 1ff65f29931a6bf5a47fb564d581d3f1b850f523
Showing with 95 additions and 39 deletions.
  1. +3 −2 .gitignore
  2. +27 −0 .goreleaser.yml
  3. +37 −0 Dockerfile
  4. +28 −19 Makefile
  5. +0 −12 examples/article.md.example
  6. +0 −6 examples/conf.yml.example
@@ -27,6 +27,7 @@ _testmain.go
smallblog
pages/
conf.yml
releases
vendor
releases/
dist/
vendor/
coverage.txt
@@ -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:'
@@ -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
@@ -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

This file was deleted.

This file was deleted.

0 comments on commit 1ff65f2

Please sign in to comment.
You can’t perform that action at this time.