diff --git a/.travis.yml b/.travis.yml index 5256bb1f..19bfac48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,16 @@ -sudo: false +sudo: required language: go +services: + - docker go: -- 1.8 +- 1.8.x before_install: install: -- make +- make release script: - echo "test skip" before_deploy: -- "./release" +- make install deploy: provider: releases api_key: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..fd9a84ab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine:latest +MAINTAINER martinyunify + +ADD daemon / + + + +ENTRYPOINT ["/daemon"] \ No newline at end of file diff --git a/Makefile b/Makefile index 4fd2fc34..ec050c50 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,9 @@ # GitHub viewer defaults to 8, change with ?ts=4 in URL # Vars describing project -NAME = hostnic-cni -GIT_REPOSITORY = github.com/yunify/hostnic-cni +NAME= hostnic-cni +GIT_REPOSITORY= github.com/yunify/hostnic-cni +DOCKER_IMAGE_NAME?= dockerhub.qingcloud.com/qingcloud/hostnic-cni # Generate vars to be included from external script # Allows using bash to generate complex vars, such as project versions @@ -50,8 +51,15 @@ GO_VAR_BUILD_LABEL := $(BUILD_LABEL) GO_LDFLAGS = $(foreach v,$(filter $(GO_VARIABLE_PREFIX)%, $(.VARIABLES)),-X github.com/yunify/hostnic-cni/pkg.$(patsubst $(GO_VARIABLE_PREFIX)%,%,$(v))=$(value $(value v))) GO_BUILD_FLAGS = -a -tags netgo -installsuffix nocgo -ldflags "$(GO_LDFLAGS)" -# Define targets +#src +hostnic_pkg = $(subst $(GIT_REPOSITORY)/,,$(shell go list -f '{{ join .Deps "\n" }}' $(GIT_REPOSITORY)/cmd/hostnic | grep "^$(GIT_REPOSITORY)" |grep -v "^$(GIT_REPOSITORY)/vendor/" )) +hostnic_pkg += cmd/hostnic + +daemon_pkg = $(subst $(GIT_REPOSITORY)/,,$(shell go list -f '{{ join .Deps "\n" }}' $(GIT_REPOSITORY)/cmd/daemon | grep "^$(GIT_REPOSITORY)" |grep -v "^$(GIT_REPOSITORY)/vendor/" )) +daemon_pkg += cmd/daemon +# Define targets +TEST_PACKAGES?=cmd pkg # default just build binary default : go-build @@ -60,10 +68,28 @@ print-% : @echo '$*=$($*)' # perform go build on project -go-build : +go-build : bin/hostnic bin/daemon + +bin/hostnic : $(foreach dir,$(hostnic_pkg),$(wildcard $(dir)/*.go)) go build -o bin/hostnic $(GO_BUILD_FLAGS) $(GIT_REPOSITORY)/cmd/hostnic/ + +bin/hostnic.tar.gz : bin/hostnic + tar -C bin/ -czf bin/hostnic.tar.gz hostnic + +bin/daemon : $(foreach dir,$(daemon_pkg),$(wildcard $(dir)/*.go)) go build -o bin/daemon $(GO_BUILD_FLAGS) $(GIT_REPOSITORY)/cmd/daemon/ +bin/.docker-images-build-timestamp : bin/daemon + cp -u Dockerfile bin + docker build -q -t $(DOCKER_IMAGE_NAME):$(BUILD_LABEL) bin/ > bin/.docker-images-build-timestamp + +release : test bin/hostnic.tar.gz bin/.docker-images-build-timestamp + +install : release + docker push $(DOCKER_IMAGE_NAME):$(BUILD_LABEL) +clean : + docker rmi `cat bin/.docker-images-build-timestamp` + rm -rf bin/ -.PHONY : default all go-build +.PHONY : default all go-build clean release install test diff --git a/release b/release deleted file mode 100755 index 4a5394f3..00000000 --- a/release +++ /dev/null @@ -1,24 +0,0 @@ -# -# ========================================================================= -# Copyright (C) 2017 by Yunify, Inc... -# ------------------------------------------------------------------------- -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this work except in compliance with the License. -# You may obtain a copy of the License in the LICENSE file, or at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ========================================================================= -# - -#!/usr/bin/env bash - -echo "Build hostnic" -mkdir -p bin/ -make -tar -C bin/ -czf bin/hostnic.tar.gz daemon hostnic