From 1455d67152ca9708743d71e8c2544180fcbb20c2 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Wed, 14 Mar 2018 17:24:07 -0400 Subject: [PATCH] Use a custom builder image Use a custom builder image to do all of Ark's builds. This image now contains k8s.io/code-generator for code generation. Enable docker in travis to use the builder image. Signed-off-by: Andy Goldstein --- .travis.yml | 5 +++++ Makefile | 22 +++++++++------------- hack/build-image/Dockerfile | 21 +++++++++++++++++++++ hack/update-generated-crd-code.sh | 23 ++++++++++++++++++----- 4 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 hack/build-image/Dockerfile diff --git a/.travis.yml b/.travis.yml index 987100cbc..2de75b42d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,9 @@ language: go go: - 1.9.x +sudo: required + +services: + - docker + script: make ci diff --git a/Makefile b/Makefile index 2cea8a9b9..7e292b4a5 100644 --- a/Makefile +++ b/Makefile @@ -55,8 +55,6 @@ endif IMAGE := $(REGISTRY)/$(BIN) -BUILD_IMAGE ?= gcr.io/heptio-images/golang:1.9-alpine3.6 - # If you want to build all binaries, see the 'all-build' rule. # If you want to build all containers, see the 'all-container' rule. # If you want to build AND push all containers, see the 'all-push' rule. @@ -92,20 +90,21 @@ _output/bin/$(GOOS)/$(GOARCH)/$(BIN): build-dirs TTY := $(shell tty -s && echo "-t") +BUILDER_IMAGE := ark-builder + # Example: make shell CMD="date > datefile" -shell: build-dirs +shell: build-dirs build-image @docker run \ -i $(TTY) \ --rm \ -u $$(id -u):$$(id -g) \ -v "$$(pwd)/.go/pkg:/go/pkg" \ - -v "$$(pwd)/.go/src:/go/src" \ -v "$$(pwd)/.go/std:/go/std" \ -v "$$(pwd):/go/src/$(PKG)" \ -v "$$(pwd)/_output/bin:/output" \ -v "$$(pwd)/.go/std/$(GOOS)/$(GOARCH):/usr/local/go/pkg/$(GOOS)_$(GOARCH)_static" \ -w /go/src/$(PKG) \ - $(BUILD_IMAGE) \ + $(BUILDER_IMAGE) \ /bin/sh $(CMD) DOTFILE_IMAGE = $(subst :,_,$(subst /,_,$(IMAGE))-$(VERSION)) @@ -173,15 +172,12 @@ build-dirs: @mkdir -p _output/bin/$(GOOS)/$(GOARCH) @mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(GOOS)/$(GOARCH) -clean: container-clean bin-clean +build-image: + cd hack/build-image && docker build -t $(BUILDER_IMAGE) . -container-clean: +clean: rm -rf .container-* _output/.dockerfile-* .push-* - -bin-clean: rm -rf .go _output + docker rmi $(BUILDER_IMAGE) -ci: - hack/verify-all.sh - hack/test.sh $(SRC_DIRS) - GOOS=$(GOOS) GOARCH=$(GOARCH) VERSION=$(VERSION) PKG=$(PKG) BIN=$(BIN) ./hack/build.sh +ci: build verify test diff --git a/hack/build-image/Dockerfile b/hack/build-image/Dockerfile new file mode 100644 index 000000000..0b2ca257f --- /dev/null +++ b/hack/build-image/Dockerfile @@ -0,0 +1,21 @@ +# Copyright 2018 the Heptio Ark contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM gcr.io/heptio-images/golang:1.9-alpine3.6 + +RUN mkdir -p /go/src/k8s.io && \ + cd /go/src/k8s.io && \ + git clone -b kubernetes-1.9.0 https://github.com/kubernetes/code-generator && \ + git clone -b kubernetes-1.9.0 https://github.com/kubernetes/apimachinery && \ + echo chmod -R a+w /go diff --git a/hack/update-generated-crd-code.sh b/hack/update-generated-crd-code.sh index 14927ec4a..ad9ddc4ae 100755 --- a/hack/update-generated-crd-code.sh +++ b/hack/update-generated-crd-code.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash # # Copyright 2017 the Heptio Ark contributors. # @@ -14,13 +14,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -HACK_DIR=$(dirname "${BASH_SOURCE}") -REPO_ROOT=${HACK_DIR}/.. +set -o errexit +set -o nounset +set -o pipefail +set -o xtrace -${REPO_ROOT}/vendor/k8s.io/code-generator/generate-groups.sh \ +if [[ -z "${GOPATH}" ]]; then + GOPATH=~/go +fi + +if [[ ! -d "${GOPATH}/src/k8s.io/code-generator" ]]; then + echo "k8s.io/code-generator missing from GOPATH" + exit 1 +fi + +cd ${GOPATH}/src/k8s.io/code-generator + +./generate-groups.sh \ all \ github.com/heptio/ark/pkg/generated \ github.com/heptio/ark/pkg/apis \ ark:v1 \ - --go-header-file hack/boilerplate.go.txt \ + --go-header-file ${GOPATH}/src/github.com/heptio/ark/hack/boilerplate.go.txt \ $@