Skip to content

Commit

Permalink
feat(container): make container builds faster
Browse files Browse the repository at this point in the history
  • Loading branch information
ecordell committed Nov 7, 2018
1 parent bb0313a commit 57c139d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git/objects
./bin/*
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

WORKDIR /go/src/github.com/operator-framework/operator-lifecycle-manager

# copy just enough of the git repo to parse HEAD, used to record version in OLM binaries
COPY .git/HEAD .git/HEAD
COPY .git/refs/heads/. .git/refs/heads
RUN mkdir -p .git/objects

COPY Makefile Makefile
COPY .git .git
COPY OLM_VERSION OLM_VERSION
COPY pkg pkg
COPY vendor vendor
Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ IMAGE_REPO := quay.io/coreos/olm
IMAGE_TAG ?= "dev"
KUBE_DEPS := api apiextensions-apiserver apimachinery code-generator kube-aggregator kubernetes
KUBE_RELEASE := release-1.11
MOD_FLAGS := $(shell (go version | grep -q 1.11) && echo -mod=vendor)

.PHONY: build test run clean vendor schema-check \
vendor-update coverage coverage-html e2e .FORCE
Expand All @@ -21,13 +22,13 @@ all: test build
test: clean cover.out

unit:
go test -mod=vendor -v -race ./pkg/...
go test $(MOD_FLAGS) -v -race ./pkg/...

schema-check:
go run -mod=vendor ./cmd/validator/main.go ./deploy/chart/catalog_resources
go run $(MOD_FLAGS) ./cmd/validator/main.go ./deploy/chart/catalog_resources

cover.out: schema-check
go test -mod=vendor -v -race -coverprofile=cover.out -covermode=atomic \
go test $(MOD_FLAGS) -v -race -coverprofile=cover.out -covermode=atomic \
-coverpkg ./pkg/controller/... ./pkg/...

coverage: cover.out
Expand All @@ -43,10 +44,9 @@ build: clean $(CMDS)
build-coverage: build_cmd=test -c -covermode=count -coverpkg ./pkg/controller/...
build-coverage: clean $(CMDS)

$(CMDS): mod_flags=$(shell [ -f go.mod ] && echo -mod=vendor)
$(CMDS): version_flags=-ldflags "-w -X $(PKG)/pkg/version.GitCommit=`git rev-parse --short HEAD` -X $(PKG)/pkg/version.OLMVersion=`cat OLM_VERSION`"
$(CMDS):
CGO_ENABLED=0 go $(build_cmd) $(mod_flags) $(version_flags) -o $@ $(PKG)/cmd/$(shell basename $@);
CGO_ENABLED=0 go $(build_cmd) $(MOD_FLAGS) $(version_flags) -o $@ $(PKG)/cmd/$(shell basename $@);

run-local:
. ./scripts/build_local.sh
Expand Down Expand Up @@ -89,7 +89,7 @@ vendor: $(KUBE_DEPS)
go mod tidy
go mod vendor

container: build
container:
docker build -t $(IMAGE_REPO):$(IMAGE_TAG) .

clean:
Expand All @@ -109,6 +109,9 @@ gen-ci: $(CI)
# Must be run in gopath: https://github.com/kubernetes/kubernetes/issues/67566
# use container-codegen
codegen:
cp scripts/generate_groups.sh vendor/k8s.io/code-generator/generate_groups.sh
mkdir -p vendor/k8s.io/code-generator/hack
cp boilerplate.go.txt vendor/k8s.io/code-generator/hack/boilerplate.go.txt
go run vendor/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go --logtostderr -i ./vendor/k8s.io/apimachinery/pkg/runtime,./vendor/k8s.io/apimachinery/pkg/apis/meta/v1,./vendor/k8s.io/apimachinery/pkg/version,./pkg/package-server/apis/packagemanifest/v1alpha1 -p $(PKG)/pkg/package-server/apis/openapi -O zz_generated.openapi -h boilerplate.go.txt -r /dev/null
$(CODEGEN) all $(PKG)/pkg/api/client $(PKG)/pkg/api/apis "operators:v1alpha1,v1alpha2"
$(CODEGEN) all $(PKG)/pkg/package-server/client $(PKG)/pkg/package-server/apis "packagemanifest:v1alpha1"
Expand All @@ -127,7 +130,7 @@ verify-codegen: codegen
git diff --exit-code

verify-catalog: schema-check
go test -mod=vendor -v ./test/schema/catalog_versions_test.go
go test $(MOD_FLAGS) -v ./test/schema/catalog_versions_test.go

generate-mock-client:
go generate ./$(PKG_DIR)/...
Expand Down
5 changes: 4 additions & 1 deletion e2e.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ LABEL stage=builder
WORKDIR /go/src/github.com/operator-framework/operator-lifecycle-manager
RUN curl -L https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -o /bin/jq
RUN chmod +x /bin/jq
# copy just enough of the git repo to parse HEAD, used to record version in OLM binaries
COPY .git/HEAD .git/HEAD
COPY .git/refs/heads/. .git/refs/heads
RUN mkdir -p .git/objects
COPY Makefile Makefile
COPY .git .git
COPY OLM_VERSION OLM_VERSION
COPY pkg pkg
COPY vendor vendor
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ require (
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92 // indirect
k8s.io/kube-aggregator v0.0.0-20180905000155-efa32eb095fe
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd
k8s.io/kubernetes v1.11.5-beta.0.0.20181106200134-5bfe2967a4cd
k8s.io/kubernetes v1.11.5-beta.0.0.20181107171428-941010e531b7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,5 @@ k8s.io/kube-aggregator v0.0.0-20180905000155-efa32eb095fe h1:LM48rywzVEPRg+Os2oU
k8s.io/kube-aggregator v0.0.0-20180905000155-efa32eb095fe/go.mod h1:8sbzT4QQKDEmSCIbfqjV0sd97GpUT7A4W626sBiYJmU=
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd h1:ggv/Vfza0i5xuhUZyYyxcc25AmQvHY8Zi1C2m8WgBvA=
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
k8s.io/kubernetes v1.11.5-beta.0.0.20181106200134-5bfe2967a4cd h1:G3Mi/dLCTnSgA4CLlsbMKbUwX82yDKQ2lH2qpupT44U=
k8s.io/kubernetes v1.11.5-beta.0.0.20181106200134-5bfe2967a4cd/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
k8s.io/kubernetes v1.11.5-beta.0.0.20181107171428-941010e531b7 h1:Mw61CrhX1Xb/A4JAe0HI3TMy0q2MFAMGUwjcz/2n/6A=
k8s.io/kubernetes v1.11.5-beta.0.0.20181107171428-941010e531b7/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,16 @@ k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme
k8s.io/kube-aggregator/pkg/client/listers/apiregistration/v1beta1
# k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd
k8s.io/kube-openapi/cmd/openapi-gen
k8s.io/kube-openapi/pkg/common
k8s.io/kube-openapi/pkg/generators
k8s.io/kube-openapi/cmd/openapi-gen/args
k8s.io/kube-openapi/pkg/common
k8s.io/kube-openapi/pkg/util/proto
k8s.io/kube-openapi/pkg/util
k8s.io/kube-openapi/pkg/generators/rules
k8s.io/kube-openapi/pkg/builder
k8s.io/kube-openapi/pkg/handler
k8s.io/kube-openapi/pkg/util/sets
# k8s.io/kubernetes v1.11.5-beta.0.0.20181106200134-5bfe2967a4cd
# k8s.io/kubernetes v1.11.5-beta.0.0.20181107171428-941010e531b7
k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac
k8s.io/kubernetes/pkg/apis/rbac/v1
k8s.io/kubernetes/pkg/registry/rbac/validation
Expand Down

0 comments on commit 57c139d

Please sign in to comment.