diff --git a/.drone.yml b/.drone.yml index a4d70f4..77094b9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,6 +1,6 @@ workspace: - base: /srv/app - path: src/github.com/appleboy/drone-jenkins + base: /go + path: src/github.com/appleboy/drone-gitlab-ci clone: git: @@ -9,56 +9,75 @@ clone: tags: true pipeline: - test: - image: appleboy/golang-testing + lint: + image: golang:1.11 pull: true - environment: - TAGS: netgo - GOPATH: /srv/app - secrets: [ codecov_token ] + group: test commands: - make vet - make lint + - make test-vendor + - make misspell-check + + test: + image: golang:1.11 + pull: true + group: test + commands: - make test - make coverage - - make build - # build binary for docker image - - make static_build - when: - event: [ push, tag, pull_request ] - publish_latest: - image: plugins/docker - repo: ${DRONE_REPO} - tags: [ 'latest' ] - secrets: [ docker_username, docker_password ] + # build_linux_amd64_with_module: + # image: golang:1.11 + # pull: true + # group: build + # environment: + # GO111MODULE: "on" + # commands: + # - make build_linux_amd64 + + build_linux_amd64: + image: golang:1.11 + pull: true + group: build + commands: + - make build_linux_amd64 + + build_linux_i386: + image: golang:1.11 + pull: true + group: build + commands: + - make build_linux_i386 + + build_linux_arm64: + image: golang:1.11 + pull: true + group: build + commands: + - make build_linux_arm64 + + build_linux_arm: + image: golang:1.11 + pull: true + group: build + commands: + - make build_linux_arm + + codecov: + image: robertstettner/drone-codecov + secrets: [ codecov_token ] when: - event: [ push ] - branch: [ master ] - local: false + event: [ push, pull_request ] + status: [ success ] release: - image: appleboy/golang-testing + image: golang:1.11 pull: true - environment: - TAGS: netgo - GOPATH: /srv/app commands: - make release when: event: [ tag ] - branch: [ refs/tags/* ] - local: false - - publish_tag: - image: plugins/docker - repo: ${DRONE_REPO} - tags: [ '${DRONE_TAG}' ] - secrets: [ docker_username, docker_password ] - group: release - when: - event: [ tag ] - branch: [ refs/tags/* ] local: false release_tag: @@ -72,10 +91,66 @@ pipeline: branch: [ refs/tags/* ] local: false - facebook: - image: appleboy/drone-facebook - secrets: [ fb_page_token, fb_verify_token ] + publish_linux_amd64: + image: plugins/docker:17.12 + group: release pull: true - to: 1234973386524610 + repo: ${DRONE_REPO} + secrets: [ docker_username, docker_password ] + auto_tag: true + auto_tag_suffix: linux-amd64 when: - status: [ changed, failure ] + event: [ push, tag ] + local: false + + publish_alpine: + image: plugins/docker:17.12 + group: release + pull: true + dockerfile: Dockerfile.alpine + secrets: [ docker_username, docker_password ] + auto_tag: true + auto_tag_suffix: linux-alpine + repo: ${DRONE_REPO} + when: + event: [ push, tag ] + local: false + + publish_linux_i386: + image: plugins/docker:17.12 + pull: true + secrets: [ docker_username, docker_password ] + group: release + repo: ${DRONE_REPO} + auto_tag: true + auto_tag_suffix: linux-i386 + dockerfile: Dockerfile.i386 + when: + event: [ push, tag ] + local: false + + publish_linux_arm64: + image: plugins/docker:17.12 + pull: true + secrets: [ docker_username, docker_password ] + group: release + repo: ${DRONE_REPO} + auto_tag: true + auto_tag_suffix: linux-arm64 + dockerfile: Dockerfile.arm64 + when: + event: [ push, tag ] + local: false + + publish_linux_arm: + image: plugins/docker:17.12 + pull: true + secrets: [ docker_username, docker_password ] + group: release + repo: ${DRONE_REPO} + auto_tag: true + auto_tag_suffix: linux-arm + dockerfile: Dockerfile.arm + when: + event: [ push, tag ] + local: false diff --git a/Dockerfile b/Dockerfile index a197c2c..308ebaf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ -FROM centurylink/ca-certs +FROM plugins/base:multiarch -LABEL maintainer="Bo-Yi Wu " +LABEL maintainer="Bo-Yi Wu " \ + org.label-schema.name="Drone Jenkins" \ + org.label-schema.vendor="Bo-Yi Wu" \ + org.label-schema.schema-version="1.0" -ADD drone-jenkins / +ADD release/linux/amd64/drone-jenkins /bin/ -ENTRYPOINT ["/drone-jenkins"] +ENTRYPOINT ["/bin/drone-jenkins"] diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..c4e37cd --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,13 @@ +FROM alpine:3.8 + +LABEL maintainer="Bo-Yi Wu " \ + org.label-schema.name="Drone Jenkins" \ + org.label-schema.vendor="Bo-Yi Wu" \ + org.label-schema.schema-version="1.0" + +RUN apk add -U --no-cache ca-certificates && \ + rm -rf /var/cache/apk/* + +ADD release/linux/amd64/drone-jenkins /bin/ + +ENTRYPOINT ["/bin/drone-jenkins"] diff --git a/Dockerfile.arm b/Dockerfile.arm new file mode 100644 index 0000000..e54a3a1 --- /dev/null +++ b/Dockerfile.arm @@ -0,0 +1,10 @@ +FROM plugins/base:multiarch + +LABEL maintainer="Bo-Yi Wu " \ + org.label-schema.name="Drone Jenkins" \ + org.label-schema.vendor="Bo-Yi Wu" \ + org.label-schema.schema-version="1.0" + +ADD release/linux/arm/drone-jenkins /bin/ + +ENTRYPOINT ["/bin/drone-jenkins"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 new file mode 100644 index 0000000..b9306c5 --- /dev/null +++ b/Dockerfile.arm64 @@ -0,0 +1,10 @@ +FROM plugins/base:multiarch + +LABEL maintainer="Bo-Yi Wu " \ + org.label-schema.name="Drone Jenkins" \ + org.label-schema.vendor="Bo-Yi Wu" \ + org.label-schema.schema-version="1.0" + +ADD release/linux/arm64/drone-jenkins /bin/ + +ENTRYPOINT ["/bin/drone-jenkins"] diff --git a/Dockerfile.armhf b/Dockerfile.armhf deleted file mode 100644 index 2c2eeca..0000000 --- a/Dockerfile.armhf +++ /dev/null @@ -1,8 +0,0 @@ -FROM armhfbuild/alpine:3.4 - -RUN apk update && \ - apk add ca-certificates && \ - rm -rf /var/cache/apk/* - -ADD drone-jenkins /bin/ -ENTRYPOINT ["/bin/drone-jenkins"] diff --git a/Dockerfile.i386 b/Dockerfile.i386 new file mode 100644 index 0000000..4bbd10d --- /dev/null +++ b/Dockerfile.i386 @@ -0,0 +1,10 @@ +FROM plugins/base:multiarch + +LABEL maintainer="Bo-Yi Wu " \ + org.label-schema.name="Drone Jenkins" \ + org.label-schema.vendor="Bo-Yi Wu" \ + org.label-schema.schema-version="1.0" + +ADD release/linux/i386/drone-jenkins /bin/ + +ENTRYPOINT ["/bin/drone-jenkins"] diff --git a/Dockerfile.windows b/Dockerfile.windows new file mode 100644 index 0000000..334e05a --- /dev/null +++ b/Dockerfile.windows @@ -0,0 +1,9 @@ +FROM microsoft/nanoserver:10.0.14393.1884 + +LABEL maintainer="Bo-Yi Wu " \ + org.label-schema.name="Drone Jenkins" \ + org.label-schema.vendor="Bo-Yi Wu" \ + org.label-schema.schema-version="1.0" + +ADD release/drone-jenkins.exe /drone-jenkins.exe +ENTRYPOINT [ "\\drone-jenkins.exe" ] diff --git a/Makefile b/Makefile index 667c44f..e1e1169 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,19 @@ -.PHONY: test drone-jenkins build fmt vet errcheck lint install update release-dirs release-build release-copy release-check release coverage - DIST := dist EXECUTABLE := drone-jenkins +GOFMT ?= gofmt "-s" +GO ?= go # for dockerhub DEPLOY_ACCOUNT := appleboy DEPLOY_IMAGE := $(EXECUTABLE) -GOFMT ?= gofmt "-s" TARGETS ?= linux darwin windows -PACKAGES ?= $(shell go list ./... | grep -v /vendor/) +PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/) +GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*") SOURCES ?= $(shell find . -name "*.go" -type f) -GOFILES := find . -name "*.go" -type f -not -path "./vendor/*" TAGS ?= LDFLAGS ?= -X 'main.Version=$(VERSION)' +TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'tempdir') ifneq ($(shell uname), Darwin) EXTLDFLAGS = -extldflags "-static" $(null) @@ -30,51 +30,66 @@ endif all: build fmt: - $(GOFILES) | xargs $(GOFMT) -w + $(GOFMT) -w $(GOFILES) vet: - go vet $(PACKAGES) - -errcheck: - @which errcheck > /dev/null; if [ $$? -ne 0 ]; then \ - go get -u github.com/kisielk/errcheck; \ - fi - errcheck $(PACKAGES) + $(GO) vet $(PACKAGES) lint: @which golint > /dev/null; if [ $$? -ne 0 ]; then \ - go get -u github.com/golang/lint/golint; \ + $(GO) get -u github.com/golang/lint/golint; \ fi for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done; -unconvert: - @which unconvert > /dev/null; if [ $$? -ne 0 ]; then \ - go get -u github.com/mdempsky/unconvert; \ +.PHONY: misspell-check +misspell-check: + @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + $(GO) get -u github.com/client9/misspell/cmd/misspell; \ fi - for PKG in $(PACKAGES); do unconvert -v $$PKG || exit 1; done; + misspell -error $(GOFILES) + +.PHONY: misspell +misspell: + @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + $(GO) get -u github.com/client9/misspell/cmd/misspell; \ + fi + misspell -w $(GOFILES) .PHONY: fmt-check fmt-check: - # get all go files and run go fmt on them - @files=$$($(GOFILES) | xargs $(GOFMT) -l); if [ -n "$$files" ]; then \ + @diff=$$($(GOFMT) -d $(GOFILES)); \ + if [ -n "$$diff" ]; then \ echo "Please run 'make fmt' and commit the result:"; \ - echo "$${files}"; \ + echo "$${diff}"; \ exit 1; \ - fi; + fi; + +.PHONY: test-vendor +test-vendor: + @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + $(GO) get -u github.com/kardianos/govendor; \ + fi + govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused" + [ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\" + + govendor list +outside | tee "$(TMPDIR)/wc-gitea-outside" + [ $$(cat "$(TMPDIR)/wc-gitea-outside" | wc -l) -eq 0 ] || exit 1 + + govendor status || exit 1 test: fmt-check - for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done; + for PKG in $(PACKAGES); do $(GO) test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done; html: - go tool cover -html=coverage.txt + $(GO) tool cover -html=coverage.txt install: $(SOURCES) - go install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' + $(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' build: $(EXECUTABLE) $(EXECUTABLE): $(SOURCES) - go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@ + $(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@ release: release-dirs release-build release-copy release-check @@ -83,7 +98,7 @@ release-dirs: release-build: @which gox > /dev/null; if [ $$? -ne 0 ]; then \ - go get -u github.com/mitchellh/gox; \ + $(GO) get -u github.com/mitchellh/gox; \ fi gox -os="$(TARGETS)" -arch="amd64 386" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}" @@ -93,14 +108,22 @@ release-copy: release-check: cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;) -# for docker. -static_build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $(DEPLOY_IMAGE) +build_linux_amd64: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE) + +build_linux_i386: + CGO_ENABLED=0 GOOS=linux GOARCH=386 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/i386/$(DEPLOY_IMAGE) + +build_linux_arm64: + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE) + +build_linux_arm: + CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE) docker_image: docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) . -docker: static_build docker_image +docker: docker_image docker_deploy: ifeq ($(tag),) @@ -113,13 +136,10 @@ endif coverage: sed -i '/main.go/d' coverage.txt - curl -s https://codecov.io/bash > .codecov && \ - chmod +x .codecov && \ - ./.codecov -f coverage.txt clean: - go clean -x -i ./... - rm -rf coverage.txt $(EXECUTABLE) $(DIST) vendor + $(GO) clean -x -i ./... + rm -rf coverage.txt $(EXECUTABLE) $(DIST) version: @echo $(VERSION)