fix(travis): build multiple architectures

This commit is contained in:
Markus Pesch 2019-08-26 08:26:37 +02:00
parent dbdd541ffb
commit 6835d4793b
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
5 changed files with 136 additions and 56 deletions

7
.env
View File

@ -1,7 +0,0 @@
PG_INTERN_PORT=5432
PG_EXTERN_PORT=5432
PG_NAME=public
PG_USER=postgres
PG_PASSWORD=postgres
TZ=Europe/Berlin

14
.gitignore vendored
View File

@ -1,3 +1,13 @@
flucky* # absolute files
.env
flucky
flucky.rpm
flucky.tar.bz2
flucky.tar.gz
flucky.tar.xz
# relative files
**/bindata*.go **/bindata*.go
.vscode
# directories
.vscode/

View File

@ -1,24 +1,22 @@
language: go
services: services:
- docker - docker
jobs: jobs:
include: include:
- stage: "build" - stage: build
name: go-build name: go-build
script: make container-go-build script: make container/all
# - stage: "test"
# name: go-test
# script: make container-go-test
- stage: "pre-deploy"
name: rpm-build
script: make container-rpm-build
deploy: deploy:
provider: releases - provider: script
api_key: script: make container/release
secure: NyeJvsDRo/gDl3KLaE4SMOezeUN9TXzZcRF8PfByf0PS9nx8Al0hjTzgC9BFvzS7GmJKfKcJMORzWsUKroX8wvN6MjboVZuFMZqgkb2R9aamzKWINB3zzm0A42UNM79benh0NKiYiN2CvxSON1duMTlGKv3adRUm5oAXyU0MwvwacGCNxI5xrJJu7RCucMyQrvS6g+TqGjzfke13Oft02Qwh0qFNYF5MRe6cxXeFba/2r17a34ZEySi5SfwcRzUfXaU3juYzsxfWGm3+4sHI7E05NHXupgN0hTaqSggAf/ZLE68lrSwgUCSM4/QJALk2DQoMzp2KBqaiIOHN4/llGiTE4NXVUz58Vrhj25OBWBARPafekqJuBYzo3YwMSv4GQgsMDVa5ni03TB82GQltWS2xodncfUsRheloL72UjA9MXRxk8lwv7POp+rIo9SOD/GOtYcuGTc25kHNzVHidp40rRXWB2y72lpL5FPSaSLw0eXP4pYysFNM/4sKS7E/zdEEs+JS/X8A+vJcs5vdeZV5rnjkEP3DjASowWmm6CVw5bGlx9dMM6a5HgLPMqG67dwqC0QL5BKv3DGqRMWzmybK46SStNmIocEk7mKMU+Ga4uOLVHpqpaU7BpFgTIbZfRJcGhdQJSw/yXqqPK0HrY4E3t1nEIrpr8sU4AZUaQ+8= # skip_cleanup: true
file: flucky.rpm on:
on: tags: true
repo: volker-raschek/flucky
tags: true notifications:
skip_cleanup: true email:
on_success: change
on_failure: change

130
Makefile
View File

@ -16,41 +16,113 @@ CONTAINER_RUNTIME?=$(shell which docker)
# BUILD_IMAGE # BUILD_IMAGE
BUILD_IMAGE:=volkerraschek/build-image:latest BUILD_IMAGE:=volkerraschek/build-image:latest
# GO ENVIRONMENT # GH_USER/GITHUB_TOKEN
GOARCH?=amd64 # It's the user name from github.com and his token. This token and the username
GOOS?=linux # can be set over encrypted environment variables in the ci/cd pipeline
GITHUB_USER=volker-raschek
GITHUB_TOKEN?=""
# default build # EXECUTABLE
go-build: bindata # Executable binary which should be compiled for different architecures
GOOS=${GOOS} \ EXECUTABLE:=flucky
GOARCH=${GOARCH} \
go build -ldflags "-X main.version=${VERSION}"
chown ${UID}:${GID} ./*
go-test: go-build # UNIX_EXECUTABLES
go test -v ./pkg/... # 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 # EXECUTABLE_TARGETS
rpm-builder \ # Include the relative paths to all executables
--arch x86_64 \ EXECUTABLE_TARGETS=$(UNIX_EXECUTABLES:%=bin/%)
--compression gzip \
--exec-file "flucky:/usr/bin/flucky" \ # COMPRSSED_EXECUTABLES
--file "systemd/flucky.service:/usr/lib/systemd/system/flucky.service" \ # Append to all defined executables the compression extentions to detect the
--version ${VERSION} \ # different make steps which compress the binary
flucky 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: bindata:
go-bindata -pkg db -o ./pkg/db/bindataSQL.go ./pkg/db/sql/*** go-bindata -pkg db -o ./pkg/db/bindataSQL.go ./pkg/db/sql/***
go-bindata -pkg goldenfiles -o ./test/goldenfiles/bindata.go ./test/goldenfiles/json/*** go-bindata -pkg goldenfiles -o ./test/goldenfiles/bindata.go ./test/goldenfiles/json/***
container-go-build: %.tar.bz2: %
$(MAKE) container-run COMMAND=go-build tar --create --bzip2 --file "$@" "$<"
container-go-test: %.tar.gz: %
$(MAKE) container-run COMMAND=go-test tar --create --gunzip --file "$@" "$<"
container-rpm-build: %.tar.xz: %
$(MAKE) container-run COMMAND=rpm-build 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-run:
${CONTAINER_RUNTIME} run \ ${CONTAINER_RUNTIME} run \
@ -61,10 +133,8 @@ container-run:
UID=${UID} \ UID=${UID} \
GID=${GID} \ GID=${GID} \
VERSION=${VERSION} \ VERSION=${VERSION} \
GOOS=${GOOS} \ GITHUB_TOKEN=${GITHUB_TOKEN}
GOARCH=${GOARCH}
remote: remote: bin/linux/arm/7/${EXECUTABLE}
$(MAKE) go-build GOARCH=arm scp bin/linux/arm/7/${EXECUTABLE} ${FLUCKY_REMOTE}:/usr/local/bin
scp flucky ${FLUCKY_REMOTE}:/usr/local/bin
ssh ${FLUCKY_REMOTE} "chmod +x /usr/local/bin/flucky" ssh ${FLUCKY_REMOTE} "chmod +x /usr/local/bin/flucky"

9
systemd/flucky.service Normal file
View File

@ -0,0 +1,9 @@
[Unit]
Description=Start flucky daemon
[Service]
Type=simple
ExecStart=/usr/local/bin/flucky daemon
[Install]
WantedBy=multi-user.target