forked from radondb/radondb-postgresql-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
237 lines (186 loc) · 6.82 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# Default values if not already set
ANSIBLE_VERSION ?= 2.9.*
PGOROOT ?= $(CURDIR)
PGO_BASEOS ?= debian
BASE_IMAGE_OS ?= $(PGO_BASEOS)
PGO_IMAGE_PREFIX ?= radondb
PGO_VERSION ?= 2.1.1
PGO_IMAGE_TAG ?= $(PGO_BASEOS)-$(PGO_VERSION)
PGO_PG_VERSION ?= 14
PGO_PG_FULLVERSION ?= 14.2
PGO_BACKREST_VERSION ?= 2.33
PACKAGER ?= apt
RELTMPDIR=/tmp/release.$(PGO_VERSION)
RELFILE=/tmp/postgres-operator.$(PGO_VERSION).tar.gz
# Valid values: buildah (default), docker
IMGBUILDER ?= docker
# Determines whether or not rootless builds are enabled
IMG_ROOTLESS_BUILD ?= false
# The utility to use when pushing/pulling to and from an image repo (e.g. docker or buildah)
IMG_PUSHER_PULLER ?= docker
# Determines whether or not images should be pushed to the local docker daemon when building with
# a tool other than docker (e.g. when building with buildah)
IMG_PUSH_TO_DOCKER_DAEMON ?= false
# Defines the sudo command that should be prepended to various build commands when rootless builds are
# not enabled
IMGCMDSUDO=
ifneq ("$(IMG_ROOTLESS_BUILD)", "true")
IMGCMDSUDO=sudo --preserve-env
endif
IMGCMDSTEM=$(IMGCMDSUDO) buildah bud --layers $(SQUASH)
DFSET=$(PGO_BASEOS)
# Default the buildah format to docker to ensure it is possible to pull the images from a docker
# repository using docker (otherwise the images may not be recognized)
export BUILDAH_FORMAT ?= docker
DOCKERBASEREGISTRY=docker.io/
# Allows simplification of IMGBUILDER switching
ifeq ("$(IMGBUILDER)","docker")
IMGCMDSTEM=docker build
endif
DEBUG_BUILD ?= false
GO_BUILD = $(GO_CMD) build
GO_CMD = $(GO_ENV) go
# Disable optimizations if creating a debug build
ifeq ("$(DEBUG_BUILD)", "true")
GO_BUILD += -gcflags='all=-N -l'
endif
ifeq ("$(PGO_BASEOS)", "debian")
PACKAGER=apt
BASE_IMAGE_OS=bullseye-slim
endif
# To build a specific image, run 'make <name>-image' (e.g. 'make pgo-apiserver-image')
images = pgo-apiserver \
pgo-event \
pgo-rmdata \
pgo-scheduler \
pgo-client \
pgo-deployer \
radondb-postgres-exporter \
postgres-operator
.PHONY: all installrbac setup setupnamespaces cleannamespaces \
deployoperator cli-docs clean push pull release license
#======= Main functions =======
all: linuxpgo $(images:%=%-image)
installrbac:
PGOROOT='$(PGOROOT)' ./deploy/install-rbac.sh
setup:
PGOROOT='$(PGOROOT)' ./bin/get-deps.sh
./bin/check-deps.sh
setupnamespaces:
PGOROOT='$(PGOROOT)' ./deploy/setupnamespaces.sh
cleannamespaces:
PGOROOT='$(PGOROOT)' ./deploy/cleannamespaces.sh
deployoperator:
PGOROOT='$(PGOROOT)' ./deploy/deploy.sh
#======= Binary builds =======
build: build-dev license
build-dev: build-postgres-operator build-pgo-apiserver build-pgo-client build-pgo-rmdata build-pgo-scheduler
build-pgo-apiserver:
$(GO_BUILD) -o bin/apiserver ./cmd/apiserver
build-pgo-rmdata:
$(GO_BUILD) -o bin/pgo-rmdata/pgo-rmdata ./cmd/pgo-rmdata
build-pgo-scheduler:
$(GO_BUILD) -o bin/pgo-scheduler/pgo-scheduler ./cmd/pgo-scheduler
build-postgres-operator:
$(GO_BUILD) -o bin/postgres-operator ./cmd/postgres-operator
build-pgo-client:
$(GO_BUILD) -o bin/pgo ./cmd/pgo
build-pgo-%:
$(info No binary build needed for $@)
build-radondb-postgres-exporter:
$(info No binary build needed for $@)
linuxpgo: GO_ENV += GOOS=linux GOARCH=amd64
linuxpgo:
$(GO_BUILD) -o bin/pgo ./cmd/pgo
macpgo: GO_ENV += GOOS=darwin GOARCH=amd64
macpgo:
$(GO_BUILD) -o bin/pgo-mac ./cmd/pgo
winpgo: GO_ENV += GOOS=windows GOARCH=386
winpgo:
$(GO_BUILD) -o bin/pgo.exe ./cmd/pgo
#======= Image builds =======
$(PGOROOT)/build/%/Dockerfile:
$(error No Dockerfile found for $* naming pattern: [$@])
%-img-build: pgo-base-$(IMGBUILDER) build-% $(PGOROOT)/build/%/Dockerfile
$(IMGCMDSTEM) \
-f $(PGOROOT)/build/$*/Dockerfile \
-t $(PGO_IMAGE_PREFIX)/$*:$(PGO_IMAGE_TAG) \
--build-arg BASEOS=$(PGO_BASEOS) \
--build-arg BASEVER=$(PGO_VERSION) \
--build-arg PREFIX=$(PGO_IMAGE_PREFIX) \
--build-arg PGVERSION=$(PGO_PG_VERSION) \
--build-arg BACKREST_VERSION=$(PGO_BACKREST_VERSION) \
--build-arg ANSIBLE_VERSION=$(ANSIBLE_VERSION) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
$(PGOROOT)
%-img-buildah: %-img-build ;
# only push to docker daemon if variable PGO_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
$(IMGCMDSUDO) buildah push $(PGO_IMAGE_PREFIX)/$*:$(PGO_IMAGE_TAG) docker-daemon:$(PGO_IMAGE_PREFIX)/$*:$(PGO_IMAGE_TAG)
endif
%-img-docker: %-img-build ;
%-image: %-img-$(IMGBUILDER) ;
pgo-base: pgo-base-$(IMGBUILDER)
pgo-base-build: build $(PGOROOT)/build/pgo-base/Dockerfile
$(IMGCMDSTEM) \
-f $(PGOROOT)/build/pgo-base/Dockerfile \
-t $(PGO_IMAGE_PREFIX)/pgo-base:$(PGO_IMAGE_TAG) \
--build-arg BASEOS=$(PGO_BASEOS) \
--build-arg RELVER=$(PGO_VERSION) \
--build-arg PGVERSION=$(PGO_PG_VERSION) \
--build-arg PG_FULL=$(PGO_PG_FULLVERSION) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
--build-arg DOCKERBASEREGISTRY=$(DOCKERBASEREGISTRY) \
--build-arg BASE_IMAGE_OS=$(BASE_IMAGE_OS) \
$(PGOROOT)
pgo-base-buildah: pgo-base-build ;
# only push to docker daemon if variable PGO_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
$(IMGCMDSUDO) buildah push $(PGO_IMAGE_PREFIX)/pgo-base:$(PGO_IMAGE_TAG) docker-daemon:$(PGO_IMAGE_PREFIX)/pgo-base:$(PGO_IMAGE_TAG)
endif
pgo-base-docker: pgo-base-build
#======== Utility =======
check:
PGOROOT=$(PGOROOT) go test ./...
cli-docs:
rm docs/content/pgo-client/reference/*.md
cd docs/content/pgo-client/reference && go run ../../../../cmd/pgo/generatedocs.go
sed -e '1,5 s|^title:.*|title: "pgo Client Reference"|' \
docs/content/pgo-client/reference/pgo.md > \
docs/content/pgo-client/reference/_index.md
rm docs/content/pgo-client/reference/pgo.md
clean: clean-deprecated
rm -f bin/apiserver
rm -f bin/postgres-operator
rm -f bin/pgo bin/pgo-mac bin/pgo.exe
rm -f bin/pgo-rmdata/pgo-rmdata
rm -f bin/pgo-scheduler/pgo-scheduler
[ -z "$$(ls hack/tools)" ] || rm hack/tools/*
clean-deprecated:
@# packages used to be downloaded into the vendor directory
[ ! -d vendor ] || rm -r vendor
@# executables used to be compiled into the $GOBIN directory
[ ! -n '$(GOBIN)' ] || rm -f $(GOBIN)/postgres-operator $(GOBIN)/apiserver $(GOBIN)/*pgo
[ ! -d bin/postgres-operator ] || rm -r bin/postgres-operator
license:
./bin/license_aggregator.sh
push: $(images:%=push-%) ;
push-%:
$(IMG_PUSHER_PULLER) push $(PGO_IMAGE_PREFIX)/$*:$(PGO_IMAGE_TAG)
pull: $(images:%=pull-%) ;
pull-%:
$(IMG_PUSHER_PULLER) pull $(PGO_IMAGE_PREFIX)/$*:$(PGO_IMAGE_TAG)
release: linuxpgo macpgo winpgo
rm -rf $(RELTMPDIR) $(RELFILE)
mkdir $(RELTMPDIR)
cp -r $(PGOROOT)/examples $(RELTMPDIR)
cp -r $(PGOROOT)/deploy $(RELTMPDIR)
cp -r $(PGOROOT)/conf $(RELTMPDIR)
cp bin/pgo $(RELTMPDIR)
cp bin/pgo-mac $(RELTMPDIR)
cp bin/pgo.exe $(RELTMPDIR)
tar czvf $(RELFILE) -C $(RELTMPDIR) .
generate:
GOBIN='$(CURDIR)/hack/tools' ./hack/update-codegen.sh