Skip to content

Commit

Permalink
build image using multi-stage builds (#72)
Browse files Browse the repository at this point in the history
* chore: build image using multi-stage builds

* chore: run tests during image build
  • Loading branch information
linki authored and mikkeloscar committed Jun 20, 2017
1 parent bdce197 commit ce6ce5d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 45 deletions.
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
FROM registry.opensource.zalan.do/stups/alpine:UPSTREAM
MAINTAINER Team Teapot @ Zalando SE <[email protected]>
# builder image
FROM golang:1.8 as builder

RUN go get github.com/Masterminds/glide
WORKDIR /go/src/github.com/zalando-incubator/kube-ingress-aws-controller
COPY . .
RUN glide install --strip-vendor
RUN make test
RUN make build.linux

# add scm-source
ADD scm-source.json /
# final image
FROM registry.opensource.zalan.do/stups/alpine:latest
MAINTAINER Team Teapot @ Zalando SE <[email protected]>

# add binary
ADD build/linux/kube-aws-ingress-controller /
COPY --from=builder /go/src/github.com/zalando-incubator/kube-ingress-aws-controller/build/linux/kube-ingress-aws-controller \
/bin/kube-ingress-aws-controller

ENTRYPOINT ["/kube-aws-ingress-controller"]
ENTRYPOINT ["/bin/kube-ingress-aws-controller"]
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: clean check build.local build.linux build.osx build.docker build.push

BINARY ?= kube-aws-ingress-controller
BINARY ?= kube-ingress-aws-controller
VERSION ?= $(shell git describe --tags --always --dirty)
IMAGE ?= registry-write.opensource.zalan.do/teapot/$(BINARY)
TAG ?= $(VERSION)
Expand Down Expand Up @@ -46,14 +46,8 @@ build/linux/$(BINARY): $(SOURCES)
build/osx/$(BINARY): $(SOURCES)
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/osx/$(BINARY) -ldflags "$(LDFLAGS)" .

$(DOCKERFILE).upstream: $(DOCKERFILE)
sed "s@UPSTREAM@$(shell $(shell head -1 $(DOCKERFILE) | sed -E 's@FROM (.*)/(.*)/(.*):.*@pierone latest \2 \3 --url \1@'))@" $(DOCKERFILE) > $(DOCKERFILE).upstream

build.docker: $(DOCKERFILE).upstream scm-source.json build.linux
docker build --rm -t "$(IMAGE):$(TAG)" -f $(DOCKERFILE).upstream .
build.docker: build.linux
docker build -t "$(IMAGE):$(TAG)" -f $(DOCKERFILE) .

build.push: build.docker
docker push "$(IMAGE):$(TAG)"

scm-source.json: .git
@echo '{"url": "$(GITURL)", "revision": "$(GITHEAD)", "author": "$(USER)", "status": "$(GITSTATUS)"}' > scm-source.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ registry of your choice.
To deploy the ingress controller, use the [example YAML](deploy/ingress-controller.yaml) as the descriptor. You can
customize the image used in the example YAML file.

We provide `registry.opensource.zalan.do/teapot/kube-aws-ingress-controller:latest` as a publicly usable Docker image
We provide `registry.opensource.zalan.do/teapot/kube-ingress-aws-controller:latest` as a publicly usable Docker image
built from this codebase. You can deploy it with 2 easy steps:
- Replace the placeholder for your region inside the example YAML, for ex., `eu-west-1`
- Use kubectl to execute the command `kubectl apply -f deploy/ingress-controller.yaml`
Expand Down
44 changes: 17 additions & 27 deletions delivery.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
build_steps:
- desc: 'Install required build software'
cmd: |
apt-get update
apt-get install -y make git apt-transport-https ca-certificates \
curl software-properties-common python-software-properties
- desc: 'Install go'
cmd: |
add-apt-repository -y ppa:longsleep/golang-backports
apt-get update
apt-get install -y golang-go
- desc: 'Install Docker'
cmd: |
curl -sSL https://get.docker.com/ | sh
- desc: 'Symlink sources into the GOPATH'
cmd: |
export GOPATH=$HOME/go
export PKG_BASE_PATH=$GOPATH/src/github.com/zalando-incubator
mkdir -p $PKG_BASE_PATH
ln -s $(pwd) $PKG_BASE_PATH/kube-ingress-aws-controller
- desc: 'Build & push docker image'
cmd: |
export PATH=$PATH:$HOME/go/bin
IS_PR_BUILD=${CDP_PULL_REQUEST_NUMBER+"true"}
if [[ ${CDP_TARGET_BRANCH} == "master" && ${IS_PR_BUILD} != "true" ]]
then
make build.push
fi
- desc: Install docker
cmd: |
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) edge"
apt-get update
apt-get install -y docker-ce
- desc: Build and push docker image
cmd: |
image=registry-write.opensource.zalan.do/teapot/kube-ingress-aws-controller:${CDP_BUILD_VERSION}
docker build --tag $image .
IS_PR_BUILD=${CDP_PULL_REQUEST_NUMBER+"true"}
if [[ ${CDP_TARGET_BRANCH} == "master" && ${IS_PR_BUILD} != "true" ]]
then
docker push $image
fi
2 changes: 1 addition & 1 deletion deploy/ingress-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: controller
image: registry.opensource.zalan.do/teapot/kube-aws-ingress-controller:latest
image: registry.opensource.zalan.do/teapot/kube-ingress-aws-controller:latest
env:
- name: AWS_REGION
value: $YOUR_REGION

0 comments on commit ce6ce5d

Please sign in to comment.