This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
189 lines (157 loc) · 7.24 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# NOTES
# MacOS build: ensure libs from ORACLE_HOME/lib are available in /usr/local/lib since variable DYLD_LIBRARY_PATH is
# silently ignored on macOS in some cases.
TEST_MODULES = actions cmd components config constants file helper plugin-loader rdbms table-definition transform
HP_VERSION:=$(shell git describe --tags --abbrev=0 | tr -d '[:space:]')
ORA_VERSION=19.14
BUILD_DATE=$(shell date +%F) # use +%FT%H:%M%z for format '2020-10-08T17:55+0100'
OSARCH=$(shell uname | tr "[:upper:]" "[:lower:]")
GOARCH=amd64
LD_FLAGS:=-X github.com/relloyd/halfpipe/cmd.version=${HP_VERSION} -X github.com/relloyd/halfpipe/cmd.buildDate=${BUILD_DATE} -X github.com/relloyd/halfpipe/cmd.osArch=${OSARCH}
LD_FLAGS_VERBOSE:="-v"
LD_FLAGS_DEV:=-ldflags "${LD_FLAGS}"
LD_FLAGS_RELEASE:=-ldflags "${LD_FLAGS} -s -w"
# GC_FLAGS_GOLAND is used to work around build errors produced because hp plugins appear to be compiled with different library versions due to path issues.
GC_FLAGS_GOLAND:=-gcflags "all=-N -l"
define command-export-aws-keys
$(eval export AWS_ACCESS_KEY_ID=$(shell aws configure get aws_access_key_id --profile halfpipe))
$(eval export AWS_SECRET_ACCESS_KEY=$(shell aws configure get aws_secret_access_key --profile halfpipe))
endef
.PHONY: default
default: install
set-aws-keys:
$(call command-export-aws-keys)
.PHONY: check-test-vars
check-test-vars:
ifndef AWS_ACCESS_KEY_ID
$(error AWS_ACCESS_KEY_ID is not set)
endif
ifndef AWS_SECRET_ACCESS_KEY
$(error AWS_SECRET_ACCESS_KEY is not set)
endif
.PHONY: check-ora-vars
check-ora-vars:
ifndef ORA_VERSION
$(error ORA_VERSION is not set)
endif
.PHONY: check-directory-var
check-directory-var:
ifndef DIR
$(error DIR is not set)
endif
.PHONY: tag-prerelease
tag-prerelease:
$(eval NEXT_TAG=$(shell git describe --tags --abbrev=0 | awk -F. '{printf "%s.%s.%s-pre", $$1, $$2, $$3+1}'))
git tag -a "$(NEXT_TAG)" -m "$(NEXT_TAG)"
echo "Bumped tag to: $(NEXT_TAG)"
.PHONY: tag-next
tag-next:
$(eval NEXT_TAG=$(shell git describe --tags --abbrev=0 | awk -F. '{printf "%s.%s.%s", $$1, $$2, $$3+1}'))
@git tag -a "$(NEXT_TAG)" -m "$(NEXT_TAG)"
@echo "Bumped tag to: $(NEXT_TAG)"
###############################################################################
# TESTING
###############################################################################
.PHONY: test-dir
test-dir: check-directory-var
export AWS_PROFILE=halfpipe && \
cd $(DIR) && \
go test -trimpath $(LD_FLAGS_DEV) $(GC_FLAGS_GOLAND)
.PHONY: test-integration
test-integration: check-directory-var
export AWS_PROFILE=halfpipe && \
cd cmd && \
go test -trimpath $(LD_FLAGS_DEV) $(GC_FLAGS_GOLAND) -tags=integration
.PHONY: test-modules
test-modules:
export AWS_PROFILE=halfpipe && \
for dir in $(TEST_MODULES); do \
go test -trimpath $(LD_FLAGS_DEV) $(GC_FLAGS_GOLAND) ./$$dir/... || exit 1 ; \
done
.PHONY: test
test: test-modules
###############################################################################
# BUILD BINARIES
###############################################################################
.PHONY: build
build:
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_DEV) $(GC_FLAGS_GOLAND) -o dist/hp main.go
.PHONY: build-so
build-so:
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_DEV) $(GC_FLAGS_GOLAND) -buildmode=plugin -o dist/hp-oracle-plugin.so rdbms/oracle/main.go
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_DEV) $(GC_FLAGS_GOLAND) -buildmode=plugin -o dist/hp-odbc-plugin.so rdbms/odbc/main.go
.PHONY: build-race
build-race:
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_DEV) -race -o dist/hp main.go
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_DEV) -buildmode=plugin -race -o dist/hp-oracle-plugin.so rdbms/oracle/main.go
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_DEV) -buildmode=plugin -race -o dist/hp-odbc-plugin.so rdbms/odbc/main.go
# build-linux target should be used inside Docker else the linking to OCI shared libraries are bad at runtime.
.PHONY: build-linux
build-linux: check-ora-vars
# Pre-requisites:
# Ensure Oracle instant client libraries and header files can be found during compilation:
# LIBRARY_PATH and C_INCLUDE_PATH can be set to achieve this.
CGO_ENABLED=1 GOOS=$(OSARCH) GOARCH=$(GOARCH) go build -v -trimpath $(LD_FLAGS_RELEASE) -o dist/hp main.go
CGO_ENABLED=1 GOOS=$(OSARCH) GOARCH=$(GOARCH) go build -v -trimpath $(LD_FLAGS_RELEASE) -buildmode=plugin -o dist/hp-oracle-plugin.so rdbms/oracle/main.go
CGO_ENABLED=1 GOOS=$(OSARCH) GOARCH=$(GOARCH) go build -v -trimpath $(LD_FLAGS_RELEASE) -buildmode=plugin -o dist/hp-odbc-plugin.so rdbms/odbc/main.go
###############################################################################
# BUILD & INSTALL NATIVE BINARIES
###############################################################################
.PHONY: install
install: build build-so
cp -p dist/hp $$GOPATH/bin/
cp -p dist/hp-oracle-plugin.so /usr/local/lib
cp -p dist/hp-odbc-plugin.so /usr/local/lib
.PHONY: install-core
install-core: build
cp -p dist/hp $$GOPATH/bin/
###############################################################################
# LINUX BUILDS VIA DOCKER
###############################################################################
.PHONY: docker-build
docker-build:
scripts/docker-build.sh $(ORA_VERSION) $(HP_VERSION) relloyd/halfpipe-oracle-$(ORA_VERSION)
.PHONY: docker-run
docker-run:
mkdir -p $$HOME/.halfpipe && \
docker run -ti --rm \
-v $$HOME/.halfpipe:/home/dataops/.halfpipe \
relloyd/halfpipe-oracle-$(ORA_VERSION):latest
###############################################################################
# QUICKSTART
#
# 1. Build the core halfpipe docker image with additional tools like
# AWS CLI, kubectl, k9s, less and other CLI hacks.
# 2. Start the image with .aws and .halfpipe directories mounted
# and AWS_PROFILE=halfpipe
#
###############################################################################
.PHONY: quickstart
quickstart: docker-build
scripts/docker-build.sh $(ORA_VERSION) $(HP_VERSION) relloyd/halfpipe-oracle-$(ORA_VERSION)-quickstart quickstart && \
scripts/start-halfpipe.sh relloyd/halfpipe-oracle-$(ORA_VERSION)-quickstart:latest
###############################################################################
# RELEASES
###############################################################################
.PHONY: docker-get-files
docker-get-files:
$(eval RELEASE_DIR=dist/hp-linux-amd64-$(HP_VERSION)-oracle-$(ORA_VERSION))
mkdir -p $(RELEASE_DIR)
$(eval id=$(shell docker create relloyd/halfpipe-oracle-$(ORA_VERSION):$(HP_VERSION)))
docker cp $(id):/usr/local/bin/hp $(RELEASE_DIR)
docker cp $(id):/usr/local/lib/hp-odbc-plugin.so $(RELEASE_DIR)
docker cp $(id):/usr/local/lib/hp-oracle-plugin.so $(RELEASE_DIR)
docker rm -v $(id)
.PHONY: release-darwin
release-darwin:
$(eval RELEASE_DIR=dist/hp-$(OSARCH)-$(GOARCH)-$(HP_VERSION)-oracle-$(ORA_VERSION))
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_RELEASE) -o $(RELEASE_DIR)/hp main.go
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_RELEASE) -buildmode=plugin -o $(RELEASE_DIR)/hp-oracle-plugin.so rdbms/oracle/main.go
CGO_ENABLED=1 go build -trimpath $(LD_FLAGS_RELEASE) -buildmode=plugin -o $(RELEASE_DIR)/hp-odbc-plugin.so rdbms/odbc/main.go
@echo Release darwin complete
.PHONY: release-linux
release-linux: docker-build docker-get-files
@echo Release linux complete
.PHONY: release
release: release-darwin release-linux
@echo Release complete