From 7563aa52edf4ba9f363cd4bb7af712b227e16de1 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 20 Sep 2020 22:43:22 +0200 Subject: [PATCH] build binaries --- .drone.jsonnet | 59 +++++++++++++++++++++-- .drone.yml | 68 ++++++++++++++++++++++----- docker/Dockerfile.amd64 | 9 ++++ docker/{Dockerfile => Dockerfile.arm} | 2 +- docker/Dockerfile.arm64 | 9 ++++ 5 files changed, 129 insertions(+), 18 deletions(-) create mode 100644 docker/Dockerfile.amd64 rename docker/{Dockerfile => Dockerfile.arm} (86%) create mode 100644 docker/Dockerfile.arm64 diff --git a/.drone.jsonnet b/.drone.jsonnet index 0f73cfc..3e8b261 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -70,6 +70,56 @@ local PipelineTest = { }, }; + +local PipelineBuildBinaries = { + kind: 'pipeline', + name: 'build-binaries', + platform: { + os: 'linux', + arch: 'amd64', + }, + steps: [ + { + name: 'build', + image: 'techknowlogick/xgo:latest', + commands: [ + '[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}', + "xgo -ldflags \"-s -w -X main.Version=$BUILD_VERSION\" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out /drone/src/release/drone-github-comment ./cmd/drone-github-comment", + 'tree', + ], + }, + { + name: 'executable', + image: 'alpine', + commands: [ + '$(find release/ -executable -type f | grep drone-github-comment-linux-amd64) --help', + ], + }, + { + name: 'compress', + image: 'alpine', + commands: [ + 'apk add upx', + 'find release/ -maxdepth 1 -executable -type f -exec upx {} ;', + 'ls -lh release/', + ], + }, + { + name: 'checksum', + image: 'alpine', + commands: [ + 'cd release/ && sha256sum * > sha256sum.txt', + ], + }, + ], + depends_on: [ + 'test', + ], + trigger: { + ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'], + }, +}; + local PipelineBuildContainer(arch='amd64') = { kind: 'pipeline', name: 'build-container-' + arch, @@ -82,7 +132,7 @@ local PipelineBuildContainer(arch='amd64') = { name: 'build', image: 'golang:1.14', commands: [ - 'go build -v -ldflags "-X main.version=${DRONE_TAG:-latest}" -a -tags netgo -o release/drone-github-comment ./cmd/drone-github-comment', + 'go build -v -ldflags "-X main.version=${DRONE_TAG:-latest}" -a -tags netgo -o release/' + arch + 'drone-github-comment ./cmd/drone-github-comment', ], }, { @@ -90,7 +140,7 @@ local PipelineBuildContainer(arch='amd64') = { image: 'plugins/docker:18-linux-' + arch, settings: { dry_run: true, - dockerfile: 'docker/Dockerfile', + dockerfile: 'docker/Dockerfile.' + arch, repo: 'thegeeklab/${DRONE_REPO_NAME}', username: { from_secret: 'docker_username' }, password: { from_secret: 'docker_password' }, @@ -106,7 +156,7 @@ local PipelineBuildContainer(arch='amd64') = { settings: { auto_tag: true, auto_tag_suffix: arch, - dockerfile: 'docker/Dockerfile', + dockerfile: 'docker/Dockerfile.' + arch, repo: 'thegeeklab/${DRONE_REPO_NAME}', username: { from_secret: 'docker_username' }, password: { from_secret: 'docker_password' }, @@ -135,7 +185,7 @@ local PipelineBuildContainer(arch='amd64') = { }, ], depends_on: [ - 'test', + 'build-binaries', ], trigger: { ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'], @@ -240,6 +290,7 @@ local PipelineNotifications = { [ PipelineTest, + PipelineBuildBinaries, PipelineBuildContainer(arch='amd64'), PipelineBuildContainer(arch='arm64'), PipelineBuildContainer(arch='arm'), diff --git a/.drone.yml b/.drone.yml index 54fa7a7..ae4e59a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -49,6 +49,48 @@ trigger: - refs/tags/** - refs/pull/** +--- +kind: pipeline +name: build-binaries + +platform: + os: linux + arch: amd64 + +steps: +- name: build + image: techknowlogick/xgo:latest + commands: + - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" + - xgo -ldflags "-s -w -X main.Version=$BUILD_VERSION" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out /drone/src/release/drone-github-comment ./cmd/drone-github-comment + - tree + +- name: executable + image: alpine + commands: + - $(find release/ -executable -type f | grep drone-github-comment-linux-amd64) --help + +- name: compress + image: alpine + commands: + - apk add upx + - find release/ -maxdepth 1 -executable -type f -exec upx {} ; + - ls -lh release/ + +- name: checksum + image: alpine + commands: + - cd release/ && sha256sum * > sha256sum.txt + +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +depends_on: +- test + --- kind: pipeline name: build-container-amd64 @@ -61,12 +103,12 @@ steps: - name: build image: golang:1.14 commands: - - go build -v -ldflags "-X main.version=${DRONE_TAG:-latest}" -a -tags netgo -o release/drone-github-comment ./cmd/drone-github-comment + - go build -v -ldflags "-X main.version=${DRONE_TAG:-latest}" -a -tags netgo -o release/amd64drone-github-comment ./cmd/drone-github-comment - name: dryrun image: plugins/docker:18-linux-amd64 settings: - dockerfile: docker/Dockerfile + dockerfile: docker/Dockerfile.amd64 dry_run: true password: from_secret: docker_password @@ -84,7 +126,7 @@ steps: settings: auto_tag: true auto_tag_suffix: amd64 - dockerfile: docker/Dockerfile + dockerfile: docker/Dockerfile.amd64 password: from_secret: docker_password repo: thegeeklab/${DRONE_REPO_NAME} @@ -123,7 +165,7 @@ trigger: - refs/pull/** depends_on: -- test +- build-binaries --- kind: pipeline @@ -137,12 +179,12 @@ steps: - name: build image: golang:1.14 commands: - - go build -v -ldflags "-X main.version=${DRONE_TAG:-latest}" -a -tags netgo -o release/drone-github-comment ./cmd/drone-github-comment + - go build -v -ldflags "-X main.version=${DRONE_TAG:-latest}" -a -tags netgo -o release/arm64drone-github-comment ./cmd/drone-github-comment - name: dryrun image: plugins/docker:18-linux-arm64 settings: - dockerfile: docker/Dockerfile + dockerfile: docker/Dockerfile.arm64 dry_run: true password: from_secret: docker_password @@ -160,7 +202,7 @@ steps: settings: auto_tag: true auto_tag_suffix: arm64 - dockerfile: docker/Dockerfile + dockerfile: docker/Dockerfile.arm64 password: from_secret: docker_password repo: thegeeklab/${DRONE_REPO_NAME} @@ -199,7 +241,7 @@ trigger: - refs/pull/** depends_on: -- test +- build-binaries --- kind: pipeline @@ -213,12 +255,12 @@ steps: - name: build image: golang:1.14 commands: - - go build -v -ldflags "-X main.version=${DRONE_TAG:-latest}" -a -tags netgo -o release/drone-github-comment ./cmd/drone-github-comment + - go build -v -ldflags "-X main.version=${DRONE_TAG:-latest}" -a -tags netgo -o release/armdrone-github-comment ./cmd/drone-github-comment - name: dryrun image: plugins/docker:18-linux-arm settings: - dockerfile: docker/Dockerfile + dockerfile: docker/Dockerfile.arm dry_run: true password: from_secret: docker_password @@ -236,7 +278,7 @@ steps: settings: auto_tag: true auto_tag_suffix: arm - dockerfile: docker/Dockerfile + dockerfile: docker/Dockerfile.arm password: from_secret: docker_password repo: thegeeklab/${DRONE_REPO_NAME} @@ -275,7 +317,7 @@ trigger: - refs/pull/** depends_on: -- test +- build-binaries --- kind: pipeline @@ -373,6 +415,6 @@ depends_on: --- kind: signature -hmac: 49ac4d5dbe243dec7b576714870117cb0c4a1faef2cdaa1f2202464b0229727a +hmac: 359b44f4a22939e189ecd48556204f22a49fd1983d14bde32a942e5f123195db ... diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 new file mode 100644 index 0000000..4552f0f --- /dev/null +++ b/docker/Dockerfile.amd64 @@ -0,0 +1,9 @@ +FROM plugins/base:multiarch + +LABEL maintainer="Robert Kaussow " \ + org.label-schema.name="Drone GitHub Comment" \ + org.label-schema.vendor="Robert Kaussow" \ + org.label-schema.schema-version="1.0" + +ADD release/amd64/drone-github-comment /bin/ +ENTRYPOINT [ "/bin/drone-github-comment" ] diff --git a/docker/Dockerfile b/docker/Dockerfile.arm similarity index 86% rename from docker/Dockerfile rename to docker/Dockerfile.arm index 0810805..5ffc026 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile.arm @@ -5,5 +5,5 @@ LABEL maintainer="Robert Kaussow " \ org.label-schema.vendor="Robert Kaussow" \ org.label-schema.schema-version="1.0" -ADD release/drone-github-comment /bin/ +ADD release/arm/drone-github-comment /bin/ ENTRYPOINT [ "/bin/drone-github-comment" ] diff --git a/docker/Dockerfile.arm64 b/docker/Dockerfile.arm64 new file mode 100644 index 0000000..21793fd --- /dev/null +++ b/docker/Dockerfile.arm64 @@ -0,0 +1,9 @@ +FROM plugins/base:multiarch + +LABEL maintainer="Robert Kaussow " \ + org.label-schema.name="Drone GitHub Comment" \ + org.label-schema.vendor="Robert Kaussow" \ + org.label-schema.schema-version="1.0" + +ADD release/arm64/drone-github-comment /bin/ +ENTRYPOINT [ "/bin/drone-github-comment" ]