Skip to content

Commit

Permalink
Simplify and shrink Dockerfile to use alpine
Browse files Browse the repository at this point in the history
Add Makefile to simplify the build process.

Signed-off-by: Byron Ruth <b@devel.io>
  • Loading branch information
bruth committed Apr 13, 2017
1 parent 696d5eb commit 120c2f5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.7-onbuild
FROM alpine:3.5

WORKDIR /
COPY ./dist/linux-amd64/prometheus-sql /

EXPOSE 8080

ENTRYPOINT ["app", "-host", "0.0.0.0"]
ENTRYPOINT ["/prometheus-sql", "-host", "0.0.0.0"]

# Default command assumes the SQL agent is linked.
CMD ["-service", "http://sqlagent:5000"]
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
PROG_NAME := "prometheus-sql"
IMAGE_NAME := "dbhi/prometheus-sql"
CMD_PATH := "."

GIT_SHA := $(shell git log -1 --pretty=format:"%h" .)
GIT_TAG := $(shell git describe --tags --exact-match . 2>/dev/null)
GIT_BRANCH := $(shell git symbolic-ref -q --short HEAD)
GIT_VERSION := $(shell git log -1 --pretty=format:"%h (%ci)" .)

build:
go build -ldflags "-X \"main.buildVersion=$(GIT_VERSION)\"" \
-o $(GOPATH)/bin/$(PROG_NAME) $(CMD_PATH)

dist-build:
mkdir -p dist

gox -output="./dist/{{.OS}}-{{.Arch}}/$(PROG_NAME)" \
-ldflags "-X \"main.buildVersion=$(GIT_VERSION)\"" \
-os "windows linux darwin" \
-arch "amd64" $(CMD_PATH) > /dev/null

dist-zip:
cd dist && zip $(PROG_NAME)-darwin-amd64.zip darwin-amd64/*
cd dist && zip $(PROG_NAME)-linux-amd64.zip linux-amd64/*
cd dist && zip $(PROG_NAME)-windows-amd64.zip windows-amd64/*

dist: dist-build dist-zip

docker:
docker build -t ${IMAGE_NAME}:${GIT_SHA} .
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:${GIT_BRANCH}
if [ -n "${GIT_TAG}" ] ; then \
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:${GIT_TAG} ; \
fi;
if [ "${GIT_BRANCH}" == "master" ]; then \
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:latest ; \
fi;

docker-push:
docker push ${IMAGE_NAME}:${GIT_SHA}
docker push ${IMAGE_NAME}:${GIT_BRANCH}
if [ -n "${GIT_TAG}" ]; then \
docker push ${IMAGE_NAME}:${GIT_TAG} ; \
fi;
if [ "${GIT_BRANCH}" == "master" ]; then \
docker push ${IMAGE_NAME}:latest ; \
fi;

.PHONY: build dist-build dist

0 comments on commit 120c2f5

Please sign in to comment.