From d2757e0165bbef792b7a28129a860d2e694dc0a7 Mon Sep 17 00:00:00 2001 From: Aiwantaozi Date: Thu, 8 Feb 2018 13:31:20 +0800 Subject: [PATCH] add release file --- .drone.yml | 3 +-- Dockerfile.dapper | 32 ++++++++++++++++++++++++++++++++ Makefile | 25 +++++++++++++++++++++++-- main.go | 23 +++++++++++++++++++++++ scripts/build | 11 ++++++++++- scripts/test | 12 +++++++++++- scripts/validate | 21 ++++++++++++++++++++- 7 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 Dockerfile.dapper create mode 100644 main.go diff --git a/.drone.yml b/.drone.yml index 842454f..2082098 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,8 +15,7 @@ pipeline: when: branch: master event: tag - - + publish-image: image: plugins/docker dockerfile: package/Dockerfile diff --git a/Dockerfile.dapper b/Dockerfile.dapper new file mode 100644 index 0000000..cf8a508 --- /dev/null +++ b/Dockerfile.dapper @@ -0,0 +1,32 @@ +FROM ubuntu:16.04 +# FROM arm=armhf/ubuntu:16.04 + +ARG DAPPER_HOST_ARCH +ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH} + +RUN apt-get update && \ + apt-get install -y gcc ca-certificates git wget curl vim less file && \ + rm -f /bin/sh && ln -s /bin/bash /bin/sh + +ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm=armv6l GOLANG_ARCH=GOLANG_ARCH_${ARCH} \ + GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash + +RUN wget -O - https://storage.googleapis.com/golang/go1.9.2.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local && \ + go get github.com/rancher/trash && go get github.com/golang/lint/golint + +ENV DOCKER_URL_amd64=https://get.docker.com/builds/Linux/x86_64/docker-1.10.3 \ + DOCKER_URL_arm=https://github.com/rancher/docker/releases/download/v1.10.3-ros1/docker-1.10.3_arm \ + DOCKER_URL=DOCKER_URL_${ARCH} + +RUN wget -O - ${!DOCKER_URL} > /usr/bin/docker && chmod +x /usr/bin/docker + +ENV DAPPER_ENV REPO TAG DRONE_TAG +ENV DAPPER_SOURCE /go/src/github.com/rancher/fluentd/ +ENV DAPPER_OUTPUT ./bin ./dist +ENV DAPPER_DOCKER_SOCKET true +ENV TRASH_CACHE ${DAPPER_SOURCE}/.trash-cache +ENV HOME ${DAPPER_SOURCE} +WORKDIR ${DAPPER_SOURCE} + +ENTRYPOINT ["./scripts/entry"] +CMD ["ci"] diff --git a/Makefile b/Makefile index 9dd53cd..d3e1ef9 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,23 @@ -ci: - ./scripts/ci \ No newline at end of file +TARGETS := $(shell ls scripts) + +.dapper: + @echo Downloading dapper + @curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp + @@chmod +x .dapper.tmp + @./.dapper.tmp -v + @mv .dapper.tmp .dapper + +$(TARGETS): .dapper + ./.dapper $@ + +trash: .dapper + ./.dapper -m bind trash + +trash-keep: .dapper + ./.dapper -m bind trash -k + +deps: trash + +.DEFAULT_GOAL := ci + +.PHONY: $(TARGETS) \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..0c9cb6a --- /dev/null +++ b/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "os" + + "github.com/Sirupsen/logrus" + "github.com/urfave/cli" +) + +var VERSION = "v0.0.0-dev" + +func main() { + app := cli.NewApp() + app.Name = "fluentd" + app.Version = VERSION + app.Usage = "You need help!" + app.Action = func(c *cli.Context) error { + logrus.Info("I'm a turkey") + return nil + } + + app.Run(os.Args) +} diff --git a/scripts/build b/scripts/build index cc1f786..be9f74e 100755 --- a/scripts/build +++ b/scripts/build @@ -1 +1,10 @@ -#!/bin/bash \ No newline at end of file +#!/bin/bash +set -e + +source $(dirname $0)/version + +cd $(dirname $0)/.. + +mkdir -p bin +[ "$(uname)" != "Darwin" ] && LINKFLAGS="-linkmode external -extldflags -static -s" +CGO_ENABLED=0 go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o bin/fluentd diff --git a/scripts/test b/scripts/test index cc1f786..78d0797 100755 --- a/scripts/test +++ b/scripts/test @@ -1 +1,11 @@ -#!/bin/bash \ No newline at end of file +#!/bin/bash +set -e + +cd $(dirname $0)/.. + +echo Running tests + +PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin)' | sed -e 's!^!./!' -e 's!$!/...!')" + +[ "${ARCH}" == "amd64" ] && RACE=-race +go test ${RACE} -cover -tags=test ${PACKAGES} diff --git a/scripts/validate b/scripts/validate index cc1f786..17f8372 100755 --- a/scripts/validate +++ b/scripts/validate @@ -1 +1,20 @@ -#!/bin/bash \ No newline at end of file +#!/bin/bash +set -e + +cd $(dirname $0)/.. + +echo Running validation + +PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin)' | sed -e 's!^!./!' -e 's!$!/...!')" + +echo Running: go vet +go vet ${PACKAGES} +echo Running: golint +for i in ${PACKAGES}; do + if [ -n "$(golint $i | grep -v 'should have comment.*or be unexported' | tee /dev/stderr)" ]; then + failed=true + fi +done +test -z "$failed" +echo Running: go fmt +test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"