Commit 218a341d authored by zauberstuhl's avatar zauberstuhl

Add cross-compiling for 386, armv7 and amd64

* use custom docker image for faster builds
* add ci Dockerfile to repo
* fix undefined ganggoBytes function
* * for windows rename the binary from *.exe to ganggo
* use different file naming for windows in updater
* add vendor/node_modules folder to cache for speed
parent b28005c3
Pipeline #43 failed with stages
in 5 minutes and 34 seconds
image: golang:1.9-stretch
# you will find the build script
# for the image in ci/docker/Dockerfile
image: zauberstuhl/ganggo-ci:1.9-stretch
services:
- postgres:latest
variables:
......@@ -6,36 +8,64 @@ variables:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ""
UPDATE_CHANNEL: alpha
BUILD_GOOS: linux
BUILD_GOARCH: amd64
# XXX not working yet see https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/876
CI_PROJECT_DIR: $GOPATH/src/github.com/ganggo/ganggo
stages:
- test
- package
- packages
- deploy
cache:
key: "ganggo-$CI_PIPELINE_ID"
paths:
- vendor
- node_modules
before_script:
- export VERSION=$(git describe --abbrev=0 --tags)
- curl -sL https://deb.nodesource.com/setup_10.x | bash -
- apt-get install -y nodejs
# XXX remove clone workaround if CI_PROJECT_DIR is implemented
- mkdir -p $GOPATH/src/github.com/ganggo
- ln -s $(pwd) $GOPATH/src/github.com/ganggo/ganggo
# XXX end
- cd $GOPATH/src/github.com/ganggo/ganggo && make install
- if [ ! -d "vendor" ]; then make install; fi
running unit tests:
stage: test
script:
# if we define GOARCH, GOOS and GOARM directly
# it will be resetted after calling install/script function
# to avoid it we wrap the values in the BUILD-variables
- GOARCH=$BUILD_GOARCH GOOS=$BUILD_GOOS GOARM=$BUILD_GOARM make test
build update package:
stage: package
- make test
building with GOARCH=amd64 GOOS=linux:
stage: packages
script:
- export GOARCH=amd64
- export GOOS=linux
- make release
building with GOARCH=amd64 GOOS=windows:
stage: packages
script:
- export CGO_ENABLED=1
- export CXX=x86_64-w64-mingw32-g++
- export CC=x86_64-w64-mingw32-gcc
- export GOARCH=amd64
- export GOOS=windows
- make release
building with GOARCH=386 GOOS=windows:
stage: packages
script:
- export CGO_ENABLED=1
- export CXX=i686-w64-mingw32-g++
- export CC=i686-w64-mingw32-gcc
- export GOARCH=386
- export GOOS=windows
- make release
building with GOARCH=arm GOOS=linux GOARM=7:
stage: packages
script:
- export CGO_ENABLED=1
- export CC=arm-linux-gnueabihf-gcc
- export GOARCH=arm
- export GOOS=linux
- export GOARM=7
- make release
deploy update packages:
stage: deploy
artifacts:
name: "$BUILD_GOOS-$BUILD_GOARCH-$UPDATE_CHANNEL"
name: "$UPDATE_CHANNEL"
expire_in: "1 day"
paths:
- updater
- updater.*.bin
script:
- GOARCH=$BUILD_GOARCH GOOS=$BUILD_GOOS GOARM=$BUILD_GOARM make release
- bash -c true
when: manual
......@@ -4,46 +4,31 @@
# for detailed Gopkg.toml documentation.
#
required = [
"github.com/revel/cmd/revel",
"github.com/revel/cmd/harness"
]
required = ["github.com/revel/cmd/revel"]
[[constraint]]
branch = "master"
name = "github.com/dchest/captcha"
[[constraint]]
branch = "master"
name = "github.com/ganggo/api"
[[constraint]]
branch = "master"
name = "github.com/ganggo/federation"
[[constraint]]
branch = "master"
name = "github.com/jpillora/overseer"
[[constraint]]
name = "github.com/revel/config"
[[override]]
version = "0.19.0"
[[constraint]]
name = "github.com/revel/modules"
version = "0.19.0"
[[constraint]]
[[override]]
version = "0.19.1"
name = "github.com/revel/revel"
[[override]]
version = "0.14.1"
name = "github.com/revel/cmd"
[[override]]
version = "0.19.0"
name = "github.com/revel/cron"
[[constraint]]
[[override]]
branch = "master"
name = "github.com/shaoshing/train"
name = "github.com/ganggo/api"
[[constraint]]
[[override]]
branch = "master"
name = "golang.org/x/crypto"
name = "github.com/ganggo/federation"
[[constraint]]
name = "gopkg.in/AlecAivazis/survey.v1"
......@@ -52,15 +37,3 @@ required = [
[[constraint]]
name = "gopkg.in/ganggo/gorm.v2"
version = "2.0.0"
[[override]]
name = "github.com/xeonx/timeago"
branch = "master"
[[override]]
name = "github.com/revel/log15"
branch = "master"
[[override]]
name = "github.com/revel/cron"
version = "0.19.0"
......@@ -7,26 +7,30 @@ package := github.com/ganggo/ganggo
srcdir := $(GOPATH)/src/$(package)
go := $(shell command -v go 2> /dev/null)
godep := $(shell command -v dep 2> /dev/null)
gobin := $(shell command -v go-bindata 2> /dev/null)
npm := $(shell command -v npm 2> /dev/null)
revel := $(shell command -v revel 2> /dev/null)
train := $(shell command -v train 2> /dev/null)
define version_info
Please define a version you want to build e.g. VERSION=v0 make
endef
ifndef go
$(error "go is not available: https://golang.org/dl/")
endif
define install_deps_info
is not available please run 'make install-deps'
define version_info
Please define a version you want to build e.g. VERSION=v0 make
endef
define train_info
$(install_deps_info)
And don't forget to add the node modules to your path
e.g. export PATH=$$PATH:$$(pwd)/node_modules/.bin
define install-tools
# go dependencies
go get -u github.com/golang/dep/cmd/dep
# web framework
go get -u github.com/revel/cmd/revel
# asset compilation
go get -u github.com/shaoshing/train/cmd
go build -o $$GOPATH/bin/train github.com/shaoshing/train/cmd
# embedding binary data e.g. assets
go get -u github.com/jteeuwen/go-bindata/...
endef
install: clean install-deps
......@@ -34,38 +38,25 @@ install: clean install-deps
release: precompile compile u2d-wrapper
install-deps:
ifndef go
$(error "go is not available: https://golang.org/dl/")
endif
ifndef npm
$(error "npm is not available please install it first!")
endif
ifndef godep
$(install-tools)
endif
# Install CSS and Javascript dependencies
cd $(srcdir) && npm install --prefix .
# GangGo dependencies
go get -u github.com/golang/dep/cmd/dep
# ganggo dependencies
cd $(srcdir) && dep ensure
# XXX this seams to be a bug in revel
# it cannot find the api module within
# the vendor directory even though it exists
go get -d github.com/ganggo/api/...
## CLI for train asset library / revel webframework
go get -d \
github.com/shaoshing/train \
github.com/revel/cmd/...
go build -o $(GOPATH)/bin/train github.com/shaoshing/train/cmd
go build -o $(GOPATH)/bin/revel github.com/revel/cmd/revel
# Embedding binary data e.g. assets
go get -u github.com/jteeuwen/go-bindata/...
clean:
rm -r app/assets/vendor/* \
tmp node_modules || true
rm bindata.go updater *.tar.gz || true
rm -r tmp vendor node_modules \
test-results bindata.go \
updater.*.bin *.tar.gz || true
precompile:
ifndef train
$(error "train $(train_info)")
$(install-tools)
endif
cd $(srcdir) && train -out public -source app/assets
# Append vendor files to manifest
......@@ -82,21 +73,23 @@ ifndef version
$(error $(version_info))
endif
ifndef revel
$(error "revel $(install_deps_info)")
$(install-tools)
endif
cp $(srcdir)/conf/app.conf.example $(srcdir)/conf/app.conf
cd $(srcdir) && APP_VERSION=$(version) revel package $(package)
cd $(srcdir) && \
APP_VERSION=$(version) revel package $(package)
test:
go tool vet -v -all app/
ifndef revel
$(error "revel $(install_deps_info)")
$(install-tools)
endif
cd $(srcdir) && \
go tool vet -v -all app/
cp $(srcdir)/conf/app.conf.example $(srcdir)/conf/app.conf
# XXX revel will not print error stacks to console
# (see https://github.com/revel/cmd/issues/121)
revel test $(package) ci || { \
cd $(srcdir) && bash tests/scripts/test_results.sh ;\
cd $(srcdir) && bash ci/scripts/test_results.sh ;\
exit 1 ;\
}
......@@ -105,12 +98,15 @@ ifndef version
$(error $(version_info))
endif
ifndef gobin
$(error "go-bindata $(install_deps_info)")
$(install-tools)
endif
mkdir -p $(srcdir)/tmp && cd $(srcdir)/tmp && \
tar -x -f "../ganggo.tar.gz" && \
rm -rf src/$(package)/{vendor,node_modules} && \
go-bindata -o ../bindata.go ganggo src/...
mkdir -p $(srcdir)/tmp && cd $$_ && { \
tar -x -f "../ganggo.tar.gz" ;\
[ -f "ganggo.exe" ] && mv ganggo.exe ganggo ;\
go-bindata -ignore \
'src/$(package)/[vendor|node_modules|bindata.go|.*\.tar\.gz|tmp]' \
-o ../bindata.go ganggo src/... ;\
}
cd $(srcdir) && go build \
-ldflags "-X main.version=$(version)" \
-o updater updater.go bindata.go
-o updater.$$GOOS-$$GOARCH$$GOARM.bin updater.go bindata.go
FROM golang:1.9-stretch
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
# armhf c cross compiler
RUN apt-get install -y gcc-arm-linux-gnueabihf
# windows 64 and 32 c/c++ cross compiler
RUN apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686
RUN apt-get install -y g++-mingw-w64-x86-64 g++-mingw-w64-i686
......@@ -244,6 +244,9 @@ func AssetValidator(filename string) bool {
func prog(state overseer.State) {
buildID := int32(time.Now().Unix())
binFile := fmt.Sprintf("./ganggo.%s.%d", version, buildID)
if runtime.GOOS == "windows" {
binFile = fmt.Sprintf("ganggo.%s.%d.exe", version, buildID)
}
// clean-up binaries
defer func() {
os.Remove(binFile)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment