feat(build): cross-compile and bundle binary
This commit is contained in:
parent
4005e8682f
commit
216fe62090
103
.gitlab-ci.yml
103
.gitlab-ci.yml
|
@ -1,5 +1,6 @@
|
||||||
stages:
|
stages:
|
||||||
- status-pre
|
- status-pre
|
||||||
|
- test
|
||||||
- build
|
- build
|
||||||
- image
|
- image
|
||||||
- status-post
|
- status-post
|
||||||
|
@ -10,51 +11,117 @@ stages:
|
||||||
- platform:k8s
|
- platform:k8s
|
||||||
- runner:shared
|
- runner:shared
|
||||||
|
|
||||||
build-go:
|
.build-go:
|
||||||
extends:
|
extends:
|
||||||
- .build-base
|
- .build-base
|
||||||
stage: build
|
stage: build
|
||||||
image: apextoaster/golang:1.14
|
image: apextoaster/golang:1.14-master
|
||||||
script:
|
|
||||||
- time go build
|
|
||||||
- time go test
|
|
||||||
variables:
|
variables:
|
||||||
GOPATH: /build
|
GOPATH: /build
|
||||||
|
BUILD_OPTS: -a -v -x
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- make go-clean
|
||||||
|
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
|
||||||
- home-dns
|
|
||||||
expire_in: 1 hour
|
expire_in: 1 hour
|
||||||
cache:
|
paths:
|
||||||
key: "${CI_COMMIT_REF_SLUG}"
|
- bin/
|
||||||
policy: pull-push
|
|
||||||
|
cache: &go-cache
|
||||||
paths:
|
paths:
|
||||||
- vendor
|
- vendor
|
||||||
|
policy: pull
|
||||||
|
|
||||||
build-image:
|
test-go:
|
||||||
|
extends:
|
||||||
|
- .build-go
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- make go-test
|
||||||
|
cache:
|
||||||
|
<<: *go-cache
|
||||||
|
policy: pull-push
|
||||||
|
|
||||||
|
build-go-darwin-x86:
|
||||||
|
extends:
|
||||||
|
- .build-go
|
||||||
|
script:
|
||||||
|
- GOOS=darwin GOARCH=386 make go-build
|
||||||
|
- GOOS=darwin GOARCH=amd64 make go-build
|
||||||
|
|
||||||
|
build-go-linux-arm:
|
||||||
|
extends:
|
||||||
|
- .build-go
|
||||||
|
script:
|
||||||
|
- GOOS=linux GOARCH=arm make go-build
|
||||||
|
- GOOS=linux GOARCH=arm64 make go-build
|
||||||
|
|
||||||
|
build-go-linux-x86:
|
||||||
|
extends:
|
||||||
|
- .build-go
|
||||||
|
script:
|
||||||
|
- GOOS=linux GOARCH=386 make go-build
|
||||||
|
- GOOS=linux GOARCH=amd64 make go-build
|
||||||
|
|
||||||
|
build-go-windows-x86:
|
||||||
|
extends:
|
||||||
|
- .build-go
|
||||||
|
script:
|
||||||
|
- GOOS=windows GOARCH=386 make go-build
|
||||||
|
- GOOS=windows GOARCH=amd64 make go-build
|
||||||
|
|
||||||
|
# always build an image (tagged by branch), publish tags to latest
|
||||||
|
.build-docker:
|
||||||
extends:
|
extends:
|
||||||
- .build-base
|
- .build-base
|
||||||
stage: image
|
|
||||||
image: apextoaster/docker:18.09
|
image: apextoaster/docker:18.09
|
||||||
services:
|
services:
|
||||||
- apextoaster/docker-dind:18.09
|
- apextoaster/docker-dind:18.09
|
||||||
dependencies:
|
variables: &vars-docker
|
||||||
- build-go
|
DOCKER_DRIVER: overlay2
|
||||||
allow_failure: false
|
DOCKER_HOST: tcp://localhost:2375
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- mkdir ${HOME}/.docker
|
- mkdir ${HOME}/.docker
|
||||||
- echo "${DOCKER_SECRET}" | base64 -d > ${HOME}/.docker/config.json
|
- echo "${DOCKER_SECRET}" | base64 -d > ${HOME}/.docker/config.json
|
||||||
script:
|
script:
|
||||||
- ${CI_PROJECT_DIR}/scripts/docker-build.sh --push
|
- ./scripts/docker-build.sh --push --default
|
||||||
after_script:
|
after_script:
|
||||||
- rm -rfv ${HOME}/.docker
|
- rm -rfv ${HOME}/.docker
|
||||||
|
|
||||||
|
build-image:
|
||||||
|
extends:
|
||||||
|
- .build-docker
|
||||||
|
stage: image
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- build-go-linux-x86
|
||||||
variables:
|
variables:
|
||||||
DOCKER_DRIVER: overlay2
|
|
||||||
DOCKER_HOST: tcp://localhost:2375
|
|
||||||
IMAGE_ARCH: ubuntu
|
IMAGE_ARCH: ubuntu
|
||||||
|
|
||||||
|
build-binary:
|
||||||
|
extends:
|
||||||
|
- .build-base
|
||||||
|
stage: image
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- tags
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- build-go-darwin-x86
|
||||||
|
- build-go-linux-arm
|
||||||
|
- build-go-linux-x86
|
||||||
|
- build-go-windows-x86
|
||||||
|
|
||||||
|
script:
|
||||||
|
- make bundle-all
|
||||||
|
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 day
|
||||||
|
paths:
|
||||||
|
- bin/
|
||||||
|
|
||||||
github-pending:
|
github-pending:
|
||||||
stage: status-pre
|
stage: status-pre
|
||||||
extends:
|
extends:
|
||||||
|
|
Loading…
Reference in New Issue