forked from oracle/mysql-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
126 lines (107 loc) · 3.97 KB
/
Makefile
File metadata and controls
126 lines (107 loc) · 3.97 KB
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
119
120
121
122
123
124
125
126
# 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.
USE_GLOBAL_NAMESPACE ?= false
ifdef WERCKER
# Insert swear words about mysql group replication and hostname length. Arghh..
VERSION := ${WERCKER_GIT_COMMIT}
else
NEW_NAMESPACE ?= e2e-${USER}
VERSION := ${USER}-$(shell date +%Y%m%d%H%M%S)
endif
ROOT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
PKG := github.com/oracle/mysql-operator
REGISTRY := wcr.io/oracle
SRC_DIRS := cmd pkg test/examples
REGISTRY_STRING := $(subst /,_,$(REGISTRY))
CMD_DIRECTORIES := $(sort $(dir $(wildcard ./cmd/*/)))
COMMANDS := $(CMD_DIRECTORIES:./cmd/%/=%)
CONTAINER_FILES := $(addprefix .container-$(REGISTRY_STRING)-,$(addsuffix -$(VERSION),$(COMMANDS)))
PUSH_FILES := $(addprefix .push-$(REGISTRY_STRING)-,$(addsuffix -$(VERSION),$(COMMANDS)))
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)/
# Note: Only used for development, i.e. in CI the images are built using Wercker.
.PHONY: containers
containers: $(CONTAINER_FILES)
.container-$(REGISTRY_STRING)-%-$(VERSION): build dist
@echo Builing container: $*
@docker login -u '$(DOCKER_REGISTRY_USERNAME)' -p '$(DOCKER_REGISTRY_PASSWORD)' $(REGISTRY)
@docker build --build-arg=http_proxy --build-arg=https_proxy -t $(REGISTRY)/$*:$(VERSION) -f docker/$*/Dockerfile .
@docker images -q $(REGISTRY)/$*:$(VERSION) > $@
# Note: Only used for development, i.e. in CI the images are pushed using Wercker.
.PHONY: push
push: $(PUSH_FILES)
.push-$(REGISTRY_STRING)-%-$(VERSION): .container-$(REGISTRY_STRING)-%-$(VERSION)
@echo Pushing container: $*
@docker login -u '$(DOCKER_REGISTRY_USERNAME)' -p '$(DOCKER_REGISTRY_PASSWORD)' $(REGISTRY)
@docker push $(REGISTRY)/$*:$(VERSION)
@docker images -q $(REGISTRY)/$*:$(VERSION) > $@
.PHONY: version
version:
@echo $(VERSION)
.PHONY: lint
lint:
@find pkg cmd -name '*.go' | grep -v 'generated' | xargs -L 1 golint
.PHONY: clean
clean: container-clean bin-clean
.PHONY: container-clean
container-clean:
rm -rf .container-* .push-* dist
.PHONY: bin-clean
bin-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 \
--kubeconfig=${KUBECONFIG} \
--v=4 \
--namespace=${USER}
.PHONY: generate
generate:
./hack/update-generated.sh