2019-04-18 14:59:55 +00:00
|
|
|
# UID/GID
|
|
|
|
# UID or GID is the UNIX user ID or group ID of the user who executes
|
|
|
|
# make. If the UID or GID is not passed as a make variable, an attempt
|
|
|
|
# is made to determine it.
|
2019-05-12 09:57:53 +00:00
|
|
|
UID?=$(shell id --user)
|
|
|
|
GID?=$(shell id --group)
|
2019-04-18 14:59:55 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# VERSION/RELEASE
|
2019-04-18 14:59:55 +00:00
|
|
|
# If no version is specified as a parameter of make, the last git hash
|
|
|
|
# value is taken.
|
2019-09-04 11:37:50 +00:00
|
|
|
VERSION?=$(shell git describe --abbrev=0)+hash.$(shell git rev-parse --short HEAD)
|
|
|
|
RELEASE?=1
|
|
|
|
|
2019-09-04 11:53:58 +00:00
|
|
|
# CONTAINER_IMAGE_VERSION
|
|
|
|
# Defines the version of the container image which has included the executable
|
|
|
|
# binary. This is somethimes different to the variable VERSION, because the
|
|
|
|
# container image version should be latest instead contains the latest git tag
|
|
|
|
# and hash sum.
|
|
|
|
CONTAINER_IMAGE_VERSION:=$(or ${VERSION}, latest)
|
|
|
|
|
|
|
|
# CONTAINER_RUNTIME/BUILD_IMAGE
|
|
|
|
# The CONTAINER_RUNTIME variable will be used to specified the path to a
|
|
|
|
# container runtime. This is needed to start and run a container image defined
|
|
|
|
# by the BUILD_IMAGE variable. The BUILD_IMAGE container serve as build
|
|
|
|
# environment to execute the different make steps inside. Therefore, the bulid
|
|
|
|
# environment requires all necessary dependancies to build this project.
|
2019-06-16 21:39:07 +00:00
|
|
|
CONTAINER_RUNTIME?=$(shell which docker)
|
2019-09-04 11:53:58 +00:00
|
|
|
BUILD_IMAGE:=volkerraschek/build-image:latest
|
2019-06-16 21:39:07 +00:00
|
|
|
|
2019-08-26 06:26:37 +00:00
|
|
|
# GH_USER/GITHUB_TOKEN
|
|
|
|
# It's the user name from github.com and his token. This token and the username
|
2019-09-04 11:53:58 +00:00
|
|
|
# can be set over encrypted environment variables in the ci/cd pipeline. It's
|
|
|
|
# necessary to push the releases on github.com
|
2019-08-26 06:26:37 +00:00
|
|
|
GITHUB_USER=volker-raschek
|
|
|
|
GITHUB_TOKEN?=""
|
|
|
|
|
|
|
|
# EXECUTABLE
|
|
|
|
# Executable binary which should be compiled for different architecures
|
|
|
|
EXECUTABLE:=flucky
|
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# DARWIN_EXECUTABLES AND TARGETS
|
|
|
|
DARWIN_EXECUTABLES:=\
|
|
|
|
darwin/386/${EXECUTABLE} \
|
|
|
|
darwin/amd64/${EXECUTABLE}
|
|
|
|
|
|
|
|
DARWIN_EXECUTABLE_TARGETS:=${DARWIN_EXECUTABLES:%=bin/%}
|
|
|
|
|
|
|
|
# FREEBSD_EXECUTABLES AND TARGETS
|
|
|
|
FREEBSD_EXECUTABLES:= \
|
|
|
|
freebsd/amd64/${EXECUTABLE}
|
|
|
|
|
|
|
|
FREEBSD_EXECUTABLE_TARGETS:=${FREEBSD_EXECUTABLES:%=bin/%}
|
|
|
|
|
|
|
|
# LINUX_EXECUTABLES AND TARGETS
|
|
|
|
LINUX_EXECUTABLES:= \
|
|
|
|
linux/amd64/${EXECUTABLE} \
|
|
|
|
linux/386/${EXECUTABLE} \
|
|
|
|
linux/arm/5/${EXECUTABLE} \
|
|
|
|
linux/arm/7/${EXECUTABLE}
|
|
|
|
|
|
|
|
LINUX_EXECUTABLE_TARGETS:=${LINUX_EXECUTABLES:%=bin/%}
|
|
|
|
|
|
|
|
# UNIX_EXECUTABLES AND TARGETS
|
2019-08-26 06:26:37 +00:00
|
|
|
# Define all executables for different architectures and operation systems
|
2019-09-04 11:37:50 +00:00
|
|
|
UNIX_EXECUTABLES:= \
|
|
|
|
${DARWIN_EXECUTABLES} \
|
|
|
|
${FREEBSD_EXECUTABLES} \
|
|
|
|
${LINUX_EXECUTABLES}
|
|
|
|
|
|
|
|
UNIX_EXECUTABLE_TARGETS:= \
|
|
|
|
${DARWIN_EXECUTABLE_TARGETS} \
|
|
|
|
${FREEBSD_EXECUTABLE_TARGETS} \
|
|
|
|
${LINUX_EXECUTABLE_TARGETS}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
|
|
|
# EXECUTABLE_TARGETS
|
2019-09-04 11:37:50 +00:00
|
|
|
# Include all UNIX and Windows targets.
|
|
|
|
EXECUTABLE_TARGETS:= \
|
|
|
|
${UNIX_EXECUTABLE_TARGETS}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
|
|
|
# COMPRSSED_EXECUTABLES
|
|
|
|
# Append to all defined executables the compression extentions to detect the
|
|
|
|
# different make steps which compress the binary
|
2019-09-04 11:37:50 +00:00
|
|
|
COMPRESSED_EXECUTABLES:= \
|
|
|
|
${UNIX_EXECUTABLES:%=%.tar.bz2} \
|
|
|
|
${UNIX_EXECUTABLES:%=%.tar.gz} \
|
|
|
|
${UNIX_EXECUTABLES:%=%.tar.xz} \
|
|
|
|
${UNIX_EXECUTABLES:%=%.zip}
|
|
|
|
COMPRESSED_EXECUTABLE_TARGETS:=${COMPRESSED_EXECUTABLES:%=bin/%}
|
|
|
|
|
|
|
|
# RPM_TARGETS
|
|
|
|
RPM_EXECUTABLES:=${LINUX_EXECUTABLES:%=%.rpm}
|
|
|
|
RPM_EXECUTABLE_TARGETS:=${RPM_EXECUTABLES:%=bin/%}
|
|
|
|
|
|
|
|
# RELEASE_TARGETS
|
|
|
|
RELEASE_EXECUTABLES:= \
|
|
|
|
${COMPRESSED_EXECUTABLE_TARGETS} \
|
|
|
|
${RPM_EXECUTABLE_TARGETS}
|
|
|
|
|
|
|
|
RELEASE_EXECUTABLE_TARGETS:= \
|
|
|
|
${COMPRESSED_EXECUTABLE_TARGETS:%=release/%} \
|
|
|
|
${RPM_EXECUTABLE_TARGETS:%=release/%}
|
|
|
|
|
|
|
|
# BINARIES
|
|
|
|
# ==============================================================================
|
|
|
|
# current os
|
|
|
|
${EXECUTABLE}: bindata
|
|
|
|
CGO_ENABLED=0 go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
|
|
|
|
|
|
|
# build all binaries
|
|
|
|
PHONY:=all
|
2019-08-26 13:12:32 +00:00
|
|
|
all: ${EXECUTABLE_TARGETS}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# darwin os
|
|
|
|
bin/darwin/386/${EXECUTABLE}: bindata
|
|
|
|
CGO_ENABLED=0 GOARCH=386 GOOS=darwin go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
bin/darwin/amd64/${EXECUTABLE}: bindata
|
|
|
|
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# freebsd os
|
|
|
|
bin/freebsd/amd64/${EXECUTABLE}: bindata
|
|
|
|
CGO_ENABLED=0 GOARCH=amd64 GOOS=freebsd go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# linux os
|
|
|
|
bin/linux/386/${EXECUTABLE}: bindata
|
|
|
|
CGO_ENABLED=0 GOARCH=386 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
2019-06-14 19:35:13 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
bin/linux/amd64/${EXECUTABLE}: bindata
|
|
|
|
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-08-26 13:12:32 +00:00
|
|
|
bin/linux/arm/5/${EXECUTABLE}: bindata
|
2019-09-04 11:37:50 +00:00
|
|
|
CGO_ENABLED=0 GOARM=5 GOARCH=arm GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
2019-08-26 13:12:32 +00:00
|
|
|
|
|
|
|
bin/linux/arm/7/${EXECUTABLE}: bindata
|
2019-09-04 11:37:50 +00:00
|
|
|
CGO_ENABLED=0 GOARM=7 GOARCH=arm GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# GO-BINDATA
|
|
|
|
# ==============================================================================
|
2019-06-14 19:35:13 +00:00
|
|
|
bindata:
|
2019-09-04 11:37:50 +00:00
|
|
|
go-bindata -pkg db -o ./pkg/storage/db/bindataSQL.go ./pkg/storage/db/sql/*** ./pkg/storage/db/sql/psql/schema/***
|
|
|
|
go-bindata -pkg goldenfiles -o ./test/goldenfiles/bindata.go ./test/goldenfiles/json
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# TEST
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=test test-update-all
|
2019-08-26 06:26:37 +00:00
|
|
|
test: ${EXECUTABLE}
|
2019-09-04 11:37:50 +00:00
|
|
|
go test -v ./...
|
|
|
|
|
|
|
|
test-update-all: ${EXECUTABLE}
|
|
|
|
go test -v ./pkg/... -update all
|
|
|
|
|
|
|
|
# PACKAGES
|
|
|
|
# ==============================================================================
|
|
|
|
%.rpm: %
|
|
|
|
rpm-builder \
|
|
|
|
--exec-file "$<:/usr/bin/${EXECUTABLE}" \
|
|
|
|
--dir "systemd:/usr/lib/systemd/system" \
|
|
|
|
--license AGFA_PROPERTERY \
|
|
|
|
--version ${VERSION} \
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--out $@ \
|
|
|
|
${EXECUTABLE}
|
|
|
|
|
|
|
|
# RELEASE
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=release/all
|
|
|
|
release/all: clean ${RELEASE_EXECUTABLES}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
|
|
|
github-release release \
|
|
|
|
--user ${GITHUB_USER} \
|
|
|
|
--repo ${EXECUTABLE} \
|
|
|
|
--tag ${VERSION}
|
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
$(foreach FILE,${RELEASE_EXECUTABLES},github-release upload --user ${GITHUB_USER} --repo ${EXECUTABLE} --tag ${VERSION} --name $(subst /,-,${FILE}) --file bin/${FILE} --replace;)
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
PHONY+=${RELEASE_EXECUTABLE_TARGETS}
|
|
|
|
${RELEASE_EXECUTABLE_TARGETS}: clean
|
|
|
|
$(MAKE) $(subst release/,,$@)
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
github-release release \
|
|
|
|
--user ${GITHUB_USER} \
|
|
|
|
--repo ${EXECUTABLE} \
|
|
|
|
--tag ${VERSION}
|
2019-06-15 17:12:27 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
github-release upload \
|
|
|
|
--user ${GITHUB_USER} \
|
|
|
|
--repo ${EXECUTABLE} \
|
|
|
|
--tag ${VERSION} \
|
|
|
|
--name $(subst /,-,$(subst release/bin/,,$@)) \
|
|
|
|
--file $(subst release/,,$@) \
|
|
|
|
--replace
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# COMPRESSION
|
|
|
|
# ==============================================================================
|
|
|
|
%.tar.bz2: %
|
|
|
|
tar --create --bzip2 --file "$@" "$<"
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
%.tar.gz: %
|
|
|
|
tar --create --gunzip --file "$@" "$<"
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
%.tar.xz: %
|
|
|
|
tar --create --xz --file "$@" "$<"
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
%.zip: %
|
|
|
|
zip "$@" "$<"
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# OTHER STUFF
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=clean
|
|
|
|
clean:
|
|
|
|
rm ${EXECUTABLE} || true
|
|
|
|
rm ${EXECUTABLE}.* || true
|
|
|
|
rm --recursive --force bin/ || true
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-08-25 14:31:52 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# CONTAINER IMAGE STEPS
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=container-image/build/amd64
|
|
|
|
container-image/build/amd64: bin/linux/amd64/${EXECUTABLE}
|
|
|
|
${CONTAINER_RUNTIME} build \
|
|
|
|
--tag volkerraschek/${EXECUTABLE}:${IMAGE_VERSION} \
|
|
|
|
.
|
|
|
|
|
|
|
|
PHONY+=container-image/push/amd64
|
|
|
|
container-image/push/amd64: container-image/build/amd64
|
|
|
|
${CONTAINER_RUNTIME} push volkerraschek/${EXECUTABLE}:${IMAGE_VERSION}
|
|
|
|
|
|
|
|
# CONTAINER STEPS - BINARY
|
|
|
|
# ==============================================================================
|
|
|
|
# current os
|
|
|
|
PHONY+=container-run/${EXECUTABLE}
|
|
|
|
container-run/${EXECUTABLE}:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# build all binaries for any operating system
|
|
|
|
PHONY+=container-run/all
|
|
|
|
container-run/all:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
PHONY+=${UNIX_EXECUTABLE_TARGETS:%=container-run/%}
|
|
|
|
${UNIX_EXECUTABLE_TARGETS:%=container-run/%}:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - GO-BINDATA
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=container-run/bindata
|
|
|
|
container-run/bindata:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - TEST
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=container-run/test
|
|
|
|
container-run/test:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
PHONY+=container-run/test-update-all
|
|
|
|
container-run/test-update-all:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - COMPRESSED BINARIES AND PACKAGES
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=${COMPRESSED_EXECUTABLE_TARGETS:%=container-run/%}
|
|
|
|
${COMPRESSED_EXECUTABLE_TARGETS:%=container-run/%}:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
PHONY+=${RPM_EXECUTABLE_TARGETS:%=container-run/%}
|
|
|
|
${RPM_EXECUTABLE_TARGETS:%=container-run/%}:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - RELEASE COMPRESSED BINARIES AND PACKAGES
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=${RELEASE_EXECUTABLE_TARGETS%=container-run/%}
|
|
|
|
${RELEASE_EXECUTABLE_TARGETS:%=container-run/%}:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - OTHER STUF
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=container-run/clean
|
|
|
|
container-run/clean:
|
2019-09-04 12:04:02 +00:00
|
|
|
$(MAKE) container-run COMMAND=$(subst container-run/,,$@)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# GENERAL CONTAINER COMMAND
|
|
|
|
# ==============================================================================
|
2019-09-04 12:04:02 +00:00
|
|
|
PHONY+=container-run
|
|
|
|
container-run:
|
2019-06-16 21:39:07 +00:00
|
|
|
${CONTAINER_RUNTIME} run \
|
|
|
|
--rm \
|
2019-08-25 14:31:52 +00:00
|
|
|
--volume ${PWD}:/workspace \
|
|
|
|
${BUILD_IMAGE} \
|
|
|
|
make ${COMMAND} \
|
|
|
|
UID=${UID} \
|
|
|
|
GID=${GID} \
|
|
|
|
VERSION=${VERSION} \
|
2019-09-04 11:37:50 +00:00
|
|
|
RELEASE=${RELEASE}
|
|
|
|
|
|
|
|
# REMOTE
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=${FLUCKY_REMOTE:%=remote/%}
|
|
|
|
remote/${FLUCKY_REMOTE}: bin/linux/arm/7/${EXECUTABLE}
|
|
|
|
scp bin/linux/arm/7/${EXECUTABLE} root@${FLUCKY_REMOTE}:/usr/local/bin/${EXECUTABLE}
|
|
|
|
ssh root@${FLUCKY_REMOTE} 'chmod +x /usr/local/bin/${EXECUTABLE}'
|
2019-06-11 18:07:55 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# PHONY
|
|
|
|
# ==============================================================================
|
|
|
|
# Declare the contents of the PHONY variable as phony. We keep that information
|
|
|
|
# in a variable so we can use it in if_changed.
|
|
|
|
.PHONY: ${PHONY}
|