This repository has been archived by the owner on Jun 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
151 lines (133 loc) · 4.15 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Copyright 2017 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.
BIN := oci
BUILD_DIR := dist
BIN_DIR := ${BUILD_DIR}/bin
BUILD := $(shell git describe --always --dirty)
# Allow overriding for release versions
# Else just equal the build (git hash)
VERSION ?= ${BUILD}
GOOS ?= linux
GOARCH ?= amd64
REGISTRY ?= iad.ocir.io
DOCKER_REGISTRY_TENANCY ?= oracle
DOCKER_REGISTRY_USERNAME ?= oracle
IMAGE := $(REGISTRY)/$(DOCKER_REGISTRY_TENANCY)/oci-flexvolume-driver
TEST_IMAGE ?= $(REGISTRY)/$(DOCKER_REGISTRY_TENANCY)/oci-flexvolume-driver-test
SRC_DIRS := cmd pkg # directories which hold app source (not vendored)
RETURN_CODE := $(shell sed --version >/dev/null 2>&1; echo $$?)
ifeq ($(RETURN_CODE),1)
SED_INPLACE = -i ''
else
SED_INPLACE = -i
endif
.PHONY: all
all: clean test build manifests build-integration-tests
.PHONY: gofmt
gofmt:
@./hack/check-gofmt.sh ${SRC_DIRS}
.PHONY: golint
golint:
@./hack/check-golint.sh ${SRC_DIRS}
.PHONY: govet
govet:
@./hack/check-govet.sh ${SRC_DIRS}
.PHONY: test
test:
@./hack/test.sh $(SRC_DIRS)
.PHONY: clean
clean:
rm -rf ${BUILD_DIR}
.PHONY: build
build:
mkdir -p ${BIN_DIR}
GOOS=${GOOS} \
CGO_ENABLED=0 \
GOARCH=${GOARCH} \
go build \
-i \
-v \
-ldflags="-s -w -X main.version=${VERSION} -X main.build=${BUILD}" \
-o ${BIN_DIR}/${BIN} ./cmd/oci/
.PHONY: manifests
manifests: build
@cp -a manifests/* dist
@sed ${SED_INPLACE} 's#__VERSION__#${VERSION}#g' dist/oci-flexvolume-driver.yaml
@sed ${SED_INPLACE} 's#__DOCKER_REGISTRY_TENANCY__#${DOCKER_REGISTRY_TENANCY}#g' dist/oci-flexvolume-driver.yaml
.PHONY: build-integration-tests
build-integration-tests:
mkdir -p ${BIN_DIR}
GOOS=${GOOS} \
CGO_ENABLED=0 \
GOARCH=${GOARCH} \
go test \
-v \
-c \
-i \
-o ${BIN_DIR}/integration-tests \
./test/integration
.PHONY: image
image: manifests build-integration-tests
docker build -t ${IMAGE}:${VERSION} -f Dockerfile .
docker build -t ${TEST_IMAGE}:${VERSION} -f Dockerfile.test .
.PHONY: push
push: image
docker login -u '$(DOCKER_REGISTRY_USERNAME)' -p '$(DOCKER_REGISTRY_PASSWORD)' $(REGISTRY)
docker push ${IMAGE}:${VERSION}
docker push ${TEST_IMAGE}:${VERSION}
.PHONY:system-test-config
system-test-config:
ifndef KUBECONFIG
ifndef KUBECONFIG_VAR
$(error "KUBECONFIG or KUBECONFIG_VAR must be defined")
else
$(eval KUBECONFIG:=/tmp/kubeconfig)
$(eval export KUBECONFIG)
$(shell echo "$${KUBECONFIG_VAR}" | openssl enc -base64 -d -A > $(KUBECONFIG))
endif
endif
ifndef OCI_API_KEY
ifdef OCI_API_KEY_VAR
$(eval OCI_API_KEY:=/tmp/oci_api_key.pem)
$(eval export OCI_API_KEY)
$(shell echo "$${OCI_API_KEY_VAR}" | openssl enc -base64 -d -A > $(OCI_API_KEY))
$(eval DOCKER_OPTIONS+=-e OCI_API_KEY=$(OCI_API_KEY) -v $(OCI_API_KEY):$(OCI_API_KEY))
$(eval export DOCKER_OPTIONS)
endif
endif
ifndef INSTANCE_KEY
ifdef INSTANCE_KEY_VAR
$(eval INSTANCE_KEY:=/tmp/instance_key)
$(eval export INSTANCE_KEY)
$(shell echo "$${INSTANCE_KEY_VAR}" | openssl enc -base64 -d -A > $(INSTANCE_KEY))
$(shell chmod 600 $(INSTANCE_KEY))
$(eval DOCKER_OPTIONS+=-e INSTANCE_KEY=$(INSTANCE_KEY) -v $(INSTANCE_KEY):$(INSTANCE_KEY))
$(eval export DOCKER_OPTIONS)
endif
endif
.PHONY: system-test
system-test: system-test-config
docker run -it ${DOCKER_OPTIONS} \
-e KUBECONFIG=$(KUBECONFIG) \
-v $(KUBECONFIG):$(KUBECONFIG) \
-e MASTER_IP=$$MASTER_IP \
-e SLAVE0_IP=$$SLAVE0_IP \
-e SLAVE1_IP=$$SLAVE1_IP \
-e VCN=$$VCN \
-e WERCKER_API_TOKEN=$$WERCKER_API_TOKEN \
-e HTTPS_PROXY=$$HTTPS_PROXY \
${TEST_IMAGE}:${VERSION} ${TEST_IMAGE_ARGS}
.PHONY: version
version:
@echo ${VERSION}