From 49f7f8d80f4159008f5b5e42a1074b7cb34a21ff Mon Sep 17 00:00:00 2001 From: cnbattle Date: Wed, 6 May 2020 21:50:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 283 +++++++++++++++++++++++++++----- Dockerfile | 6 +- Makefile | 25 ++- docker/Dockerfile.linux.amd64 | 7 + docker/Dockerfile.linux.arm | 7 + docker/Dockerfile.linux.arm64 | 7 + docker/Dockerfile.windows.amd64 | 5 + docker/manifest.tmpl | 25 +++ 8 files changed, 317 insertions(+), 48 deletions(-) create mode 100644 docker/Dockerfile.linux.amd64 create mode 100644 docker/Dockerfile.linux.arm create mode 100644 docker/Dockerfile.linux.arm64 create mode 100644 docker/Dockerfile.windows.amd64 create mode 100644 docker/manifest.tmpl diff --git a/.drone.yml b/.drone.yml index 6a2228d..e91a243 100644 --- a/.drone.yml +++ b/.drone.yml @@ -9,39 +9,36 @@ platform: steps: - name: vet pull: always - image: golang:1.13 + image: golang:1.14 commands: - make vet volumes: - name: gopath path: /go -# - name: lint -# pull: always -# image: golang:1.13 -# commands: -# - make lint -# volumes: -# - name: gopath -# path: /go + - name: lint + pull: always + image: golang:1.14 + commands: + - make lint + volumes: + - name: gopath + path: /go -# - name: misspell -# pull: always -# image: golang:1.13 -# commands: -# - make misspell-check -# volumes: -# - name: gopath -# path: /go + - name: misspell + pull: always + image: golang:1.14 + commands: + - make misspell-check + volumes: + - name: gopath + path: /go - name: test pull: always - image: golang:1.13-alpine + image: golang:1.14-alpine commands: - - apk add git make curl perl bash build-base zlib-dev ucl-dev -# - make ssh-server - make test -# - make coverage volumes: - name: gopath path: /go @@ -50,7 +47,6 @@ volumes: - name: gopath temp: {} - --- kind: pipeline name: linux-amd64 @@ -62,9 +58,9 @@ platform: steps: - name: build-push pull: always - image: golang:1.13 + image: golang:1.14 commands: - - go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-upx + - "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-upx" environment: CGO_ENABLED: 0 when: @@ -74,9 +70,9 @@ steps: - name: build-tag pull: always - image: golang:1.13 + image: golang:1.14 commands: - - go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-upx + - "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-upx" environment: CGO_ENABLED: 0 when: @@ -85,16 +81,16 @@ steps: - name: executable pull: always - image: golang:1.13 + image: golang:1.14 commands: - - ./release/linux/amd64/drone-upx + - ./release/linux/amd64/drone-upx --help - name: dryrun pull: always image: plugins/docker:linux-amd64 settings: cache_from: cnbattle/drone-upx - dockerfile: Dockerfile + dockerfile: docker/Dockerfile.linux.amd64 dry_run: true repo: cnbattle/drone-upx tags: linux-amd64 @@ -110,7 +106,7 @@ steps: auto_tag_suffix: linux-amd64 cache_from: cnbattle/drone-upx daemon_off: false - dockerfile: Dockerfile + dockerfile: docker/Dockerfile.linux.amd64 password: from_secret: docker_password repo: cnbattle/drone-upx @@ -124,25 +120,236 @@ steps: trigger: ref: - refs/heads/master - - refs/pull/** - - refs/tags/** + - "refs/pull/**" + - "refs/tags/**" depends_on: - testing +--- +kind: pipeline +name: linux-arm64 + +platform: + os: linux + arch: arm64 + +steps: + - name: build-push + pull: always + image: golang:1.14 + commands: + - "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-upx" + environment: + CGO_ENABLED: 0 + when: + event: + exclude: + - tag + + - name: build-tag + pull: always + image: golang:1.14 + commands: + - "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-upx" + environment: + CGO_ENABLED: 0 + when: + event: + - tag + + - name: executable + pull: always + image: golang:1.14 + commands: + - ./release/linux/arm64/drone-upx --help + + - name: dryrun + pull: always + image: plugins/docker:linux-arm64 + settings: + cache_from: cnbattle/drone-upx + dockerfile: docker/Dockerfile.linux.arm64 + dry_run: true + repo: cnbattle/drone-upx + tags: linux-arm64 + when: + event: + - pull_request + + - name: publish + pull: always + image: plugins/docker:linux-arm64 + settings: + auto_tag: true + auto_tag_suffix: linux-arm64 + cache_from: cnbattle/drone-upx + daemon_off: false + dockerfile: docker/Dockerfile.linux.arm64 + password: + from_secret: docker_password + repo: cnbattle/drone-upx + username: + from_secret: docker_username + when: + event: + exclude: + - pull_request + +trigger: + ref: + - refs/heads/master + - "refs/pull/**" + - "refs/tags/**" + +depends_on: + - testing --- kind: pipeline -name: run myself +name: linux-arm + +platform: + os: linux + arch: arm + +steps: + - name: build-push + pull: always + image: golang:1.14 + commands: + - "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-upx" + environment: + CGO_ENABLED: 0 + when: + event: + exclude: + - tag + + - name: build-tag + pull: always + image: golang:1.14 + commands: + - "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-upx" + environment: + CGO_ENABLED: 0 + when: + event: + - tag + + - name: executable + pull: always + image: golang:1.14 + commands: + - ./release/linux/arm/drone-upx --help + + - name: dryrun + pull: always + image: plugins/docker:linux-arm + settings: + cache_from: cnbattle/drone-upx + dockerfile: docker/Dockerfile.linux.arm + dry_run: true + repo: cnbattle/drone-upx + tags: linux-arm + when: + event: + - pull_request + + - name: publish + pull: always + image: plugins/docker:linux-arm + settings: + auto_tag: true + auto_tag_suffix: linux-arm + cache_from: cnbattle/drone-upx + daemon_off: false + dockerfile: docker/Dockerfile.linux.arm + password: + from_secret: docker_password + repo: cnbattle/drone-upx + username: + from_secret: docker_username + when: + event: + exclude: + - pull_request + +trigger: + ref: + - refs/heads/master + - "refs/pull/**" + - "refs/tags/**" + +depends_on: + - testing + +--- +kind: pipeline +name: release-binary platform: os: linux arch: amd64 steps: - - name: upx - image: cnbattle/drone-upx:linux-amd64 + - name: build-all-binary + pull: always + image: golang:1.14 + commands: + - make release + when: + event: + - tag + + - name: deploy-all-binary + pull: always + image: plugins/github-release settings: - level: 9 - save_file: ./release/linux/amd64/drone-upx-new - original_file: ./release/linux/amd64/drone-upx \ No newline at end of file + api_key: + from_secret: github_release_api_key + files: + - "dist/release/*" + when: + event: + - tag + +trigger: + ref: + - "refs/tags/**" + +depends_on: + - testing + +--- +kind: pipeline +name: notifications + +platform: + os: linux + arch: amd64 + +steps: + - name: manifest + pull: always + image: plugins/manifest + settings: + ignore_missing: true + password: + from_secret: docker_password + spec: docker/manifest.tmpl + username: + from_secret: docker_username + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + +depends_on: + - linux-amd64 + - linux-arm64 + - linux-arm + - release-binary + +... \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7fdf3c9..f5b6e1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ FROM alpine -ADD https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz /usr/local -RUN xz -d -c /usr/local/upx-3.95-amd64_linux.tar.xz | tar -xOf - upx-3.95-amd64_linux/upx > /bin/upx && \ +ADD https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz /usr/local +RUN xz -d -c /usr/local/upx-3.96-amd64_linux.tar.xz | tar -xOf - upx-3.96-amd64_linux/upx > /bin/upx && \ chmod a+x /bin/upx RUN /bin/upx --help ADD release/linux/amd64/drone-upx /bin/ -ENTRYPOINT /bin/drone-upx +ENTRYPOINT ["/bin/drone-upx"] diff --git a/Makefile b/Makefile index 2780d71..529ce92 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,6 @@ DEPLOY_IMAGE := $(EXECUTABLE) TARGETS ?= linux darwin windows ARCHS ?= amd64 386 -PACKAGES ?= $(shell $(GO) list ./...) SOURCES ?= $(shell find . -name "*.go" -type f) TAGS ?= LDFLAGS ?= -X 'main.Version=$(VERSION)' @@ -32,7 +31,7 @@ fmt: $(GOFMT) -w $(SOURCES) vet: - $(GO) vet $(PACKAGES) + $(GO) vet ./... lint: @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @@ -40,6 +39,21 @@ lint: fi revive -config .revive.toml ./... || exit 1 +.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 + misspell -error $(SOURCES) + +.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 $(SOURCES) + +.PHONY: fmt-check fmt-check: @diff=$$($(GOFMT) -d $(SOURCES)); \ if [ -n "$$diff" ]; then \ @@ -49,7 +63,7 @@ fmt-check: fi; test: fmt-check - @$(GO) test -v -cover -coverprofile coverage.txt $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1 + @$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1 install: $(SOURCES) $(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' @@ -104,7 +118,4 @@ endif clean: $(GO) clean -x -i ./... - rm -rf coverage.txt $(EXECUTABLE) $(DIST) - -version: - @echo $(VERSION) \ No newline at end of file + rm -rf coverage.txt $(EXECUTABLE) $(DIST) \ No newline at end of file diff --git a/docker/Dockerfile.linux.amd64 b/docker/Dockerfile.linux.amd64 new file mode 100644 index 0000000..2ed2b1e --- /dev/null +++ b/docker/Dockerfile.linux.amd64 @@ -0,0 +1,7 @@ +FROM plugins/base:linux-amd64 + +RUN apk add --no-cache ca-certificates && \ + rm -rf /var/cache/apk/* + +COPY release/linux/amd64/drone-scp /bin/ +ENTRYPOINT ["/bin/drone-scp"] diff --git a/docker/Dockerfile.linux.arm b/docker/Dockerfile.linux.arm new file mode 100644 index 0000000..f38f686 --- /dev/null +++ b/docker/Dockerfile.linux.arm @@ -0,0 +1,7 @@ +FROM plugins/base:linux-arm + +RUN apk add --no-cache ca-certificates && \ + rm -rf /var/cache/apk/* + +COPY release/linux/arm/drone-scp /bin/ +ENTRYPOINT ["/bin/drone-scp"] diff --git a/docker/Dockerfile.linux.arm64 b/docker/Dockerfile.linux.arm64 new file mode 100644 index 0000000..9b1d7b4 --- /dev/null +++ b/docker/Dockerfile.linux.arm64 @@ -0,0 +1,7 @@ +FROM plugins/base:linux-arm64 + +RUN apk add --no-cache ca-certificates && \ + rm -rf /var/cache/apk/* + +COPY release/linux/arm64/drone-scp /bin/ +ENTRYPOINT ["/bin/drone-scp"] diff --git a/docker/Dockerfile.windows.amd64 b/docker/Dockerfile.windows.amd64 new file mode 100644 index 0000000..215fbbf --- /dev/null +++ b/docker/Dockerfile.windows.amd64 @@ -0,0 +1,5 @@ +FROM microsoft/nanoserver:10.0.14393.1884 + +COPY drone-scp.exe /drone-scp.exe + +ENTRYPOINT [ "\\drone-scp.exe" ] diff --git a/docker/manifest.tmpl b/docker/manifest.tmpl new file mode 100644 index 0000000..d8ad89f --- /dev/null +++ b/docker/manifest.tmpl @@ -0,0 +1,25 @@ +image: cnbattle/drone-upx:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} +{{#if build.tags}} +tags: +{{#each build.tags}} + - {{this}} +{{/each}} +{{/if}} +manifests: + - + image: cnbattle/drone-upx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 + platform: + architecture: amd64 + os: linux + - + image: cnbattle/drone-upx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 + platform: + architecture: arm64 + os: linux + variant: v8 + - + image: cnbattle/drone-upx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm + platform: + architecture: arm + os: linux + variant: v7