Skip to content

Commit 5da8e16

Browse files
committed
Improve Makefile rules
1. Use file targets instead of .PHONY ones when possible. 2. Avoid generating files if they are up to date 3. Use proper prerequisites
1 parent 9d12a50 commit 5da8e16

File tree

6 files changed

+61
-48
lines changed

6 files changed

+61
-48
lines changed

.circleci/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ jobs:
55
machine:
66
image: ubuntu-1604:201903-01
77
environment:
8+
GO_VERSION: 1.12.6
89
GOCACHE: /home/circleci/.cache/go-build/
910
GOPATH: /home/circleci/go
1011
steps:
@@ -14,6 +15,15 @@ jobs:
1415
- go-cache-{{ .Branch }}-{{ .Revision }}
1516
- go-cache-{{ .Branch }}-
1617
- go-cache-
18+
- run:
19+
name: Install Golang (needed for dependency calculation)
20+
command: |
21+
curl -OL https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz
22+
tar -xf go${GO_VERSION}.linux-amd64.tar.gz
23+
sudo rm -rf /usr/local/go
24+
sudo mv go /usr/local
25+
mkdir -p "$HOME/go/bin"
26+
go version
1727
- run: mkdir -p ./test-results/ginkgo
1828
- run: make eksctl-image
1929
- run: sudo chown -R circleci.circleci /home/circleci/.cache/go-build/ /home/circleci/go/pkg/mod/

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Make sure you can run the tests and build the binary.
6464
```bash
6565
make install-build-deps
6666
make test
67-
make build
67+
make eksctl
6868
```
6969

7070
> NOTE: Windows users should install Docker for Windows and run `make eksctl-image` to build their code.

Makefile

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
SHELL=bash -x
12
built_at := $(shell date +%s)
23
git_commit := $(shell git describe --dirty --always)
34

@@ -20,8 +21,10 @@ install-build-deps: ## Install dependencies (packages and tools)
2021

2122
##@ Build
2223

23-
.PHONY: build
24-
build: generate-bindata-assets generate-kubernetes-types ## Build eksctl
24+
gofiles = $(shell $1 | xargs go list -f '{{if not .Standard}}{{ $$dep := . }}{{range .GoFiles}}{{$$dep.Dir}}/{{.}} {{end}}{{end}}')
25+
godeps = $(call gofiles,go list -f '{{join .Deps "\n"}}' $1)
26+
27+
eksctl: $(call godeps,./cmd/...) ## Build main binary
2528
CGO_ENABLED=0 time go build -v -ldflags "-X $(version_pkg).gitCommit=$(git_commit) -X $(version_pkg).builtAt=$(built_at)" ./cmd/eksctl
2629

2730
##@ Testing & CI
@@ -50,11 +53,11 @@ lint: ## Run linter over the codebase
5053
time "$(GOBIN)/gometalinter" ./pkg/... ./cmd/... ./integration/...
5154

5255
.PHONY: test
53-
test: ## Run unit test (and re-generate code under test)
56+
test:
5457
$(MAKE) lint
55-
$(MAKE) generate-aws-mocks-test generate-bindata-assets-test generate-kubernetes-types-test
58+
$(MAKE) check-generated-sources-up-to-date
5659
$(MAKE) unit-test
57-
$(MAKE) build-integration-test
60+
$(MAKE) eksctl-integration-test
5861

5962
.PHONY: unit-test
6063
unit-test: ## Run unit test only
@@ -64,14 +67,12 @@ unit-test: ## Run unit test only
6467
unit-test-race: ## Run unit test with race detection
6568
CGO_ENABLED=1 time go test -race ./pkg/... ./cmd/... $(UNIT_TEST_ARGS)
6669

67-
.PHONY: build-integration-test
68-
build-integration-test: ## Build integration test binary
69-
time go test -tags integration ./integration/... -c -o ./eksctl-integration-test
70+
eksctl-integration-test: $(call gofiles,go list -f '{{join .Deps "\n"}}' `go list -tags integration -f '{{join .XTestImports " "}}' ./integration/...`) ## Build integration test binary
71+
time go test -tags integration ./integration/... -c -o $@
7072

7173
.PHONY: integration-test
72-
integration-test: build build-integration-test ## Run the integration tests (with cluster creation and cleanup)
73-
cd integration; ../eksctl-integration-test -test.timeout 60m \
74-
$(INTEGRATION_TEST_ARGS)
74+
integration-test: eksctl eksctl-integration-test ## Run the integration tests (with cluster creation and cleanup)
75+
cd integration; ../eksctl-integration-test -test.timeout 60m $(INTEGRATION_TEST_ARGS)
7576

7677
.PHONY: integration-test-container
7778
integration-test-container: eksctl-image ## Run the integration tests inside a Docker container
@@ -91,7 +92,7 @@ integration-test-container-pre-built: ## Run the integration tests inside a Dock
9192

9293
TEST_CLUSTER ?= integration-test-dev
9394
.PHONY: integration-test-dev
94-
integration-test-dev: build build-integration-test ## Run the integration tests without cluster teardown. For use when developing integration tests.
95+
integration-test-dev: eksctl eksctl-integration-test ## Run the integration tests without cluster teardown. For use when developing integration tests.
9596
./eksctl utils write-kubeconfig \
9697
--auto-kubeconfig \
9798
--name=$(TEST_CLUSTER)
@@ -111,54 +112,55 @@ delete-integration-test-dev-cluster: build ## Delete the test cluster for use wh
111112

112113
##@ Code Generation
113114

114-
.PHONY: generate-bindata-assets
115-
generate-bindata-assets: ## Generate bindata assets (node bootstrap config files & add-on manifests)
116-
chmod g-w ./pkg/nodebootstrap/assets/*
117-
env GOBIN=$(GOBIN) time go generate ./pkg/nodebootstrap ./pkg/addons/default
115+
AWS_SDK_MOCKS=$(wildcard pkg/eks/mocks/*API.go)
116+
117+
GENERATED_FILES=pkg/addons/default/assets.go \
118+
pkg/nodebootstrap/assets.go \
119+
pkg/apis/eksctl.io/v1alpha5/zz_generated.deepcopy.go \
120+
pkg/ami/static_resolver_ami.go \
121+
site/content/usage/20-schema.md \
122+
$(AWS_SDK_MOCKS)
123+
124+
.PHONY: regenerate-sources
125+
# TODO: generate-ami is broken (see https://github.com/weaveworks/eksctl/issues/949 ), include it when fixed
126+
regenerate-sources: $(GENERATED_FILES) # generate-ami ## Re-generate all the automatically-generated source files
127+
128+
.PHONY: check-generated-files-up-to-date
129+
check-generated-sources-up-to-date: regenerate-sources
130+
git diff --quiet -- $(GENERATED_FILES) || (git --no-pager diff $(GENERATED_FILES); exit 1)
118131

119-
.PHONY: generate-bindata-assets-test
120-
generate-bindata-assets-test: generate-bindata-assets ## Test if generated bindata assets are checked-in
121-
git diff --exit-code ./pkg/nodebootstrap/assets.go > /dev/null || (git --no-pager diff ./pkg/nodebootstrap/assets.go; exit 1)
122-
git diff --exit-code ./pkg/addons/default/assets.go > /dev/null || (git --no-pager diff ./pkg/addons/default/assets.go; exit 1)
132+
pkg/addons/default/assets.go: $(wildcard pkg/addons/default/assets/*)
133+
env GOBIN=$(GOBIN) time go generate ./$(@D)
134+
135+
pkg /nodebootstrap/assets.go: $(wildcard pkg/nodebootstrap/assets/*)
136+
chmod g-w $^
137+
env GOBIN=$(GOBIN) time go generate ./$(@D)
123138

124139
.license-header: LICENSE
125140
@# generate-groups.sh can't find the lincense header when using Go modules, so we provide one
126141
printf "/*\n%s\n*/\n" "$$(cat LICENSE)" > $@
127142

128-
.PHONY: generate-kubernetes-types
129-
generate-kubernetes-types: .license-header ## Generate Kubernetes API helpers
143+
pkg/apis/eksctl.io/v1alpha5/zz_generated.deepcopy.go: $(call godeps,./pkg/apis/...) .license-header ## Generate Kubernetes API helpers
130144
time go mod download k8s.io/code-generator # make sure the code-generator is present
131145
time env GOPATH="$$(go env GOPATH)" bash "$$(go env GOPATH)/pkg/mod/k8s.io/[email protected]/generate-groups.sh" \
132-
deepcopy,defaulter pkg/apis ./pkg/apis eksctl.io:v1alpha5 --go-header-file .license-header --output-base="$${PWD}" \
146+
deepcopy,defaulter _ ./pkg/apis eksctl.io:v1alpha5 --go-header-file .license-header --output-base="$${PWD}" \
133147
|| (cat codegenheader.txt ; cat pkg/apis/eksctl.io/v1alpha5/zz_generated.deepcopy.go ; exit 1)
134148

135-
.PHONY: generate-kubernetes-types-test
136-
generate-kubernetes-types-test: generate-kubernetes-types ## Test if generated Kubernetes API helpers are checked-in
137-
git diff --exit-code ./pkg/nodebootstrap/assets.go > /dev/null || (git --no-pager diff ./pkg/nodebootstrap/assets.go; exit 1)
138-
149+
# static_resolver_ami.go doesn't only depend on files (it should be refreshed whenever a release is made in AWS)
150+
# so we need to forcicly generate it
139151
.PHONY: generate-ami
140152
generate-ami: ## Generate the list of AMIs for use with static resolver. Queries AWS.
141153
time go generate ./pkg/ami
142154

143-
.PHONY: generate-schema
144-
generate-schema: ## Generate the schema file in the documentation site.
145-
@go run ./cmd/schema/generate.go
155+
site/content/usage/20-schema.md: $(call godeps,cmd/schema/generate.go)
156+
time go run ./cmd/schema/generate.go $@
146157

147-
.PHONY: ami-check
148-
ami-check: generate-ami ## Check whether the AMIs have been updated and fail if they have. Designed for a automated test
149-
git diff --exit-code pkg/ami/static_resolver_ami.go > /dev/null || (git --no-pager diff; exit 1)
150-
151-
.PHONY: generate-aws-mocks
152-
generate-aws-mocks: ## Generate mocks for AWS SDK
158+
$(AWS_SDK_MOCKS): $(call godeps,pkg/eks/mocks/mocks.go)
153159
mkdir -p vendor/github.com/aws/
154160
@# Hack for Mockery to find the dependencies handled by `go mod`
155161
ln -sfn "$$(go env GOPATH)/pkg/mod/github.com/aws/[email protected]" vendor/github.com/aws/aws-sdk-go
156162
time env GOBIN=$(GOBIN) go generate ./pkg/eks/mocks
157163

158-
.PHONY: generate-aws-mocks-test
159-
generate-aws-mocks-test: generate-aws-mocks ## Test if generated mocks for AWS SDK are checked-in
160-
git diff --exit-code ./pkg/eks/mocks > /dev/null || (git --no-pager diff ./pkg/eks/mocks; exit 1)
161-
162164
##@ Docker
163165

164166
ifeq ($(OS),Windows_NT)

cmd/schema/generate.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import (
44
"github.com/alecthomas/jsonschema"
55
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
66
"io/ioutil"
7+
"os"
78
"sigs.k8s.io/yaml"
89
"strings"
910
)
1011

11-
const outputFile = "site/content/usage/20-schema.md"
12-
1312
func main() {
1413

14+
if len(os.Args) != 2 {
15+
panic("expected one argument with the output file")
16+
}
17+
outputFile := os.Args[1]
18+
1519
var document strings.Builder
1620
document.WriteString(`---
1721
title: Config file schema

eksctl-image-builder.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export JUNIT_REPORT_DIR=/src/test-results/ginkgo
44
mkdir -p "${JUNIT_REPORT_DIR}"
55

66
make $TEST_TARGET
7-
make build \
7+
make eksctl \
88
&& cp ./eksctl /out/usr/local/bin/eksctl
9-
make build-integration-test \
9+
make eksctl-integration-test \
1010
&& mkdir -p /out/usr/local/share/eksctl \
1111
&& cp integration/*.yaml /out/usr/local/share/eksctl \
1212
&& cp ./eksctl-integration-test /out/usr/local/bin/eksctl-integration-test

pkg/addons/default/generate.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
package defaultaddons
22

3-
//go:generate curl --silent --location https://github.com/aws/amazon-vpc-cni-k8s/blob/957f835f437fd76953f37e6b409ba6426bb4ce37/config/v1.4/aws-k8s-cni.yaml?raw=1 --output assets/aws-node.yaml
4-
//go:generate curl --silent --location https://github.com/aws/amazon-vpc-cni-k8s/blob/957f835f437fd76953f37e6b409ba6426bb4ce37/config/v1.4/aws-k8s-cni-1.10.yaml?raw=1 --output assets/aws-node-1.10.yaml
5-
63
//go:generate ${GOBIN}/go-bindata -pkg ${GOPACKAGE} -prefix assets -nometadata -o assets.go assets

0 commit comments

Comments
 (0)