-
Notifications
You must be signed in to change notification settings - Fork 237
/
Makefile
195 lines (161 loc) · 6.52 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
190
191
192
193
194
195
ARCH ?= $(shell uname -m)
OS_TYPE ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH_TYPE ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(ARCH)))
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
VERSION ?= 0.6.0
LDFLAGS := -X main.Version=$(VERSION)
GOFLAGS := -ldflags "$(LDFLAGS) -s -w"
BUILD_ARGS = --build-arg VERSION=$(VERSION)
LEGACY_TABLESPACE = --build-arg LEGACY_TABLESPACE=.legacy-tablespace
OUTDIR = ./dist
LINTER_VERSION ?= v1.55.2
LINTER_IMAGE ?= docker.io/golangci/golangci-lint:$(LINTER_VERSION)
ifeq ($(shell command -v podman 2> /dev/null),)
DOCKER_CMD = docker
else
DOCKER_CMD = podman
endif
IMAGE_NAME ?= iamseth/oracledb_exporter
IMAGE_ID ?= $(IMAGE_NAME):$(VERSION)
IMAGE_ID_LATEST?= $(IMAGE_NAME):latest
RELEASE ?= true
UBUNTU_BASE_IMAGE ?= docker.io/library/ubuntu:24.04
ORACLE_LINUX_BASE_IMAGE ?= docker.io/library/oraclelinux:9-slim
ALPINE_BASE_IMAGE ?= docker.io/library/alpine:3.19
SCRATCH_BASE_IMAGE ?= scratch
ifeq ($(GOOS), windows)
EXT?=.exe
else
EXT?=
endif
export LD_LIBRARY_PATH
version:
@echo "$(VERSION)"
.PHONY: go-build
go-build:
@echo "Build $(OS_TYPE)"
mkdir -p $(OUTDIR)/oracledb_exporter-$(VERSION).$(GOOS)-$(GOARCH)/
go build $(GOFLAGS) -o $(OUTDIR)/oracledb_exporter-$(VERSION).$(GOOS)-$(GOARCH)/oracledb_exporter$(EXT)
cp default-metrics.toml $(OUTDIR)/$(DIST_DIR)
(cd dist ; tar cfz oracledb_exporter-$(VERSION).$(GOOS)-$(GOARCH).tar.gz oracledb_exporter-$(VERSION).$(GOOS)-$(GOARCH))
.PHONY: go-build-linux-amd64
go-build-linux-amd64:
GOOS=linux GOARCH=amd64 $(MAKE) go-build -j2
.PHONY: go-build-linux-arm64
go-build-linux-arm64:
GOOS=linux GOARCH=arm64 $(MAKE) go-build -j2
.PHONY: go-build-darwin-amd64
go-build-darwin-amd64:
GOOS=darwin GOARCH=amd64 $(MAKE) go-build -j2
.PHONY: go-build-darwin-arm64
go-build-darwin-arm64:
GOOS=darwin GOARCH=arm64 $(MAKE) go-build -j2
.PHONY: go-build-windows-amd64
go-build-windows-amd64:
GOOS=windows GOARCH=amd64 $(MAKE) go-build -j2
.PHONY: go-build-windows-x86
go-build-windows-x86:
GOOS=windows GOARCH=386 $(MAKE) go-build -j2
go-lint:
@echo "Linting codebase"
mkdir -p ~/.cache/golangci-lint/$(LINTER_VERSION)
$(DOCKER_CMD) run --rm -v $$PWD:/app -v ~/.cache/golangci-lint/$(LINTER_VERSION):/root/.cache -w /app \
$(LINTER_IMAGE) golangci-lint run -v
local-build: go-build
@true
build: docker
@true
deps:
go get
go-test:
@echo "Run tests"
GOOS=$(OS_TYPE) GOARCH=$(ARCH_TYPE) go test -coverprofile="test-coverage.out" $$(go list ./... | grep -v /vendor/)
clean:
rm -rf ./dist sgerrand.rsa.pub glibc-*.apk oracle-*.rpm
docker: ubuntu-image alpine-image oraclelinux-image scratch-image
push-images:
@make --no-print-directory push-ubuntu-image
@make --no-print-directory push-oraclelinux-image
@make --no-print-directory push-alpine-image
@make --no-print-directory push-scratch-image
oraclelinux-image:
if DOCKER_CLI_EXPERIMENTAL=enabled $(DOCKER_CMD) manifest inspect "$(IMAGE_ID)-oraclelinux" > /dev/null; then \
echo "Image \"$(IMAGE_ID)-oraclelinux\" already exists on ghcr.io"; \
else \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) -t "$(IMAGE_ID)-oraclelinux" --build-arg BASE_IMAGE=$(ORACLE_LINUX_BASE_IMAGE) . && \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) $(LEGACY_TABLESPACE) -t "$(IMAGE_ID)-oraclelinux_legacy-tablespace" --build-arg BASE_IMAGE=$(ORACLE_LINUX_BASE_IMAGE) . && \
$(DOCKER_CMD) tag "$(IMAGE_ID)-oraclelinux" "$(IMAGE_NAME):oraclelinux"; \
fi
push-oraclelinux-image:
$(DOCKER_CMD) push $(IMAGE_ID)-oraclelinux
ifeq ("$(RELEASE)", "true")
$(DOCKER_CMD) push "$(IMAGE_NAME):oraclelinux"
$(DOCKER_CMD) push "$(IMAGE_ID)-oraclelinux_legacy-tablespace"
endif
sign-oraclelinux-image:
ifneq ("$(wildcard cosign.key)","")
cosign sign --key cosign.key $(IMAGE_ID)-oraclelinux
else
@echo "Can't find cosign.key file"
endif
ubuntu-image:
if DOCKER_CLI_EXPERIMENTAL=enabled $(DOCKER_CMD) manifest inspect "$(IMAGE_ID)" > /dev/null; then \
echo "Image \"$(IMAGE_ID)\" already exists on ghcr.io"; \
else \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) --build-arg BASE_IMAGE=$(UBUNTU_BASE_IMAGE) -t "$(IMAGE_ID)" . && \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) --build-arg BASE_IMAGE=$(UBUNTU_BASE_IMAGE) $(LEGACY_TABLESPACE) -t "$(IMAGE_ID)_legacy-tablespace" . && \
$(DOCKER_CMD) tag "$(IMAGE_ID)" "$(IMAGE_ID_LATEST)"; \
fi
push-ubuntu-image:
$(DOCKER_CMD) push $(IMAGE_ID)
ifeq ("$(RELEASE)", "true")
$(DOCKER_CMD) push "$(IMAGE_ID_LATEST)"
$(DOCKER_CMD) push "$(IMAGE_ID)_legacy-tablespace"
endif
sign-ubuntu-image:
ifneq ("$(wildcard cosign.key)","")
cosign sign --key cosign.key $(IMAGE_ID)
cosign sign --key cosign.key $(IMAGE_ID_LATEST)
else
@echo "Can't find cosign.key file"
endif
alpine-image:
if DOCKER_CLI_EXPERIMENTAL=enabled $(DOCKER_CMD) manifest inspect "$(IMAGE_ID)-alpine" > /dev/null; then \
echo "Image \"$(IMAGE_ID)-alpine\" already exists on ghcr.io"; \
else \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) -t "$(IMAGE_ID)-alpine" --build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) . && \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) $(LEGACY_TABLESPACE) --build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) -t "$(IMAGE_ID)-alpine_legacy-tablespace" . && \
$(DOCKER_CMD) tag "$(IMAGE_ID)-alpine" "$(IMAGE_NAME):alpine"; \
fi
push-alpine-image:
$(DOCKER_CMD) push $(IMAGE_ID)-alpine
ifeq ("$(RELEASE)", "true")
$(DOCKER_CMD) push "$(IMAGE_NAME):alpine"
endif
sign-alpine-image:
ifneq ("$(wildcard cosign.key)","")
cosign sign --key cosign.key $(IMAGE_ID)-alpine
else
@echo "Can't find cosign.key file"
endif
scratch-image:
if DOCKER_CLI_EXPERIMENTAL=enabled $(DOCKER_CMD) manifest inspect "$(IMAGE_ID)-scratch" > /dev/null; then \
echo "Image \"$(IMAGE_ID)-scratch\" already exists on ghcr.io"; \
else \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) -t "$(IMAGE_ID)-scratch" --build-arg BASE_IMAGE=$(SCRATCH_BASE_IMAGE) --build-arg CGO_ENABLED=0 . && \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) $(LEGACY_TABLESPACE) --build-arg BASE_IMAGE=$(SCRATCH_BASE_IMAGE) --build-arg CGO_ENABLED=0 -t "$(IMAGE_ID)-scratch_legacy-tablespace" . && \
$(DOCKER_CMD) tag "$(IMAGE_ID)-scratch" "$(IMAGE_NAME):scratch"; \
fi
push-scratch-image:
$(DOCKER_CMD) push $(IMAGE_ID)-scratch
ifeq ("$(RELEASE)", "true")
$(DOCKER_CMD) push "$(IMAGE_NAME):scratch"
endif
sign-scratch-image:
ifneq ("$(wildcard cosign.key)","")
cosign sign --key cosign.key $(IMAGE_ID)-scratch
else
@echo "Can't find cosign.key file"
endif
.PHONY: version build deps go-test clean docker