build binaries

This commit is contained in:
Robert Kaussow 2020-09-20 22:43:22 +02:00
parent 5dd7085ada
commit 7563aa52ed
Signed by: xoxys
GPG Key ID: 65362AE74AF98B61
5 changed files with 129 additions and 18 deletions

View File

@ -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'),

View File

@ -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
...

9
docker/Dockerfile.amd64 Normal file
View File

@ -0,0 +1,9 @@
FROM plugins/base:multiarch
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>" \
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" ]

View File

@ -5,5 +5,5 @@ LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>" \
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" ]

9
docker/Dockerfile.arm64 Normal file
View File

@ -0,0 +1,9 @@
FROM plugins/base:multiarch
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>" \
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" ]