Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
use multistage build Dockerfile (#142)
Browse files Browse the repository at this point in the history
* use multistage build dockerfile
* add .git to dockeringore
* simplify makefile
  • Loading branch information
roffe authored and pingles committed Aug 13, 2018
1 parent ffc65d8 commit e7e82a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
bin
docs
ci
deploy
5 changes: 0 additions & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ pipeline:
commands:
- make bench

build:
image: golang:1.10
commands:
- make build-linux

docker:
when:
event: push
Expand Down
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM alpine:3.8
FROM golang:1.10-alpine3.8 as build
RUN apk add --no-cache make
WORKDIR /go/src/github.com/uswitch/kiam
ADD . .
RUN make

FROM alpine:3.8
RUN apk --no-cache add iptables

COPY bin/kiam-linux-amd64 /kiam

COPY --from=build /go/src/github.com/uswitch/kiam/bin/kiam-linux-amd64 /kiam
CMD []
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
NAME?=kiam
ARCH=amd64
BIN = bin/kiam
BIN_LINUX = $(BIN)-linux-$(ARCH)
BIN_DARWIN = $(BIN)-darwin-$(ARCH)

GIT_BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
IMG_NAMESPACE?=quay.io/uswitch
IMG_TAG?=$(GIT_BRANCH)
REGISTRY?=$(IMG_NAMESPACE)/$(NAME)
SOURCES := $(shell find . -iname '*.go') proto/service.pb.go

.PHONY: test clean all coverage

all: proto/service.pb.go build-darwin build-linux
all: build-linux

build-darwin: $(SOURCES)
GOARCH=$(ARCH) GOOS=darwin go build -o $(BIN_DARWIN) cmd/kiam/*.go
Expand All @@ -31,8 +35,8 @@ coverage: $(SOURCES) coverage.txt
bench: $(SOURCES)
go test -run=XX -bench=. github.com/uswitch/kiam/pkg/...

docker: Dockerfile $(BIN_LINUX)
docker image build -t quay.io/uswitch/kiam:devel .
docker: Dockerfile
docker image build -t "$(REGISTRY):$(IMG_TAG)" .

clean:
rm -rf bin/

0 comments on commit e7e82a5

Please sign in to comment.