fix(travis): build multiple architectures
This commit is contained in:
130
Makefile
130
Makefile
@ -16,41 +16,113 @@ CONTAINER_RUNTIME?=$(shell which docker)
|
||||
# BUILD_IMAGE
|
||||
BUILD_IMAGE:=volkerraschek/build-image:latest
|
||||
|
||||
# GO ENVIRONMENT
|
||||
GOARCH?=amd64
|
||||
GOOS?=linux
|
||||
# GH_USER/GITHUB_TOKEN
|
||||
# It's the user name from github.com and his token. This token and the username
|
||||
# can be set over encrypted environment variables in the ci/cd pipeline
|
||||
GITHUB_USER=volker-raschek
|
||||
GITHUB_TOKEN?=""
|
||||
|
||||
# default build
|
||||
go-build: bindata
|
||||
GOOS=${GOOS} \
|
||||
GOARCH=${GOARCH} \
|
||||
go build -ldflags "-X main.version=${VERSION}"
|
||||
chown ${UID}:${GID} ./*
|
||||
# EXECUTABLE
|
||||
# Executable binary which should be compiled for different architecures
|
||||
EXECUTABLE:=flucky
|
||||
|
||||
go-test: go-build
|
||||
go test -v ./pkg/...
|
||||
# UNIX_EXECUTABLES
|
||||
# Define all executables for different architectures and operation systems
|
||||
UNIX_EXECUTABLES := \
|
||||
darwin/amd64/$(EXECUTABLE) \
|
||||
freebsd/amd64/$(EXECUTABLE) \
|
||||
linux/amd64/$(EXECUTABLE) \
|
||||
linux/arm/5/$(EXECUTABLE) \
|
||||
linux/arm/7/$(EXECUTABLE) \
|
||||
|
||||
rpm-build: go-build
|
||||
rpm-builder \
|
||||
--arch x86_64 \
|
||||
--compression gzip \
|
||||
--exec-file "flucky:/usr/bin/flucky" \
|
||||
--file "systemd/flucky.service:/usr/lib/systemd/system/flucky.service" \
|
||||
--version ${VERSION} \
|
||||
flucky
|
||||
# EXECUTABLE_TARGETS
|
||||
# Include the relative paths to all executables
|
||||
EXECUTABLE_TARGETS=$(UNIX_EXECUTABLES:%=bin/%)
|
||||
|
||||
# COMPRSSED_EXECUTABLES
|
||||
# Append to all defined executables the compression extentions to detect the
|
||||
# different make steps which compress the binary
|
||||
COMPRESSED_EXECUTABLES=$(UNIX_EXECUTABLES:%=%.tar.bz2) $(UNIX_EXECUTABLES:%=%.tar.gz) $(UNIX_EXECUTABLES:%=%.tar.xz)
|
||||
COMPRESSED_EXECUTABLE_TARGETS=$(COMPRESSED_EXECUTABLES:%=bin/%)
|
||||
|
||||
# PHONY
|
||||
# To avoid a conflict with an existing file and a defined make step
|
||||
.PHONY: clean container/${EXECUTABLE_TARGETS} container/test release remote test
|
||||
|
||||
all: ${EXECUTABLE}
|
||||
|
||||
$(EXECUTABLE): bindata
|
||||
go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
bin/tmp/${EXECUTABLE}: bindata
|
||||
go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
# arm
|
||||
bin/linux/arm/5/${EXECUTABLE}: bindata
|
||||
GOARM=5 GOARCH=arm go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
bin/linux/arm/7/${EXECUTABLE}: bindata
|
||||
GOARM=7 GOARCH=arm go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
# 386
|
||||
bin/darwin/386/$(EXECUTABLE): bindata
|
||||
GOARCH=386 GOOS=darwin go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
bin/linux/386/$(EXECUTABLE): bindata
|
||||
GOARCH=386 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
# amd64
|
||||
bin/freebsd/amd64/$(EXECUTABLE): bindata
|
||||
GOARCH=amd64 GOOS=freebsd go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
bin/darwin/amd64/$(EXECUTABLE): bindata
|
||||
GOARCH=amd64 GOOS=darwin go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
bin/linux/amd64/$(EXECUTABLE): bindata
|
||||
GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "$@"
|
||||
|
||||
bindata:
|
||||
go-bindata -pkg db -o ./pkg/db/bindataSQL.go ./pkg/db/sql/***
|
||||
go-bindata -pkg goldenfiles -o ./test/goldenfiles/bindata.go ./test/goldenfiles/json/***
|
||||
|
||||
container-go-build:
|
||||
$(MAKE) container-run COMMAND=go-build
|
||||
%.tar.bz2: %
|
||||
tar --create --bzip2 --file "$@" "$<"
|
||||
|
||||
container-go-test:
|
||||
$(MAKE) container-run COMMAND=go-test
|
||||
%.tar.gz: %
|
||||
tar --create --gunzip --file "$@" "$<"
|
||||
|
||||
container-rpm-build:
|
||||
$(MAKE) container-run COMMAND=rpm-build
|
||||
%.tar.xz: %
|
||||
tar --create --xz --file "$@" "$<"
|
||||
|
||||
|
||||
test: ${EXECUTABLE}
|
||||
go test -v ./pkg/...
|
||||
|
||||
|
||||
release: clean
|
||||
$(MAKE) $(COMPRESSED_EXECUTABLE_TARGETS)
|
||||
github-release release \
|
||||
--user ${GITHUB_USER} \
|
||||
--repo ${EXECUTABLE} \
|
||||
--tag ${VERSION}
|
||||
|
||||
$(foreach FILE,$(COMPRESSED_EXECUTABLES),github-release upload --user ${GITHUB_USER} --repo ${EXECUTABLE} --tag ${VERSION} --name $(subst /,-,$(FILE)) --file bin/$(FILE) --replace;)
|
||||
|
||||
|
||||
clean:
|
||||
rm ${EXECUTABLE} || true
|
||||
rm --recursive --force bin/ || true
|
||||
|
||||
|
||||
container/all:
|
||||
$(MAKE) container-run COMMAND=all
|
||||
|
||||
|
||||
container/test:
|
||||
$(MAKE) container-run COMMAND=test
|
||||
|
||||
container/release:
|
||||
$(MAKE) container-run COMMAND=release
|
||||
|
||||
container-run:
|
||||
${CONTAINER_RUNTIME} run \
|
||||
@ -61,10 +133,8 @@ container-run:
|
||||
UID=${UID} \
|
||||
GID=${GID} \
|
||||
VERSION=${VERSION} \
|
||||
GOOS=${GOOS} \
|
||||
GOARCH=${GOARCH}
|
||||
GITHUB_TOKEN=${GITHUB_TOKEN}
|
||||
|
||||
remote:
|
||||
$(MAKE) go-build GOARCH=arm
|
||||
scp flucky ${FLUCKY_REMOTE}:/usr/local/bin
|
||||
remote: bin/linux/arm/7/${EXECUTABLE}
|
||||
scp bin/linux/arm/7/${EXECUTABLE} ${FLUCKY_REMOTE}:/usr/local/bin
|
||||
ssh ${FLUCKY_REMOTE} "chmod +x /usr/local/bin/flucky"
|
||||
|
Reference in New Issue
Block a user