@@ -190,7 +190,7 @@ endif
190190
191191clean :
192192 $(SUDO ) docker rmi $(IMAGE_NAMES ) > /dev/null 2>&1 || true
193- rm -rf $(UPTODATE_FILES ) $(EXES ) .cache
193+ rm -rf -- $(UPTODATE_FILES ) $(EXES ) .cache $( PACKAGES ) dist/ *
194194 go clean ./...
195195
196196clean-protos :
@@ -232,7 +232,7 @@ web-serve:
232232 cd website && hugo --config config.toml -v server
233233
234234# Generate binaries for a Cortex release
235- dist :
235+ dist dist/cortex-linux-amd64 dist/cortex-darwin-amd64 dist/query-tee-linux-amd64 dist/query-tee-darwin-amd64 dist/cortex-linux-amd64-sha-256 dist/cortex-darwin-amd64-sha-256 dist/query-tee-linux-amd64-sha-256 dist/query-tee-darwin-amd64-sha-256 :
236236 rm -fr ./dist
237237 mkdir -p ./dist
238238 GOOS=" linux" GOARCH=" amd64" CGO_ENABLED=0 go build $(GO_FLAGS ) -o ./dist/cortex-linux-amd64 ./cmd/cortex
@@ -243,3 +243,50 @@ dist:
243243 shasum -a 256 ./dist/cortex-linux-amd64 | cut -d ' ' -f 1 > ./dist/cortex-linux-amd64-sha-256
244244 shasum -a 256 ./dist/query-tee-darwin-amd64 | cut -d ' ' -f 1 > ./dist/query-tee-darwin-amd64-sha-256
245245 shasum -a 256 ./dist/query-tee-linux-amd64 | cut -d ' ' -f 1 > ./dist/query-tee-linux-amd64-sha-256
246+
247+ # Generate packages for a Cortex release.
248+ FPM_OPTS := fpm -s dir -v $(VERSION ) -n cortex -f \
249+ --license "Apache 2.0" \
250+ --url "https://github.com/cortexproject/cortex"
251+
252+ FPM_ARGS := dist/cortex-linux-amd64=/usr/local/bin/cortex \
253+ docs/configuration/single-process-config.yaml=/etc/cortex/single-process-config.yaml\
254+
255+ PACKAGES := dist/cortex-$(VERSION ) .rpm dist/cortex-$(VERSION ) .deb
256+ PACKAGE_IN_CONTAINER := true
257+ PACKAGE_IMAGE ?= $(IMAGE_PREFIX ) fpm
258+ ifeq ($(PACKAGE_IN_CONTAINER ) , true)
259+
260+ .PHONY : packages
261+ packages : dist/cortex-linux-amd64 packaging/fpm/$(UPTODATE )
262+ @mkdir -p $(shell pwd) /.pkg
263+ @mkdir -p $(shell pwd) /.cache
264+ @echo " >>>> Entering build container: $@ "
265+ @$(SUDO ) time docker run $(RM ) $(TTY ) \
266+ -v $(shell pwd) :/src/github.com/cortexproject/cortex:delegated \
267+ -i $(PACKAGE_IMAGE ) $@ ;
268+
269+ else
270+
271+ packages : $(PACKAGES )
272+
273+ dist/% .deb : dist/cortex-linux-amd64 $(wildcard packaging/deb/** )
274+ $(FPM_OPTS ) -t deb \
275+ --after-install packaging/deb/control/postinst \
276+ --before-remove packaging/deb/control/prerm \
277+ --package $@ $(FPM_ARGS ) \
278+ packaging/deb/default/cortex=/etc/default/cortex \
279+ packaging/deb/systemd/cortex.service=/etc/systemd/system/cortex.service
280+
281+ dist/% .rpm : dist/cortex-linux-amd64 $(wildcard packaging/rpm/** )
282+ $(FPM_OPTS ) -t rpm \
283+ --after-install packaging/rpm/control/post \
284+ --before-remove packaging/rpm/control/preun \
285+ --package $@ $(FPM_ARGS ) \
286+ packaging/rpm/sysconfig/cortex=/etc/sysconfig/cortex \
287+ packaging/rpm/systemd/cortex.service=/etc/systemd/system/cortex.service
288+ endif
289+
290+ .PHONY : test-packages
291+ test-packages : packages packaging/rpm/centos-systemd/$(UPTODATE ) packaging/deb/debian-systemd/$(UPTODATE )
292+ ./tools/packaging/test-packages $(IMAGE_PREFIX ) $(VERSION )
0 commit comments