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.
|
2020-01-09 20:50:27 +00:00
|
|
|
VERSION?=$(shell git describe --abbrev=0)+$(shell date +'%Y%m%d%H%I%S')
|
2019-09-04 11:37:50 +00:00
|
|
|
RELEASE?=1
|
|
|
|
|
2020-01-09 20:50:27 +00:00
|
|
|
# GOPROXY settings
|
|
|
|
# If no GOPROXY environment variable available, the pre-defined GOPROXY from go
|
|
|
|
# env to download and validate go modules is used. Exclude downloading and
|
|
|
|
# validation of all private modules which are pre-defined in GOPRIVATE. If no
|
|
|
|
# GOPRIVATE variable defined, the variable of go env is used.
|
|
|
|
GOPROXY?=$(shell go env GOPROXY)
|
|
|
|
GOPRIVATE?=$(shell go env GOPRIVATE)
|
2019-06-16 21:39:07 +00:00
|
|
|
|
2019-08-26 06:26:37 +00:00
|
|
|
# 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}
|
|
|
|
|
2019-10-11 10:36:00 +00:00
|
|
|
DARWIN_EXECUTABLE_TARGETS:=\
|
|
|
|
${DARWIN_EXECUTABLES:%=bin/%}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# FREEBSD_EXECUTABLES AND TARGETS
|
2019-10-11 10:36:00 +00:00
|
|
|
FREEBSD_EXECUTABLES:=\
|
2019-09-04 11:37:50 +00:00
|
|
|
freebsd/amd64/${EXECUTABLE}
|
|
|
|
|
2019-10-11 10:36:00 +00:00
|
|
|
FREEBSD_EXECUTABLE_TARGETS:=\
|
|
|
|
${FREEBSD_EXECUTABLES:%=bin/%}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# LINUX_EXECUTABLES AND TARGETS
|
2019-10-11 10:36:00 +00:00
|
|
|
LINUX_EXECUTABLES:=\
|
2019-09-04 11:37:50 +00:00
|
|
|
linux/amd64/${EXECUTABLE} \
|
|
|
|
linux/386/${EXECUTABLE} \
|
|
|
|
linux/arm/5/${EXECUTABLE} \
|
|
|
|
linux/arm/7/${EXECUTABLE}
|
|
|
|
|
2019-10-11 10:36:00 +00:00
|
|
|
LINUX_EXECUTABLE_TARGETS:=\
|
|
|
|
${LINUX_EXECUTABLES:%=bin/%}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
2019-10-11 10:36:00 +00:00
|
|
|
# EXECUTABLES AND TARGETS
|
2019-09-04 11:37:50 +00:00
|
|
|
# Include all UNIX and Windows targets.
|
2019-10-11 10:36:00 +00:00
|
|
|
EXECUTABLES:=\
|
|
|
|
${UNIX_EXECUTABLES}
|
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
EXECUTABLE_TARGETS:= \
|
|
|
|
${UNIX_EXECUTABLE_TARGETS}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2020-01-19 13:15:38 +00:00
|
|
|
# CONTAINER_RUNTIME
|
2020-01-09 20:50:27 +00:00
|
|
|
# The CONTAINER_RUNTIME variable will be used to specified the path to a
|
2020-01-19 13:15:38 +00:00
|
|
|
# container runtime. This is needed to start and run a container images.
|
2020-01-09 20:50:27 +00:00
|
|
|
CONTAINER_RUNTIME?=$(shell which docker)
|
|
|
|
|
|
|
|
# BUILD_IMAGE
|
2020-01-19 13:15:38 +00:00
|
|
|
# Definition of the container build image, in which the BInary are compiled from
|
|
|
|
# source code
|
|
|
|
BUILD_IMAGE_REGISTRY:=docker.io
|
|
|
|
BUILD_IMAGE_NAMESPACE:=volkerraschek
|
|
|
|
BUILD_IMAGE_NAME:=build-image
|
|
|
|
BUILD_IMAGE_VERSION:=latest
|
|
|
|
BUILD_IMAGE_FULL=${BUILD_IMAGE_REGISTRY}/${BUILD_IMAGE_NAMESPACE}/${BUILD_IMAGE_NAME}:${BUILD_IMAGE_VERSION:v%=%}
|
|
|
|
BUILD_IMAGE_SHORT=${BUILD_IMAGE_NAMESPACE}/${BUILD_IMAGE_NAME}:${BUILD_IMAGE_VERSION:v%=%}
|
2020-01-09 20:50:27 +00:00
|
|
|
|
|
|
|
# BASE_IMAGE
|
2020-01-19 13:15:38 +00:00
|
|
|
# Definition of the base container image for flucky
|
|
|
|
BASE_IMAGE_REGISTRY:=docker.io
|
|
|
|
BASE_IMAGE_NAMESPACE:=library
|
|
|
|
BASE_IMAGE_NAME:=alpine
|
|
|
|
BASE_IMAGE_VERSION:=3.11.2
|
|
|
|
BASE_IMAGE_FULL=${BASE_IMAGE_REGISTRY}/${BASE_IMAGE_NAMESPACE}/${BASE_IMAGE_NAME}:${BASE_IMAGE_VERSION:v%=%}
|
|
|
|
BASE_IMAGE_SHORT=${BASE_IMAGE_NAMESPACE}/${BASE_IMAGE_NAME}:${BASE_IMAGE_VERSION:v%=%}
|
|
|
|
|
|
|
|
# CONTAINER_IMAGE
|
|
|
|
# Definition of the container image for flucky
|
|
|
|
CONTAINER_IMAGE_REGISTRY:=docker.io
|
|
|
|
CONTAINER_IMAGE_NAMESPACE:=volkerraschek
|
2020-01-09 20:50:27 +00:00
|
|
|
CONTAINER_IMAGE_NAME:=${EXECUTABLE}
|
|
|
|
CONTAINER_IMAGE_VERSION:=latest
|
2020-01-19 13:15:38 +00:00
|
|
|
CONTAINER_IMAGE_FULL=${CONTAINER_IMAGE_REGISTRY}/${CONTAINER_IMAGE_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION:v%=%}
|
|
|
|
CONTAINER_IMAGE_SHORT=${CONTAINER_IMAGE_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION:v%=%}
|
2020-01-09 20:50:27 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# BINARIES
|
|
|
|
# ==============================================================================
|
|
|
|
# current os
|
2020-01-09 20:50:27 +00:00
|
|
|
${EXECUTABLE}: bin/tmp/${EXECUTABLE}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# 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
|
2020-05-21 15:40:24 +00:00
|
|
|
CGO_ENABLED=1 \
|
2020-01-09 20:50:27 +00:00
|
|
|
GOOS=darwin \
|
|
|
|
GOARCH=386 \
|
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
|
|
|
go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
bin/darwin/amd64/${EXECUTABLE}: bindata
|
2020-05-21 15:40:24 +00:00
|
|
|
CGO_ENABLED=1 \
|
2020-01-09 20:50:27 +00:00
|
|
|
GOOS=darwin \
|
|
|
|
GOARCH=amd64 \
|
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
|
|
|
go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# freebsd os
|
|
|
|
bin/freebsd/amd64/${EXECUTABLE}: bindata
|
2020-05-21 15:40:24 +00:00
|
|
|
CGO_ENABLED=1 \
|
2020-01-09 20:50:27 +00:00
|
|
|
GOOS=freebsd \
|
|
|
|
GOARCH=amd64 \
|
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
|
|
|
go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# linux os
|
|
|
|
bin/linux/386/${EXECUTABLE}: bindata
|
2020-05-21 15:40:24 +00:00
|
|
|
CGO_ENABLED=1 \
|
2020-01-09 20:50:27 +00:00
|
|
|
GOOS=linux \
|
|
|
|
GOARCH=386 \
|
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
|
|
|
go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
|
2019-06-14 19:35:13 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
bin/linux/amd64/${EXECUTABLE}: bindata
|
2020-05-21 15:40:24 +00:00
|
|
|
CGO_ENABLED=1 \
|
2020-01-09 20:50:27 +00:00
|
|
|
GOOS=linux \
|
|
|
|
GOARCH=amd64 \
|
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
|
|
|
go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-08-26 13:12:32 +00:00
|
|
|
bin/linux/arm/5/${EXECUTABLE}: bindata
|
2020-05-21 15:40:24 +00:00
|
|
|
CGO_ENABLED=1 \
|
2020-01-09 20:50:27 +00:00
|
|
|
GOOS=linux \
|
|
|
|
GOARCH=arm \
|
|
|
|
GOARM=5 \
|
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
|
|
|
go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
|
2019-08-26 13:12:32 +00:00
|
|
|
|
|
|
|
bin/linux/arm/7/${EXECUTABLE}: bindata
|
2020-05-21 15:40:24 +00:00
|
|
|
CGO_ENABLED=1 \
|
2020-01-09 20:50:27 +00:00
|
|
|
GOOS=linux \
|
|
|
|
GOARCH=arm \
|
|
|
|
GOARM=7 \
|
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
|
|
|
go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
|
|
|
|
|
|
|
|
bin/tmp/${EXECUTABLE}: bindata
|
2020-05-21 15:40:24 +00:00
|
|
|
CGO_ENABLED=1 \
|
2020-01-09 20:50:27 +00:00
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
|
|
|
go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# GO-BINDATA
|
|
|
|
# ==============================================================================
|
2020-01-09 20:50:27 +00:00
|
|
|
BINDATA_TARGETS := \
|
2020-05-21 15:40:24 +00:00
|
|
|
pkg/repository/db/bindataSQL.go \
|
2020-01-09 20:50:27 +00:00
|
|
|
|
|
|
|
PHONY+=bindata
|
2020-05-03 12:04:08 +00:00
|
|
|
bindata: clean ${BINDATA_TARGETS}
|
2020-01-09 20:50:27 +00:00
|
|
|
|
2020-05-21 15:40:24 +00:00
|
|
|
pkg/repository/db/bindataSQL.go:
|
|
|
|
go-bindata -pkg db -o ./pkg/repository/db/bindataSQL.go pkg/repository/db/postgres/*** pkg/repository/db/sqlite3/***
|
2019-08-26 06:26:37 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# TEST
|
|
|
|
# ==============================================================================
|
2020-01-10 21:09:24 +00:00
|
|
|
PHONY+=test/unit
|
|
|
|
test/unit: clean bindata
|
2020-01-19 14:15:00 +00:00
|
|
|
go test -v -race -coverprofile=coverage.txt -covermode=atomic $(shell go list ./... | grep -v db)
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# PACKAGES
|
|
|
|
# ==============================================================================
|
|
|
|
%.rpm: %
|
|
|
|
rpm-builder \
|
|
|
|
--exec-file "$<:/usr/bin/${EXECUTABLE}" \
|
|
|
|
--dir "systemd:/usr/lib/systemd/system" \
|
2019-12-08 14:15:26 +00:00
|
|
|
--license "Apache 2.0" \
|
2020-01-09 20:50:27 +00:00
|
|
|
--version ${VERSION:v%=%} \
|
2019-09-04 11:37:50 +00:00
|
|
|
--release ${RELEASE} \
|
2019-12-08 14:15:26 +00:00
|
|
|
--out ${@} \
|
2019-09-04 11:37:50 +00:00
|
|
|
${EXECUTABLE}
|
|
|
|
|
|
|
|
# OTHER STUFF
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=clean
|
|
|
|
clean:
|
2020-01-09 20:50:27 +00:00
|
|
|
rm --force ${BINDATA_TARGETS} || true
|
|
|
|
rm --force --recursive bin/ || true
|
2019-08-26 13:12:32 +00:00
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
# CONTAINER IMAGE STEPS
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=container-image/build/amd64
|
2020-01-09 20:50:27 +00:00
|
|
|
container-image/build/amd64:
|
2019-09-04 11:37:50 +00:00
|
|
|
${CONTAINER_RUNTIME} build \
|
2020-01-19 13:15:38 +00:00
|
|
|
--build-arg BASE_IMAGE=${BASE_IMAGE_FULL} \
|
|
|
|
--build-arg BUILD_IMAGE=${BUILD_IMAGE_FULL} \
|
2020-01-09 20:50:27 +00:00
|
|
|
--build-arg EXECUTABLE=${EXECUTABLE} \
|
|
|
|
--build-arg EXECUTABLE_TARGET=bin/linux/amd64/${EXECUTABLE} \
|
|
|
|
--build-arg GOPROXY=${GOPROXY} \
|
|
|
|
--build-arg GOPRIVATE=${GOPRIVATE} \
|
|
|
|
--build-arg VERSION=${VERSION} \
|
|
|
|
--file Dockerfile \
|
|
|
|
--no-cache \
|
2020-01-19 13:15:38 +00:00
|
|
|
--tag ${CONTAINER_IMAGE_FULL} \
|
|
|
|
--tag ${CONTAINER_IMAGE_SHORT} \
|
2019-09-04 11:37:50 +00:00
|
|
|
.
|
|
|
|
|
|
|
|
PHONY+=container-image/push/amd64
|
|
|
|
container-image/push/amd64: container-image/build/amd64
|
2020-01-21 17:26:22 +00:00
|
|
|
${CONTAINER_RUNTIME} login ${CONTAINER_IMAGE_REGISTRY} \
|
|
|
|
--username ${CONTAINER_IMAGE_REGISTRY_USER} \
|
|
|
|
--password ${CONTAINER_IMAGE_REGISTRY_PASSWORD}
|
2020-01-19 13:15:38 +00:00
|
|
|
${CONTAINER_RUNTIME} push ${CONTAINER_IMAGE_FULL}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - BINARY
|
|
|
|
# ==============================================================================
|
|
|
|
# current os
|
|
|
|
PHONY+=container-run/${EXECUTABLE}
|
|
|
|
container-run/${EXECUTABLE}:
|
2019-12-08 14:15:26 +00:00
|
|
|
$(MAKE) container-run COMMAND=${@: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-12-08 14:15:26 +00:00
|
|
|
$(MAKE) container-run COMMAND=${@:container-run/%=%}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
PHONY+=${UNIX_EXECUTABLE_TARGETS:%=container-run/%}
|
|
|
|
${UNIX_EXECUTABLE_TARGETS:%=container-run/%}:
|
2019-12-08 14:15:26 +00:00
|
|
|
$(MAKE) container-run COMMAND=${@:container-run/%=%}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - GO-BINDATA
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=container-run/bindata
|
|
|
|
container-run/bindata:
|
2019-12-08 14:15:26 +00:00
|
|
|
$(MAKE) container-run COMMAND=${@:container-run/%=%}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - TEST
|
|
|
|
# ==============================================================================
|
2020-01-19 14:15:00 +00:00
|
|
|
PHONY+=container-run/test/unit
|
|
|
|
container-run/test/unit:
|
2019-12-08 14:15:26 +00:00
|
|
|
$(MAKE) container-run COMMAND=${@:container-run/%=%}
|
2019-09-04 11:37:50 +00:00
|
|
|
|
|
|
|
# CONTAINER STEPS - OTHER STUF
|
|
|
|
# ==============================================================================
|
|
|
|
PHONY+=container-run/clean
|
|
|
|
container-run/clean:
|
2019-12-08 14:15:26 +00:00
|
|
|
$(MAKE) container-run COMMAND=${@: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 \
|
2020-01-19 13:15:38 +00:00
|
|
|
${BUILD_IMAGE_FULL} \
|
2019-08-25 14:31:52 +00:00
|
|
|
make ${COMMAND} \
|
2020-01-19 13:15:38 +00:00
|
|
|
GOPROXY=${GOPROXY} \
|
|
|
|
GOPRIVATE=${GOPRIVATE} \
|
2020-01-09 20:50:27 +00:00
|
|
|
VERSION=${VERSION:v%=%} \
|
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}
|
2020-05-03 12:04:08 +00:00
|
|
|
# ssh root@${FLUCKY_REMOTE} 'mkdir --parent /etc/bash_completion.d || true'
|
|
|
|
# ssh root@${FLUCKY_REMOTE} 'flucky completion bash > /etc/bash_completion.d/flucky.sh && chmod +x /etc/bash_completion.d/flucky.sh'
|
|
|
|
# ssh root@${FLUCKY_REMOTE} 'flucky completion zsh > /etc/bash_completion.d/flucky.zsh && chmod +x /etc/bash_completion.d/flucky.zsh'
|
2019-09-04 11:37:50 +00:00
|
|
|
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}
|