forked from github/multus-cni
Add version into binary and fix .travis.yml to run forked repo.
This changes introduce goreleaser, which does cross-compile and package, as well as add version into go code. This change also changes .travis.yml to allow to other users' forked repo.
This commit is contained in:
parent
344e74f971
commit
6a46d54161
22
.goreleaser.yml
Normal file
22
.goreleaser.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# This is an example goreleaser.yaml file with some sane defaults.
|
||||||
|
# Make sure to check the documentation at http://goreleaser.com
|
||||||
|
builds:
|
||||||
|
-
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
main: ./multus/
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
goarch:
|
||||||
|
- 386
|
||||||
|
- amd64
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
archive:
|
||||||
|
wrap_in_directory: true
|
||||||
|
checksum:
|
||||||
|
name_template: 'checksums.txt'
|
||||||
|
snapshot:
|
||||||
|
name_template: "{{ .Tag }}-snapshot"
|
||||||
|
release:
|
||||||
|
draft: true
|
36
.travis.yml
36
.travis.yml
@ -3,10 +3,15 @@ language: go
|
|||||||
# for the detail
|
# for the detail
|
||||||
# sudo: requried
|
# sudo: requried
|
||||||
dist: trusty
|
dist: trusty
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.11.x
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- REGISTRY_USER=${REGISTRY_USER}
|
- REGISTRY_USER=${REGISTRY_USER}
|
||||||
- REGISTRY_PASS=${REGISTRY_PASS}
|
- REGISTRY_PASS=${REGISTRY_PASS}
|
||||||
|
- MULTUS_GOPATH=${PWD}/gopath
|
||||||
- secure: "${REGISTRY_SECURE}"
|
- secure: "${REGISTRY_SECURE}"
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
@ -17,31 +22,34 @@ install:
|
|||||||
- go get -u golang.org/x/lint/golint
|
- go get -u golang.org/x/lint/golint
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- golint ./multus/... | grep -v ALL_CAPS | xargs -r false
|
# Make gopath... to run golint/go fmt/go vet
|
||||||
- go fmt ./multus/...
|
- |-
|
||||||
- go vet ./multus/...
|
if [ ! -h gopath/src/github.com/intel/multus-cni ]; then
|
||||||
|
mkdir -p gopath/src/github.com/intel
|
||||||
|
ln -s ../../../.. gopath/src/github.com/intel/multus-cni || exit 255
|
||||||
|
fi
|
||||||
|
- env GOPATH=${MULTUS_GOPATH} golint gopath/src/github.com/intel/multus-cni/multus/... | grep -v ALL_CAPS | xargs -r false
|
||||||
|
- env GOPATH=${MULTUS_GOPATH} go fmt gopath/src/github.com/intel/multus-cni/...
|
||||||
|
- go tool vet */*.go
|
||||||
# - gocyclo -over 15 ./multus
|
# - gocyclo -over 15 ./multus
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./build
|
- ./build
|
||||||
- sudo ./test.sh
|
- sudo ./test.sh
|
||||||
- $GOPATH/bin/goveralls -coverprofile=coverage.out -service=travis-ci
|
- |-
|
||||||
|
GOV_GOPATH=${PWD}/gopath
|
||||||
|
pushd gopath/src/github.com/intel/multus-cni
|
||||||
|
env GOPATH=${GOV_GOPATH} ${GOPATH}/bin/goveralls -coverprofile=coverage.out -service=travis-ci
|
||||||
|
popd
|
||||||
- mkdir -p ${TRAVIS_BUILD_DIR}/dist
|
- mkdir -p ${TRAVIS_BUILD_DIR}/dist
|
||||||
- tar cvfz ${TRAVIS_BUILD_DIR}/dist/multus-cni_amd64.tar.gz --warning=no-file-changed --exclude="dist" --exclude="vendor" .
|
- tar cvfz ${TRAVIS_BUILD_DIR}/dist/multus-cni_amd64.tar.gz --warning=no-file-changed --exclude="dist" --exclude="vendor" .
|
||||||
- docker build -t nfvpe/multus .
|
- docker build -t nfvpe/multus .
|
||||||
|
|
||||||
before_deploy:
|
|
||||||
- go get -u github.com/laher/goxc
|
|
||||||
- mkdir -p $TRAVIS_BUILD_DIR/dist
|
|
||||||
- goxc -d=$TRAVIS_BUILD_DIR/dist -pv=$TRAVIS_TAG -bc=linux -tasks=clean-destination,xc,archive,rmbin
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
- provider: releases
|
# Release on versioned tag (e.g. v1.0)
|
||||||
api_key:
|
- provider: script
|
||||||
secure: "${DEPLOY_SECURE}"
|
|
||||||
file_glob: true
|
|
||||||
file: "$TRAVIS_BUILD_DIR/dist/*/*.gz"
|
|
||||||
skip_cleanup: true
|
skip_cleanup: true
|
||||||
|
script: curl -sL https://git.io/goreleaser | bash
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
all_branches: true
|
all_branches: true
|
||||||
|
16
build
16
build
@ -4,6 +4,20 @@ set -e
|
|||||||
ORG_PATH="github.com/intel"
|
ORG_PATH="github.com/intel"
|
||||||
REPO_PATH="${ORG_PATH}/multus-cni"
|
REPO_PATH="${ORG_PATH}/multus-cni"
|
||||||
|
|
||||||
|
# Add version/commit/date into binary
|
||||||
|
# In case of TravisCI, need to check error code of 'git describe'.
|
||||||
|
set +e
|
||||||
|
git describe --tags --abbrev=0 > /dev/null 2>&1
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
VERSION="master"
|
||||||
|
else
|
||||||
|
VERSION=$(git describe --tags --abbrev=0)
|
||||||
|
fi
|
||||||
|
set -e
|
||||||
|
DATE=$(date --iso-8601=seconds)
|
||||||
|
COMMIT=$(git rev-parse --verify HEAD)
|
||||||
|
LDFLAGS="-X main.version=${VERSION:-master} -X main.commit=${COMMIT} -X main.date=${DATE}"
|
||||||
|
|
||||||
if [ ! -h gopath/src/${REPO_PATH} ]; then
|
if [ ! -h gopath/src/${REPO_PATH} ]; then
|
||||||
mkdir -p gopath/src/${ORG_PATH}
|
mkdir -p gopath/src/${ORG_PATH}
|
||||||
ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
|
ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
|
||||||
@ -14,4 +28,4 @@ export GOBIN=${PWD}/bin
|
|||||||
export GOPATH=${PWD}/gopath
|
export GOPATH=${PWD}/gopath
|
||||||
|
|
||||||
echo "Building plugins"
|
echo "Building plugins"
|
||||||
go install "$@" ${REPO_PATH}/multus
|
go install -ldflags "${LDFLAGS}" "$@" ${REPO_PATH}/multus
|
||||||
|
@ -20,6 +20,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -32,7 +33,7 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/invoke"
|
"github.com/containernetworking/cni/pkg/invoke"
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
cnitypes "github.com/containernetworking/cni/pkg/types"
|
cnitypes "github.com/containernetworking/cni/pkg/types"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
cniversion "github.com/containernetworking/cni/pkg/version"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
k8s "github.com/intel/multus-cni/k8sclient"
|
k8s "github.com/intel/multus-cni/k8sclient"
|
||||||
"github.com/intel/multus-cni/logging"
|
"github.com/intel/multus-cni/logging"
|
||||||
@ -41,6 +42,10 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var version = "master@git"
|
||||||
|
var commit = "unknown commit"
|
||||||
|
var date = "unknown date"
|
||||||
|
|
||||||
var defaultReadinessBackoff = wait.Backoff{
|
var defaultReadinessBackoff = wait.Backoff{
|
||||||
Steps: 4,
|
Steps: 4,
|
||||||
Duration: 250 * time.Millisecond,
|
Duration: 250 * time.Millisecond,
|
||||||
@ -48,6 +53,11 @@ var defaultReadinessBackoff = wait.Backoff{
|
|||||||
Jitter: 0.1,
|
Jitter: 0.1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printVersionString() string {
|
||||||
|
return fmt.Sprintf("multus-cni version:%s, commit:%s, date:%s",
|
||||||
|
version, commit, date)
|
||||||
|
}
|
||||||
|
|
||||||
func saveScratchNetConf(containerID, dataDir string, netconf []byte) error {
|
func saveScratchNetConf(containerID, dataDir string, netconf []byte) error {
|
||||||
logging.Debugf("saveScratchNetConf: %s, %s, %s", containerID, dataDir, string(netconf))
|
logging.Debugf("saveScratchNetConf: %s, %s, %s", containerID, dataDir, string(netconf))
|
||||||
if err := os.MkdirAll(dataDir, 0700); err != nil {
|
if err := os.MkdirAll(dataDir, 0700); err != nil {
|
||||||
@ -441,6 +451,20 @@ func cmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient k8s.KubeClient) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
// Init command line flags to clear vendored packages' one, especially in init()
|
||||||
|
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
||||||
|
|
||||||
|
// add version flag
|
||||||
|
versionOpt := false
|
||||||
|
flag.BoolVar(&versionOpt, "version", false, "Show application version")
|
||||||
|
flag.BoolVar(&versionOpt, "v", false, "Show application version")
|
||||||
|
flag.Parse()
|
||||||
|
if versionOpt == true {
|
||||||
|
fmt.Printf("%s\n", printVersionString())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
skel.PluginMain(
|
skel.PluginMain(
|
||||||
func(args *skel.CmdArgs) error {
|
func(args *skel.CmdArgs) error {
|
||||||
result, err := cmdAdd(args, nil, nil)
|
result, err := cmdAdd(args, nil, nil)
|
||||||
@ -457,5 +481,5 @@ func main() {
|
|||||||
return result.Print()
|
return result.Print()
|
||||||
},
|
},
|
||||||
func(args *skel.CmdArgs) error { return cmdDel(args, nil, nil) },
|
func(args *skel.CmdArgs) error { return cmdDel(args, nil, nil) },
|
||||||
version.All, "meta-plugin that delegates to other CNI plugins")
|
cniversion.All, "meta-plugin that delegates to other CNI plugins")
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
cnitypes "github.com/containernetworking/cni/pkg/types"
|
cnitypes "github.com/containernetworking/cni/pkg/types"
|
||||||
"github.com/containernetworking/cni/pkg/types/020"
|
"github.com/containernetworking/cni/pkg/types/020"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
cniversion "github.com/containernetworking/cni/pkg/version"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ type fakePlugin struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type fakeExec struct {
|
type fakeExec struct {
|
||||||
version.PluginDecoder
|
cniversion.PluginDecoder
|
||||||
|
|
||||||
addIndex int
|
addIndex int
|
||||||
delIndex int
|
delIndex int
|
||||||
|
Loading…
Reference in New Issue
Block a user