From 6c727998ec89b19cecf708ca4290a574a10ea557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20K=C5=82obuszewski?= Date: Wed, 21 Jun 2017 15:26:16 +0200 Subject: [PATCH] Build pod_nanny in a container. --- .gitignore | 4 ++++ addon-resizer/.gitignore | 1 + addon-resizer/Dockerfile | 2 +- addon-resizer/Makefile | 47 ++++++++++++++++++++++++++----------- builder/Dockerfile | 2 +- cluster-autoscaler/Makefile | 4 ++-- 6 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 addon-resizer/.gitignore diff --git a/.gitignore b/.gitignore index f7ea4d25dc53..751f9f210137 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,10 @@ .project .settings/** +# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA +.idea/ +*.iml + # Emacs save files *~ \#*\# diff --git a/addon-resizer/.gitignore b/addon-resizer/.gitignore new file mode 100644 index 000000000000..d42e8d7d8239 --- /dev/null +++ b/addon-resizer/.gitignore @@ -0,0 +1 @@ +pod_nanny diff --git a/addon-resizer/Dockerfile b/addon-resizer/Dockerfile index 0ed2b340ccac..b9c9f4c9f15d 100644 --- a/addon-resizer/Dockerfile +++ b/addon-resizer/Dockerfile @@ -15,6 +15,6 @@ FROM busybox MAINTAINER Quintin Lee "qlee@google.com" -ADD build/pod_nanny pod_nanny +ADD pod_nanny pod_nanny CMD ./pod_nanny diff --git a/addon-resizer/Makefile b/addon-resizer/Makefile index 2d98591ebd12..7fc8542aaa85 100644 --- a/addon-resizer/Makefile +++ b/addon-resizer/Makefile @@ -14,26 +14,27 @@ # Procedure for change: # 1. Bump the tag number. -# 2. Create an image for the kubernetes user on Dockerhub and push there: make build push +# 2. Create an image for the kubernetes user on Dockerhub and push there: make dev-release # 3. Temporarily adjust any config files etc. that reference gcr.io/google_containers/addon-resizer:$(TAG) # to use kubernetes/addon-resizer:$(TAG) instead. # 4. Test etc. # 5. Issue PR. -# 6. When PR is approved make the gcr.io version of the image: make build push -# 7. Revert the references to kubernetes/addon-resizer:$(TAG) to gcr.io/google_containers/addon-resizer:$(TAG) +# 6. When PR is approved make the gcr.io version of the image (Change REGISTRY variable below first): make release +# 7. Revert the references to kubernetes/addon-resizer:$(TAG) to gcr.io/google_containers/addon-resizer:$(TAG) -OUT_DIR = build -PACKAGE = k8s.io/contrib/addon-resizer -PREFIX = gcr.io/google_containers -TAG = 2.0 +all: build -# Rules for building the real image for deployment to gcr.io +PACKAGE = k8s.io/autoscaler/addon-resizer +REGISTRY = kubernetes +# Uncomment for release +# REGISTRY = gcr.io/google_containers +TAG = 2.0 deps: go get -u github.com/tools/godep compile: nanny/ deps - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -o $(OUT_DIR)/pod_nanny nanny/main/pod_nanny.go + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -o pod_nanny nanny/main/pod_nanny.go test: nanny/ godep go test ${PACKAGE}/nanny -v @@ -41,12 +42,30 @@ test: nanny/ go: compile test clean: - rm -rf build + rm -rf pod_nanny build: go - docker build --pull -t ${PREFIX}/addon-resizer:$(TAG) . -docker: build +dev-release: build execute-release + echo "Release ${TAG} completed" + +# Rules for building the real image for deployment to gcr.io + +execute-release: +ifndef REGISTRY + ERR = $(error REGISTRY is undefined) + $(ERR) +endif + docker build --pull -t ${REGISTRY}/addon-resizer:${TAG} . + gcloud docker -- push ${REGISTRY}/addon-resizer:${TAG} + +docker-builder: + docker build -t autoscaling-builder ../builder + +build-in-docker: clean docker-builder + docker run -v `pwd`:/gopath/src/k8s.io/autoscaler/addon-resizer/ autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/addon-resizer && make' + +release: build-in-docker execute-release + echo "Full in-docker release ${TAG} completed" + -push: docker - gcloud docker -- push ${PREFIX}/addon-resizer:$(TAG) diff --git a/builder/Dockerfile b/builder/Dockerfile index b3d15f233ed5..22dbbcf5ead8 100644 --- a/builder/Dockerfile +++ b/builder/Dockerfile @@ -15,7 +15,7 @@ FROM gcr.io/google-containers/ubuntu-slim:0.8 MAINTAINER Marcin Wielgus "mwielgus@google.com" -RUN apt-get update && apt-get install --yes git wget make\ +RUN apt-get update && apt-get install --yes git wget make gcc \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* RUN wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz \ diff --git a/cluster-autoscaler/Makefile b/cluster-autoscaler/Makefile index f9e6ebe46336..c4d403866aab 100644 --- a/cluster-autoscaler/Makefile +++ b/cluster-autoscaler/Makefile @@ -34,10 +34,10 @@ format: test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -s -w {} + | tee /dev/stderr)" docker-builder: - docker build -t autoscalig-builder ../builder + docker build -t autoscaling-builder ../builder build-in-docker: clean docker-builder - docker run -v `pwd`:/gopath/src/k8s.io/autoscaler/cluster-autoscaler/ autoscalig-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/cluster-autoscaler && make' + docker run -v `pwd`:/gopath/src/k8s.io/autoscaler/cluster-autoscaler/ autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/cluster-autoscaler && make' release: build-in-docker execute-release echo "Full in-docker release ${TAG} completed"