docker-hub-description-updater/Makefile

171 lines
5.6 KiB
Makefile
Raw Normal View History

# VERSION
2019-09-16 19:36:27 +00:00
# If no version is specified as a parameter of make, the last git hash
# value is taken.
# VERSION?=$(shell git describe --abbrev=0)+hash.$(shell git rev-parse --short HEAD)
VERSION?=0.0.0+hash.$(shell git rev-parse --short HEAD)
2019-09-16 19:36:27 +00:00
2019-11-12 20:57:42 +00:00
# GO SETTINGS
# Defines a proxy server to download dependent libraries. If no proxy is
# defined, "direct" is used. See configuration options:
# - https://golang.org/cmd/go/#hdr-Module_downloading_and_verification
# - go help module-private
GOPROXY?=direct
2019-09-16 19:36:27 +00:00
# EXECUTABLE
# Executable binary which should be compiled for different architecures
EXECUTABLE:=dhdu
# LINUX_EXECUTABLES AND TARGETS
LINUX_EXECUTABLES:=\
linux/amd64/${EXECUTABLE} \
linux/arm/5/${EXECUTABLE} \
linux/arm/7/${EXECUTABLE}
2019-09-16 19:36:27 +00:00
LINUX_EXECUTABLE_TARGETS:=${LINUX_EXECUTABLES:%=bin/%}
# UNIX_EXECUTABLES AND TARGETS
# Define all executables for different architectures and operation systems
UNIX_EXECUTABLES:=\
${LINUX_EXECUTABLES}
UNIX_EXECUTABLE_TARGETS:=\
${LINUX_EXECUTABLE_TARGETS}
# EXECUTABLE_TARGETS
# Include all UNIX and Windows targets.
EXECUTABLES:=\
${UNIX_EXECUTABLES}
EXECUTABLE_TARGETS:=\
${UNIX_EXECUTABLE_TARGETS}
# 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.
CONTAINER_RUNTIME?=$(shell which docker)
BUILD_IMAGE:=volkerraschek/build-image:latest
# REGISTRY_MIRROR / REGISTRY_NAMESPACE
# The REGISTRY_MIRROR variable contains the name of the registry server to push
# on or pull from container images. The REGISTRY_NAMESPACE defines the Namespace
# where the CONTAINER_RUNTIME will be search for container images or push them
# onto. The most time it's the same as REGISTRY_USER.
2019-09-24 12:57:25 +00:00
REGISTRY_USER:=volkerraschek
2019-09-16 19:36:27 +00:00
REGISTRY_MIRROR=docker.io
REGISTRY_NAMESPACE:=${REGISTRY_USER}
2019-09-24 12:57:25 +00:00
2019-09-16 19:36:27 +00:00
# CONTAINER_IMAGE_VERSION / CONTAINER_IMAGE_NAME / CONTAINER_IMAGE
# Defines the name of the new container to be built using several variables.
BASE_IMAGE=busybox:latest
2019-09-16 19:36:27 +00:00
CONTAINER_IMAGE_NAME=${EXECUTABLE}
CONTAINER_IMAGE_VERSION?=latest
CONTAINER_IMAGE=${REGISTRY_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION}
2019-09-16 19:36:27 +00:00
README_FILE:=README.md
# BINARIES
# ==============================================================================
PHONY:=all
${EXECUTABLE}: bin/tmp/${EXECUTABLE}
2019-09-16 19:36:27 +00:00
all: ${EXECUTABLE_TARGETS}
bin/linux/amd64/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
2019-09-16 19:36:27 +00:00
bin/linux/arm/5/${EXECUTABLE}: bindata
2019-11-12 21:02:20 +00:00
CGO_ENABLED=0 GOARM=5 GOARCH=arm GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
2019-09-16 19:36:27 +00:00
bin/linux/arm/7/${EXECUTABLE}: bindata
2019-11-12 21:02:20 +00:00
CGO_ENABLED=0 GOARM=7 GOARCH=arm GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
2019-09-16 19:36:27 +00:00
bin/tmp/${EXECUTABLE}: bindata
go build -ldflags "-X main.version=${VERSION}" -o ${@}
2019-09-16 19:36:27 +00:00
# BINDATA
# ==============================================================================
BINDATA_TARGETS := \
pkg/hub/bindata.go
2019-09-16 19:36:27 +00:00
PHONY+=bindata
bindata: ${BINDATA_TARGETS}
pkg/hub/bindata.go:
go-bindata -pkg hub -o ${@} README.md
2019-09-16 19:36:27 +00:00
# TEST
# ==============================================================================
PHONY+=test
test: clean bin/tmp/${EXECUTABLE}
REGISTRY_USER=${REGISTRY_USER} \
REGISTRY_PASSWORD=${REGISTRY_PASSWORD} \
REGISTRY_NAMESPACE=${REGISTRY_NAMESPACE} \
CONTAINER_IMAGE_NAME=${CONTAINER_IMAGE_NAME} \
README_FILE=${README_FILE} \
go test -v ./pkg/...
# CLEAN
# ==============================================================================
PHONY+=clean
clean:
rm --force ${EXECUTABLE} || true
rm --force --recursive bin || true
rm --force --recursive ${BINDATA_TARGETS} || true
# CONTAINER IMAGE STEPS
# ==============================================================================
container-image/build:
${CONTAINER_RUNTIME} build \
--build-arg BASE_IMAGE=${BASE_IMAGE} \
--build-arg BUILD_IMAGE=${BUILD_IMAGE} \
--build-arg EXECUTABLE_TARGET=bin/linux/amd64/${EXECUTABLE} \
--build-arg GOPROXY=${GOPROXY} \
--build-arg VERSION=${VERSION} \
--no-cache \
--tag ${CONTAINER_IMAGE} \
--tag ${REGISTRY_MIRROR}/${CONTAINER_IMAGE} \
2019-09-16 19:36:27 +00:00
.
if [ -f $(shell which docker) ] && [ "${CONTAINER_RUNTIME}" == "$(shell which podman)" ]; then \
podman push ${REGISTRY_MIRROR}/${CONTAINER_IMAGE} docker-daemon:${CONTAINER_IMAGE}; \
fi
container-image/push: container-image/build
2019-09-24 13:17:10 +00:00
${CONTAINER_RUNTIME} login ${REGISTRY_MIRROR} --username ${REGISTRY_USER} --password ${REGISTRY_PASSWORD}
${CONTAINER_RUNTIME} push ${REGISTRY_MIRROR}/${CONTAINER_IMAGE}
2019-09-16 19:36:27 +00:00
# CONTAINER STEPS - BINARY
# ==============================================================================
PHONY+=container-run/all
container-run/all:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
PHONY+=${UNIX_EXECUTABLE_TARGETS:%=container-run/%}
${UNIX_EXECUTABLE_TARGETS:%=container-run/%}:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
# CONTAINER STEPS - CLEAN
# ==============================================================================
PHONY+=container-run/clean
container-run/clean:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
# GENERAL CONTAINER COMMAND
# ==============================================================================
PHONY+=container-run
container-run:
${CONTAINER_RUNTIME} run \
--rm \
--volume ${PWD}:/workspace \
${BUILD_IMAGE} \
make ${COMMAND} \
2019-11-12 20:46:41 +00:00
VERSION=${VERSION} \
GOPROXY=${GOPROXY}
2019-09-16 19:36:27 +00:00
# PHONY
# ==============================================================================
.PHONY: ${PHONY}