From 7ba5d9d1e226f386d5078ece3e1cb77fa81f774a Mon Sep 17 00:00:00 2001 From: Don Date: Thu, 24 Jan 2019 19:07:44 -0800 Subject: [PATCH] Add pipeline.libsonnet --- .drone.jsonnet | 177 +++----------------------------------- .drone.windows.jsonnet | 9 ++ pipeline.libsonnet | 187 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+), 166 deletions(-) create mode 100644 .drone.windows.jsonnet create mode 100644 pipeline.libsonnet diff --git a/.drone.jsonnet b/.drone.jsonnet index 5025875..5df5758 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -1,169 +1,14 @@ -local PipelineTesting = { - kind: "pipeline", - name: "testing", - platform: { - os: "linux", - arch: "amd64", - }, - steps: [ - { - name: "vet", - image: "golang:1.11", - pull: "always", - environment: { - GO111MODULE: "on", - }, - commands: [ - "go vet ./...", - ], - }, - { - name: "test", - image: "golang:1.11", - pull: "always", - environment: { - GO111MODULE: "on", - }, - commands: [ - "go test -cover ./...", - ], - }, - ], - trigger: { - branch: [ "master" ], - }, -}; - -local PipelineBuild(os="linux", arch="amd64") = { - kind: "pipeline", - name: os + "-" + arch, - platform: { - os: os, - arch: arch, - }, - steps: [ - { - name: "build-push", - image: "golang:1.11", - pull: "always", - environment: { - CGO_ENABLED: "0", - GO111MODULE: "on", - }, - commands: [ - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -o release/" + os + "/" + arch + "/drone-webhook", - ], - when: { - event: [ "push", "pull_request" ], - }, - }, - { - name: "build-tag", - image: "golang:1.11", - pull: "always", - environment: { - CGO_ENABLED: "0", - GO111MODULE: "on", - }, - commands: [ - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -o release/" + os + "/" + arch + "/drone-webhook", - ], - when: { - event: [ "tag" ], - }, - }, - { - name: "executable", - image: "golang:1.11", - pull: "always", - commands: [ - "./release/" + os + "/" + arch + "/drone-webhook --help", - ], - }, - { - name: "dryrun", - image: "plugins/docker:" + os + "-" + arch, - pull: "always", - settings: { - dry_run: true, - tags: os + "-" + arch, - dockerfile: "docker/Dockerfile." + os + "." + arch, - repo: "plugins/webhook", - username: { "from_secret": "docker_username" }, - password: { "from_secret": "docker_password" }, - }, - when: { - event: [ "pull_request" ], - }, - }, - { - name: "publish", - image: "plugins/docker:" + os + "-" + arch, - pull: "always", - settings: { - auto_tag: true, - auto_tag_suffix: os + "-" + arch, - dockerfile: "docker/Dockerfile." + os + "." + arch, - repo: "plugins/webhook", - username: { "from_secret": "docker_username" }, - password: { "from_secret": "docker_password" }, - }, - when: { - event: [ "push", "tag" ], - }, - }, - ], - depends_on: [ - "testing", - ], - trigger: { - branch: [ "master" ], - }, -}; - -local PipelineNotifications = { - kind: "pipeline", - name: "notifications", - platform: { - os: "linux", - arch: "amd64", - }, - steps: [ - { - name: "manifest", - image: "plugins/manifest:1", - pull: "always", - settings: { - username: { "from_secret": "docker_username" }, - password: { "from_secret": "docker_password" }, - spec: "docker/manifest.tmpl", - ignore_missing: true, - }, - }, - { - name: "microbadger", - image: "plugins/webhook:1", - pull: "always", - settings: { - url: { "from_secret": "microbadger_url" }, - }, - }, - ], - depends_on: [ - "linux-amd64", - "linux-arm64", - "linux-arm", - ], - trigger: { - branch: [ "master" ], - event: [ "push", "tag" ], - }, -}; +local pipeline = import 'pipeline.libsonnet'; +local name = 'drone-webhook'; [ - PipelineTesting, - PipelineBuild("linux", "amd64"), - PipelineBuild("linux", "arm64"), - PipelineBuild("linux", "arm"), - PipelineNotifications, + pipeline.test('linux', 'amd64'), + //pipeline.build(name, 'linux', 'amd64'), + //pipeline.build(name, 'linux', 'arm64'), + //pipeline.build(name, 'linux', 'arm'), + pipeline.notifications(depends_on=[ + 'linux-amd64', + 'linux-arm64', + 'linux-arm', + ]), ] diff --git a/.drone.windows.jsonnet b/.drone.windows.jsonnet new file mode 100644 index 0000000..fc7f3a9 --- /dev/null +++ b/.drone.windows.jsonnet @@ -0,0 +1,9 @@ +local pipeline = import 'pipeline.libsonnet'; +local name = 'drone-webhook'; + +[ + pipeline.test('windows', 'amd64', '1803'), + pipeline.build(name, 'windows', 'amd64', '1803'), + pipeline.build(name, 'windows', 'amd64', '1809'), + pipeline.notifications('windows', 'amd64', '1809', ['windows-1803', 'windows-1809']), +] diff --git a/pipeline.libsonnet b/pipeline.libsonnet new file mode 100644 index 0000000..e385447 --- /dev/null +++ b/pipeline.libsonnet @@ -0,0 +1,187 @@ +local windows_pipe = '\\\\\\\\.\\\\pipe\\\\docker_engine'; +local windows_pipe_volume = 'docker_pipe'; +local test_pipeline_name = 'testing'; + +local windows(os) = os == 'windows'; + +local golang_image(os, version) = + 'golang:' + '1.11' + if windows(os) then '-windowsservercore-' + version else ''; + +{ + test(os='linux', arch='amd64', version=''):: + local golang = golang_image(os, version); + { + kind: 'pipeline', + name: test_pipeline_name, + platform: { + os: os, + arch: arch, + version: if std.length(version) > 0 then version, + }, + steps: [ + { + name: 'vet', + image: golang, + pull: 'always', + environment: { + GO111MODULE: 'on', + }, + commands: [ + 'go vet ./...', + ], + }, + { + name: 'test', + image: golang, + pull: 'always', + environment: { + GO111MODULE: 'on', + }, + commands: [ + 'go test -cover ./...', + ], + }, + ], + }, + + build(name, os='linux', arch='amd64', version=''):: + local is_windows = windows(os); + local tag = if is_windows then os + '-' + version else os + '-' + arch; + local file_suffix = std.strReplace(tag, '-', '.'); + local volumes = if is_windows then [{ name: windows_pipe_volume, path: windows_pipe }] else []; + local golang = golang_image(os, version); + local plugin_repo = 'plugins/' + std.split(name, '-')[1]; + local extension = if is_windows then '.exe' else ''; + { + kind: 'pipeline', + name: tag, + platform: { + os: os, + arch: arch, + version: if std.length(version) > 0 then version, + }, + steps: [ + { + name: 'build-push', + image: golang, + pull: 'always', + environment: { + CGO_ENABLED: '0', + GO111MODULE: 'on', + }, + commands: [ + 'go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/' + os + '/' + arch + '/' + name + extension, + ], + when: { + event: ['push', 'pull_request'], + }, + }, + { + name: 'build-tag', + image: golang, + pull: 'always', + environment: { + CGO_ENABLED: '0', + GO111MODULE: 'on', + }, + commands: [ + 'go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/' + os + '/' + arch + '/' + name + extension, + ], + when: { + event: ['tag'], + }, + }, + { + name: 'executable', + image: golang, + pull: 'always', + commands: [ + './release/' + os + '/' + arch + '/' + name + extension + ' --help', + ], + }, + { + name: 'dryrun', + image: 'plugins/docker:' + tag, + pull: 'always', + settings: { + dry_run: true, + tags: tag, + dockerfile: 'docker/Dockerfile.' + file_suffix, + daemon_off: if is_windows then 'true' else 'false', + repo: plugin_repo, + username: { from_secret: 'docker_username' }, + password: { from_secret: 'docker_password' }, + }, + volumes: if std.length(volumes) > 0 then volumes, + when: { + event: ['pull_request'], + }, + }, + { + name: 'publish', + image: 'plugins/docker:' + tag, + pull: 'always', + settings: { + auto_tag: true, + auto_tag_suffix: tag, + daemon_off: if is_windows then 'true' else 'false', + dockerfile: 'docker/Dockerfile.' + file_suffix, + repo: plugin_repo, + username: { from_secret: 'docker_username' }, + password: { from_secret: 'docker_password' }, + }, + volumes: if std.length(volumes) > 0 then volumes, + when: { + event: ['push'], + }, + }, + ], + trigger: { + branch: ['master'], + }, + depends_on: [ test_pipeline_name ], + volumes: if is_windows then [{ name: windows_pipe_volume, host: { path: windows_pipe } }], + }, + + notifications(os='linux', arch='amd64', version='', depends_on=[]):: + { + kind: 'pipeline', + name: 'notifications', + platform: { + os: os, + arch: arch, + version: if std.length(version) > 0 then version, + }, + steps: [ + { + name: 'manifest', + image: 'plugins/manifest:1', + pull: 'always', + settings: { + username: { from_secret: 'docker_username' }, + password: { from_secret: 'docker_password' }, + spec: 'docker/manifest.tmpl', + ignore_missing: true, + }, + when: { + event: ['push'], + }, + }, + { + name: 'microbadger', + image: 'plugins/webhook:1', + pull: 'always', + settings: { + url: { from_secret: 'microbadger_url' }, + }, + when: { + event: ['push'], + }, + }, + ], + depends_on: depends_on, + trigger: { + branch: ['master'], + }, + }, +}