Skip to content

Commit eba4af7

Browse files
committed
Build only when files get changed
1 parent 3a5579e commit eba4af7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Makefile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ IMAGE_NAME := mysql-operator
44
SIDECAR_IMAGE_NAME := mysql-operator-sidecar
55
BUILD_TAG := build
66
IMAGE_TAGS := $(APP_VERSION)
7+
PKG_NAME := github.com/presslabs/mysql-operator
78

8-
BINDIR := bin
9+
BINDIR := $(PWD)/bin
910
KUBEBUILDER_VERSION ?= 1.0.7
1011
HELM_VERSION ?= 2.11.0
1112

@@ -20,7 +21,7 @@ ifeq 'yes' "$(shell test -f $(BINDIR)/kubebuilder && echo -n 'yes')"
2021
KUBEBUILDER_ASSETS ?= $(BINDIR)
2122
endif
2223

23-
all: test skaffold-build
24+
all: test build
2425

2526
# Run tests
2627
test: generate fmt vet manifests
@@ -33,9 +34,17 @@ build: generate fmt vet
3334
go build -o bin/mysql-operator github.com/presslabs/mysql-operator/cmd/mysql-operator
3435
go build -o bin/mysql-operator-sidecar github.com/presslabs/mysql-operator/cmd/mysql-operator-sidecar
3536

36-
skaffold-build:
37-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o $(BINDIR)/mysql-operator_linux_amd64 github.com/presslabs/mysql-operator/cmd/mysql-operator
38-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o $(BINDIR)/mysql-operator-sidecar_linux_amd64 github.com/presslabs/mysql-operator/cmd/mysql-operator-sidecar
37+
# skaffold build
38+
bin/mysql-operator_linux_amd64: $(shell hack/development/related-go-files.sh $(PKG_NAME) cmd/mysql-operator/main.go)
39+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/mysql-operator_linux_amd64 github.com/presslabs/mysql-operator/cmd/mysql-operator
40+
41+
bin/mysql-operator-sidecar_linux_amd64: $(shell hack/development/related-go-files.sh $(PKG_NAME) cmd/mysql-operator-sidecar/main.go)
42+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/mysql-operator-sidecar_linux_amd64 github.com/presslabs/mysql-operator/cmd/mysql-operator-sidecar
43+
44+
skaffold-build: bin/mysql-operator_linux_amd64 bin/mysql-operator-sidecar_linux_amd64
45+
46+
skaffold-run: skaffold-build
47+
skaffold run
3948

4049
# Run against the configured Kubernetes cluster in ~/.kube/config
4150
run: generate fmt vet
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# This command outputs a list of go files on which the given go file depends on
3+
# Example: related-go-files.sh <base package name> <go file>
4+
5+
set -e
6+
7+
go list -f '{{ join .Deps "\n" }}' $2 | grep 'pkg' | grep -v 'vendor' | sed -e "s|^$1/||" | xargs -I % find % -name "*.go" -maxdepth 1 -type f 2>/dev/null

0 commit comments

Comments
 (0)