forked from oracle/mysql-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
118 lines (101 loc) · 3.39 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright 2018 Oracle and/or its affiliates. All rights reserved.
#
# 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.
ifdef WERCKER
# Insert swear words about mysql group replication and hostname length. Arghh..
VERSION ?= ${WERCKER_GIT_COMMIT}
TENANT := "oracle"
else
VERSION ?= ${USER}-$(shell git describe --always --dirty)
TENANT ?= "spinnaker"
endif
PKG := github.com/oracle/mysql-operator
REGISTRY := iad.ocir.io
SRC_DIRS := cmd pkg test/examples
CMD_DIRECTORIES := $(sort $(dir $(wildcard ./cmd/*/)))
COMMANDS := $(CMD_DIRECTORIES:./cmd/%/=%)
ARCH ?= amd64
OS ?= linux
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
# Cross-compiling from OSX to linux, go install puts the binaries in $GOPATH/bin/$GOOS_$GOARCH
BINARIES := $(addprefix $(GOPATH)/bin/$(OS)_$(ARCH)/,$(COMMANDS))
else
ifeq ($(UNAME_S),Linux)
# Compiling on linux for linux, go install puts the binaries in $GOPATH/bin
BINARIES := $(addprefix $(GOPATH)/bin/,$(COMMANDS))
else
$(error "Unsupported OS: $(UNAME_S)")
endif
endif
.PHONY: all
all: build
.PHONY: test
test: build-dirs Makefile
@echo "Testing: $(SRC_DIRS)"
PKG=$(PKG) ./hack/test.sh $(SRC_DIRS)
.PHONY: build-dirs
build-dirs:
@echo "Creating build directories"
@mkdir -p bin/$(OS)_$(ARCH)
@mkdir -p dist/
@mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(ARCH)
.PHONY: dist
dist: build-dirs
@echo "Creating version file: $(VERSION)"
@echo ${VERSION} > dist/version.txt
.PHONY: build
build: dist build-dirs Makefile
@echo "Building: $(BINARIES)"
@touch pkg/version/version.go # Important. Work around for https://github.com/golang/go/issues/18369
ARCH=$(ARCH) OS=$(OS) VERSION=$(VERSION) PKG=$(PKG) ./hack/build.sh
cp $(BINARIES) ./bin/$(OS)_$(ARCH)/
.PHONY: build-docker
build-docker:
@docker build \
--build-arg=http_proxy \
--build-arg=https_proxy \
-t $(REGISTRY)/$(TENANT)/mysql-operator:$(VERSION) \
-f docker/mysql-operator/Dockerfile .
@docker build \
--build-arg=http_proxy \
--build-arg=https_proxy \
-t $(REGISTRY)/$(TENANT)/mysql-agent:$(VERSION) \
-f docker/mysql-agent/Dockerfile .
# Note: Only used for development, i.e. in CI the images are pushed using Wercker.
.PHONY: push
push: build build-docker
@docker login iad.ocir.io -u $(DOCKER_REGISTRY_USERNAME) -p '$(DOCKER_REGISTRY_PASSWORD)'
@docker push $(REGISTRY)/$(TENANT)/mysql-operator:$(VERSION)
@docker push $(REGISTRY)/$(TENANT)/mysql-agent:$(VERSION)
.PHONY: version
version:
@echo $(VERSION)
.PHONY: lint
lint:
@find pkg cmd -name '*.go' | grep -v 'generated' | xargs -L 1 golint
.PHONY: clean
clean:
rm -rf .go bin
.PHONY: run-dev
run-dev:
@go run \
-ldflags "-X ${PKG}/pkg/version.buildVersion=${MYSQL_AGENT_VERSION}" \
cmd/mysql-operator/main.go \
--mysql-agent-image=iad.ocir.io/$(TENANT)/mysql-agent \
--kubeconfig=${KUBECONFIG} \
--v=4 \
--namespace=${USER}
.PHONY: generate
generate:
./hack/update-generated.sh