Skip to content

Commit

Permalink
chore: build image using multi-stage builds (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
linki authored and hjacobs committed Jul 18, 2017
1 parent a31e840 commit 8b7d46c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM alpine:3.5
# builder image
FROM golang:1.8 as builder

RUN apk --update --no-cache add ca-certificates
WORKDIR /go/src/github.com/kubernetes-incubator/external-dns
COPY . .
RUN make test
RUN make build

COPY build/linux-amd64/external-dns /external-dns
# final image
FROM registry.opensource.zalan.do/stups/alpine:latest
MAINTAINER Team Teapot @ Zalando SE <team-teapot@zalando.de>

ENTRYPOINT ["/external-dns"]
COPY --from=builder /go/src/github.com/kubernetes-incubator/external-dns/build/external-dns /bin/external-dns

ENTRYPOINT ["/bin/external-dns"]
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ build/$(BINARY): $(SOURCES)
build.push: build.docker
docker push "$(IMAGE):$(VERSION)"

build.docker: build/linux-amd64/$(BINARY)
build.docker:
docker build --rm --tag "$(IMAGE):$(VERSION)" .

build/linux-amd64/$(BINARY): $(SOURCES)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/linux-amd64/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" .

clean:
@rm -rf build
18 changes: 18 additions & 0 deletions delivery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
build_steps:
- 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) stable"
apt-get update
apt-get install -y docker-ce
- desc: Build and push docker image
cmd: |
image=registry-write.opensource.zalan.do/teapot/external-dns:$(git describe --always --dirty --tags)
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

0 comments on commit 8b7d46c

Please sign in to comment.