From b67d8a93eea1d0e4c2ce950563e6cb5407b4860d Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 6 Aug 2019 22:47:04 -0700 Subject: [PATCH] add pipelines to build windows agents --- .drone.script | 108 +++++-- .drone.yml | 463 ++++++++++++++------------- CHANGELOG.md | 2 + docker/Dockerfile.agent.windows.1803 | 2 +- docker/Dockerfile.agent.windows.1809 | 2 +- docker/Dockerfile.agent.windows.1903 | 14 + docker/manifest.agent.tmpl | 8 +- go.mod | 2 +- go.sum | 3 + 9 files changed, 338 insertions(+), 266 deletions(-) create mode 100644 docker/Dockerfile.agent.windows.1903 diff --git a/.drone.script b/.drone.script index 9fb7dfad..9c22a1f0 100644 --- a/.drone.script +++ b/.drone.script @@ -1,8 +1,10 @@ -def main(): +def main(ctx): return [ pipeline('linux-amd64', 'linux', 'amd64'), pipeline('linux-arm64', 'linux', 'arm64'), pipeline('linux-arm', 'linux', 'arm'), + pipeline_windows('1809'), + pipeline_windows('1903'), manifest(), ] @@ -14,12 +16,12 @@ def docker_step(name, os, arch): repo = 'drone/drone' return { 'name': 'publish_%s' % name, - 'image': 'plugins/docker', + 'image': 'plugins/docker:18', 'settings': { 'repo': repo, 'auto_tag': True, 'auto_tag_suffix': '%s-%s' % (os, arch), - 'username': 'drone', + 'username': { 'from_secret': 'docker_username' }, 'password': { 'from_secret': 'docker_password' }, 'dockerfile': 'docker/Dockerfile.%s.%s.%s' % (name, os, arch), }, @@ -28,31 +30,12 @@ def docker_step(name, os, arch): }, } - -# defines a pipeline step that creates and publishes -# a docker manifest to a docker remote registry. -def manifest_step(name): - return { - 'name': 'publish_%s' % name, - 'image': 'plugins/manifest:1', - 'settings': { - 'auto_tag': True, - 'ignore_missing': True, - 'spec': 'docker/manifest.%s.tmpl' % name, - 'username': 'drone', - 'password': { 'from_secret': 'docker_password' }, - }, - 'when': { - 'event': [ 'push', 'tag' ], - }, - } - # defines a pipeline step that executes the Go unit tests. # this will also download dependencies and cache in /go def test_step(): return { 'name': 'test', - 'image': 'golang:1.11', + 'image': 'golang:1.12', 'commands': [ 'go test ./...', ], @@ -61,14 +44,16 @@ def test_step(): # defines a pipeline step that executes the Go unit tests. # this will also download dependencies and cache in /go def build_step(os, arch): - return { - 'name': 'build', - 'image': 'golang:1.11', - 'commands': [ - 'go build -ldflags \"-extldflags \\\\\"-static\\\\\"\" -o release/%s/%s/drone-server github.com/drone/drone/cmd/drone-server' % (os, arch), - 'CGO_ENABLED=0 go build -o release/%s/%s/drone-agent github.com/drone/drone/cmd/drone-agent' % (os, arch), - 'CGO_ENABLED=0 go build -o release/%s/%s/drone-controller github.com/drone/drone/cmd/drone-controller' % (os, arch), - ] + return { + 'name': 'build', + 'image': 'golang:1.12', + 'commands': [ + 'sh scripts/build.sh', + ], + 'environment': { + 'GOOS': os, + 'GOARCH': arch, + }, } # defines a pipeline that builds, tests and publishes @@ -76,9 +61,10 @@ def build_step(os, arch): def pipeline(name, os, arch): return { 'kind': 'pipeline', - 'name': 'default', + 'type': 'docker', + 'name': 'linux-%s' % arch, 'platform': { - 'os': os, + 'os': 'linux', 'arch': arch, }, 'steps': [ @@ -90,21 +76,77 @@ def pipeline(name, os, arch): ], } +# defines a pipeline that builds and publishes docker images +# for the Drone agent for the Windows kernel. +def pipeline_windows(version): + return { + 'kind': 'pipeline', + 'type': 'ssh', + 'name': 'windows-%s-amd64' % version, + 'platform': { 'os': 'windows' }, + 'server': { + 'host': { 'from_secret': 'windows_server_%s' % version }, + 'user': { 'from_secret': 'windows_username' }, + 'password': { 'from_secret': 'windows_password' }, + }, + 'steps': [ + { + 'name': 'build', + 'environment': { + 'USERNAME': { 'from_secret': 'docker_username' }, + 'PASSWORD': { 'from_secret': 'docker_password' }, + }, + # TODO these commands build and publish the latest + # docker tag regardless of git tag. + 'commands': [ + 'powershell.exe scripts/build.ps1', + 'docker login -u $env:USERNAME -p $env:PASSWORD', + 'docker build -f docker/Dockerfile.agent.windows.%s -t drone/agent:windows-%s-amd64 .' % (version, version), + 'docker push drone/agent:windows-%s-amd64' % version, + ], + }, + ], + 'trigger': { + 'event': ['push'] + } + } + # defines a pipeline that updates the docker manifest # for the architecture-specific images previously published # to dockerhub. def manifest(): return { 'kind': 'pipeline', + 'type': 'docker', 'name': 'manifest', 'steps': [ manifest_step('server'), manifest_step('agent'), manifest_step('controller'), ], + 'trigger': { + 'event': [ 'push', 'tag' ], + }, 'depends_on': [ 'linux-amd64', 'linux-arm64', 'linux-arm', + 'windows-1903-amd64', + 'windows-1809-amd64', ], } + +# defines a pipeline step that creates and publishes +# a docker manifest to a docker remote registry. +def manifest_step(name): + return { + 'name': 'publish_%s' % name, + 'image': 'plugins/manifest:1', + 'settings': { + 'auto_tag': True, + 'ignore_missing': True, + 'spec': 'docker/manifest.%s.tmpl' % name, + 'username': { 'from_secret': 'docker_username' }, + 'password': { 'from_secret': 'docker_password' }, + }, + } diff --git a/.drone.yml b/.drone.yml index 620313d8..434206b8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,309 +1,314 @@ --- kind: pipeline +type: docker name: linux-amd64 platform: - os: linux arch: amd64 + os: linux steps: - name: test - image: golang:1.11 + image: golang:1.12 commands: - - go test -v ./... - volumes: - - name: gopath - path: /go - + - go test ./... + - name: build - image: golang:1.11 + image: golang:1.12 commands: - - "go build -ldflags \"-extldflags \\\\\"-static\\\\\"\" -o release/linux/amd64/drone-server github.com/drone/drone/cmd/drone-server" - - CGO_ENABLED=0 go build -o release/linux/amd64/drone-agent github.com/drone/drone/cmd/drone-agent - - CGO_ENABLED=0 go build -o release/linux/amd64/drone-controller github.com/drone/drone/cmd/drone-controller - volumes: - - name: gopath - path: /go + - sh scripts/build.sh + environment: + GOARCH: amd64 + GOOS: linux + +- name: publish_drone + image: plugins/docker:18 + settings: + auto_tag: true + auto_tag_suffix: linux-amd64 + dockerfile: docker/Dockerfile.drone.linux.amd64 + repo: drone/drone + username: + from_secret: docker_username + password: + from_secret: docker_password when: event: - push - tag - name: publish_agent - image: plugins/docker + image: plugins/docker:18 settings: auto_tag: true auto_tag_suffix: linux-amd64 dockerfile: docker/Dockerfile.agent.linux.amd64 - password: - from_secret: docker_password repo: drone/agent username: from_secret: docker_username + password: + from_secret: docker_password when: event: - push - tag - name: publish_controller - image: plugins/docker + image: plugins/docker:18 settings: auto_tag: true auto_tag_suffix: linux-amd64 dockerfile: docker/Dockerfile.controller.linux.amd64 - password: - from_secret: docker_password repo: drone/controller username: from_secret: docker_username - when: - event: - - push - - tag - -- name: publish_server - image: plugins/docker - settings: - auto_tag: true - auto_tag_suffix: linux-amd64 - dockerfile: docker/Dockerfile.server.linux.amd64 password: from_secret: docker_password - repo: drone/drone - username: - from_secret: docker_username when: event: - push - tag -volumes: -- name: gopath - temp: {} - ---- -kind: pipeline -name: linux-arm - -platform: - os: linux - arch: arm - -steps: -- name: test - image: golang:1.11 - commands: - - go test -v ./... - volumes: - - name: gopath - path: /go - -- name: build - image: golang:1.11 - commands: - - "go build -ldflags \"-extldflags \\\\\"-static\\\\\"\" -o release/linux/arm/drone-server github.com/drone/drone/cmd/drone-server" - - CGO_ENABLED=0 go build -o release/linux/arm/drone-agent github.com/drone/drone/cmd/drone-agent - - CGO_ENABLED=0 go build -o release/linux/arm/drone-controller github.com/drone/drone/cmd/drone-controller - volumes: - - name: gopath - path: /go - when: - event: - - push - - tag - -- name: publish_agent - image: plugins/docker - settings: - auto_tag: true - auto_tag_suffix: linux-arm - dockerfile: docker/Dockerfile.agent.linux.arm - password: - from_secret: docker_password - repo: drone/agent - username: - from_secret: docker_username - when: - event: - - push - - tag - -- name: publish_controller - image: plugins/docker - settings: - auto_tag: true - auto_tag_suffix: linux-arm - dockerfile: docker/Dockerfile.controller.linux.arm - password: - from_secret: docker_password - repo: drone/controller - username: - from_secret: docker_username - when: - event: - - push - - tag - -- name: publish_server - image: plugins/docker - settings: - auto_tag: true - auto_tag_suffix: linux-arm - dockerfile: docker/Dockerfile.server.linux.arm - password: - from_secret: docker_password - repo: drone/drone - username: - from_secret: docker_username - when: - event: - - push - - tag - -volumes: -- name: gopath - temp: {} - --- kind: pipeline +type: docker name: linux-arm64 platform: - os: linux arch: arm64 + os: linux steps: -- name: test - image: golang:1.11 - commands: - - go test -v ./... - volumes: - - name: gopath - path: /go - - name: build - image: golang:1.11 + image: golang:1.12 commands: - - "go build -ldflags \"-extldflags \\\\\"-static\\\\\"\" -o release/linux/arm64/drone-server github.com/drone/drone/cmd/drone-server" - - CGO_ENABLED=0 go build -o release/linux/arm64/drone-agent github.com/drone/drone/cmd/drone-agent - - CGO_ENABLED=0 go build -o release/linux/arm64/drone-controller github.com/drone/drone/cmd/drone-controller - volumes: - - name: gopath - path: /go - when: - event: - - push - - tag + - sh scripts/build.sh + environment: + GOARCH: arm64 + GOOS: linux + +- name: publish_drone + image: plugins/docker:18 + settings: + auto_tag: true + auto_tag_suffix: linux-arm64 + dockerfile: docker/Dockerfile.drone.linux.arm64 + repo: drone/drone + username: + from_secret: docker_username + password: + from_secret: docker_password - name: publish_agent - image: plugins/docker + image: plugins/docker:18 settings: auto_tag: true auto_tag_suffix: linux-arm64 dockerfile: docker/Dockerfile.agent.linux.arm64 - password: - from_secret: docker_password repo: drone/agent username: from_secret: docker_username - when: - event: - - push - - tag + password: + from_secret: docker_password - name: publish_controller - image: plugins/docker + image: plugins/docker:18 settings: auto_tag: true auto_tag_suffix: linux-arm64 dockerfile: docker/Dockerfile.controller.linux.arm64 - password: - from_secret: docker_password repo: drone/controller username: from_secret: docker_username - when: - event: - - push - - tag - -- name: publish_server - image: plugins/docker - settings: - auto_tag: true - auto_tag_suffix: linux-arm64 - dockerfile: docker/Dockerfile.server.linux.arm64 password: from_secret: docker_password - repo: drone/drone - username: - from_secret: docker_username - when: - event: - - push - - tag -volumes: -- name: gopath - temp: {} - ---- -kind: pipeline -name: manifest - -platform: - os: linux - arch: amd64 - -steps: -- name: server - image: plugins/manifest - settings: - auto_tag: true - ignore_missing: true - password: - from_secret: docker_password - spec: docker/manifest.server.tmpl - username: - from_secret: docker_username - when: - event: - - push - - tag - -- name: controller - image: plugins/manifest - settings: - auto_tag: true - ignore_missing: true - password: - from_secret: docker_password - spec: docker/manifest.controller.tmpl - username: - from_secret: docker_username - when: - event: - - push - - tag - -- name: agent - image: plugins/manifest - settings: - auto_tag: true - ignore_missing: true - password: - from_secret: docker_password - spec: docker/manifest.agent.tmpl - username: - from_secret: docker_username - when: - event: - - push - - tag +trigger: + event: + - push + - tag depends_on: - linux-amd64 -- linux-arm -- linux-arm64 -... +--- +kind: pipeline +type: docker +name: linux-arm + +platform: + arch: arm + os: linux + +steps: +- name: build + image: golang:1.12 + commands: + - sh scripts/build.sh + environment: + GOARCH: arm + GOOS: linux + +- name: publish_drone + image: plugins/docker:18 + settings: + auto_tag: true + auto_tag_suffix: linux-arm + dockerfile: docker/Dockerfile.drone.linux.arm + repo: drone/drone + username: + from_secret: docker_username + password: + from_secret: docker_password + +- name: publish_agent + image: plugins/docker:18 + settings: + auto_tag: true + auto_tag_suffix: linux-arm + dockerfile: docker/Dockerfile.agent.linux.arm + repo: drone/agent + username: + from_secret: docker_username + password: + from_secret: docker_password + +- name: publish_controller + image: plugins/docker:18 + settings: + auto_tag: true + auto_tag_suffix: linux-arm + dockerfile: docker/Dockerfile.controller.linux.arm + repo: drone/controller + username: + from_secret: docker_username + password: + from_secret: docker_password + +trigger: + event: + - push + - tag + +depends_on: +- linux-amd64 + +--- +kind: pipeline +type: ssh +name: windows-1809-amd64 + +platform: + os: windows + +server: + host: windows.1809.amd64.ssh.pipeline + password: + from_secret: windows_password + user: + from_secret: windows_username + +steps: +- name: build + commands: + - powershell.exe scripts/build.ps1 + - docker login -u $env:USERNAME -p $env:PASSWORD + - docker build -f docker/Dockerfile.agent.windows.1809 -t drone/agent:windows-1809-amd64 . + - docker push drone/agent:windows-1809-amd64 + environment: + PASSWORD: + from_secret: docker_password + USERNAME: + from_secret: docker_username + +trigger: + event: + - push + +depends_on: +- linux-amd64 + +--- +kind: pipeline +type: ssh +name: windows-1903-amd64 + +platform: + os: windows + +server: + host: windows.1903.amd64.ssh.pipeline + password: + from_secret: windows_password + user: + from_secret: windows_username + +steps: +- name: build + commands: + - powershell.exe scripts/build.ps1 + - docker login -u $env:USERNAME -p $env:PASSWORD + - docker build -f docker/Dockerfile.agent.windows.1903 -t drone/agent:windows-1903-amd64 . + - docker push drone/agent:windows-1903-amd64 + environment: + PASSWORD: + from_secret: docker_password + USERNAME: + from_secret: docker_username + +trigger: + event: + - push + +depends_on: +- linux-amd64 + +--- +kind: pipeline +type: docker +name: manifest + +steps: +- name: publish_server + image: plugins/manifest:1 + settings: + auto_tag: true + ignore_missing: true + spec: docker/manifest.server.tmpl + username: + from_secret: docker_username + password: + from_secret: docker_password + +- name: publish_agent + image: plugins/manifest:1 + settings: + auto_tag: true + ignore_missing: true + spec: docker/manifest.agent.tmpl + username: + from_secret: docker_username + password: + from_secret: docker_password + +- name: publish_controller + image: plugins/manifest:1 + settings: + auto_tag: true + ignore_missing: true + spec: docker/manifest.controller.tmpl + username: + from_secret: docker_username + password: + from_secret: docker_password + +trigger: + event: + - push + - tag + +depends_on: +- linux-arm64 +- linux-arm +- windows-1903-amd64 +- windows-1809-amd64 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 755fa83e..6cf7ad7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Added +- support for windows server 1903, by [@bradrydzewski](https://github.com/bradrydzewski). ## [1.2.3] - 2019-07-30 ### Added diff --git a/docker/Dockerfile.agent.windows.1803 b/docker/Dockerfile.agent.windows.1803 index 1ba62bcb..9c369ef3 100644 --- a/docker/Dockerfile.agent.windows.1803 +++ b/docker/Dockerfile.agent.windows.1803 @@ -10,5 +10,5 @@ ENV DRONE_RUNNER_CAPACITY=1 LABEL com.centurylinklabs.watchtower.stop-signal="SIGINT" -ADD release/windows/1803/amd64/drone-agent.exe C:/drone-agent.exe +ADD release/windows/amd64/drone-agent.exe C:/drone-agent.exe ENTRYPOINT [ "C:\\drone-agent.exe" ] diff --git a/docker/Dockerfile.agent.windows.1809 b/docker/Dockerfile.agent.windows.1809 index e2e0d294..831401e0 100644 --- a/docker/Dockerfile.agent.windows.1809 +++ b/docker/Dockerfile.agent.windows.1809 @@ -10,5 +10,5 @@ ENV DRONE_RUNNER_CAPACITY=1 LABEL com.centurylinklabs.watchtower.stop-signal="SIGINT" -ADD release/windows/1809/amd64/drone-agent.exe C:/drone-agent.exe +ADD release/windows/amd64/drone-agent.exe C:/drone-agent.exe ENTRYPOINT [ "C:\\drone-agent.exe" ] diff --git a/docker/Dockerfile.agent.windows.1903 b/docker/Dockerfile.agent.windows.1903 new file mode 100644 index 00000000..a7d34426 --- /dev/null +++ b/docker/Dockerfile.agent.windows.1903 @@ -0,0 +1,14 @@ +FROM mcr.microsoft.com/windows/nanoserver:1903 +USER ContainerAdministrator + +ENV GODEBUG=netdns=go +ENV DRONE_RUNNER_OS=windows +ENV DRONE_RUNNER_ARCH=amd64 +ENV DRONE_RUNNER_PLATFORM=windows/amd64 +ENV DRONE_RUNNER_KERNEL=1903 +ENV DRONE_RUNNER_CAPACITY=1 + +LABEL com.centurylinklabs.watchtower.stop-signal="SIGINT" + +ADD release/windows/amd64/drone-agent.exe C:/drone-agent.exe +ENTRYPOINT [ "C:\\drone-agent.exe" ] diff --git a/docker/manifest.agent.tmpl b/docker/manifest.agent.tmpl index 2d8257ea..1db9863b 100644 --- a/docker/manifest.agent.tmpl +++ b/docker/manifest.agent.tmpl @@ -34,4 +34,10 @@ manifests: platform: architecture: amd64 os: windows - variant: 1803 + variant: 1809 + - + image: drone/agent:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1903-amd64 + platform: + architecture: amd64 + os: windows + variant: 1903 \ No newline at end of file diff --git a/go.mod b/go.mod index bd66f9b5..557f46ae 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/drone/drone-go v1.0.5 github.com/drone/drone-runtime v1.0.7 github.com/drone/drone-ui v0.0.0-20190530175131-92ba3df1e0a9 - github.com/drone/drone-yaml v1.2.2 + github.com/drone/drone-yaml v1.2.3-0.20190807054305-a4a63fe917cb github.com/drone/envsubst v1.0.1 github.com/drone/go-license v1.0.2 github.com/drone/go-login v1.0.4-0.20190311170324-2a4df4f242a2 diff --git a/go.sum b/go.sum index 19b20dc6..ac4cc6b1 100644 --- a/go.sum +++ b/go.sum @@ -98,6 +98,8 @@ github.com/drone/drone-yaml v1.2.2-0.20190719012529-c50000a465ee h1:/zyEkv56+T6J github.com/drone/drone-yaml v1.2.2-0.20190719012529-c50000a465ee/go.mod h1:l/ehbHx9TGs4jgzhRnP5d+M9tmRsAmWyBHWAFEOXrk4= github.com/drone/drone-yaml v1.2.2 h1:Srf8OlAHhR7SXX5Ax01dP5tpZENsrEKyg35E2nNkIew= github.com/drone/drone-yaml v1.2.2/go.mod h1:QsqliFK8nG04AHFN9tTn9XJomRBQHD4wcejWW1uz/10= +github.com/drone/drone-yaml v1.2.3-0.20190807054305-a4a63fe917cb h1:YsuNqXQD8+FbFOsDZLYimmkzJxkN0h6gzAH1r0xk/qk= +github.com/drone/drone-yaml v1.2.3-0.20190807054305-a4a63fe917cb/go.mod h1:QsqliFK8nG04AHFN9tTn9XJomRBQHD4wcejWW1uz/10= github.com/drone/envsubst v1.0.1 h1:NOOStingM2sbBwsIUeQkKUz8ShwCUzmqMxWrpXItfPE= github.com/drone/envsubst v1.0.1/go.mod h1:bkZbnc/2vh1M12Ecn7EYScpI4YGYU0etwLJICOWi8Z0= github.com/drone/go-license v1.0.2 h1:7OwndfYk+Lp/cGHkxe4HUn/Ysrrw3WYH2pnd99yrkok= @@ -176,6 +178,7 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6 h1:qCv4319q2q7XKn0MQbi8p37hsJ+9Xo8e6yojA73JVxk= github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6/go.mod h1:fXcdFsQoipQa7mwORhKad5jmDCeSy/RCGzWA08PO0lM= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/nomad v0.0.0-20190125003214-134391155854 h1:L7WhLZt2ory/kQWxqkMwOiBpIoa4BWoadN7yx8LHEtk=