diff --git a/.drone.starlark b/.drone.starlark new file mode 100644 index 0000000..ec15bb3 --- /dev/null +++ b/.drone.starlark @@ -0,0 +1,130 @@ +# this starlark script should be used to generate the .drone.yml +# configuration file. + +def main(ctx): + # TODO consider running unit tests before building and + # publishing docker images. + before = {} + + stages = [ + linux('arm'), + linux('arm64'), + linux('amd64'), + windows('1903'), + windows('1809'), + ] + + after = manifest() + + # the after stage should only execute after all previous + # stages complete. this builds the dependency graph. + for stage in stages: + after['depends_on'].append(stage['name']) + + return stages + [ after ] + +# create a pipeline stage responsible for building and +# publishing the Docker image on linux. +def linux(arch): + return { + 'kind': 'pipeline', + 'type': 'docker', + 'name': 'linux-%s' % arch, + 'platform': { + 'os': 'linux', + 'arch': arch, + }, + 'steps': [ + { + 'name': 'build', + 'image': 'golang:1.10', + 'commands': [ + 'cd posix', + 'tar -xf fixtures.tar -C /', + 'go test -v', + ], + }, + { + 'name': 'publish', + 'image': 'plugins/docker', + 'settings': { + 'auto_tag': 'true', + 'auto_tag_suffix': 'linux-%s' % arch, + 'dockerfile': 'docker/Dockerfile.linux.%s' % arch, + 'password': { + 'from_secret': 'docker_password', + }, + 'repo': 'drone/git', + 'username': 'drone', + }, + 'when': { + 'event': ['push', 'tag'] + } + } + ] + } + +# create a pipeline stage responsible for building and +# publishing the Docker image on windows. The windows stage +# uses an ssh runner, as opposed to a docker runner. +def 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': [ + 'docker login -u $env:USERNAME -p $env:PASSWORD', + 'docker build -f docker/Dockerfile.windows.%s -t drone/git:windows-%s-amd64 .' % (version, version), + 'docker push drone/git:windows-%s-amd64' % version, + ], + }, + ], + 'trigger': { + 'event': ['push'] + } + } + +# create a pipeline stage responsible for creating and +# publishing a docker manifest to the registry. +def manifest(): + return { + 'kind': 'pipeline', + 'type': 'docker', + 'name': 'manifest', + 'steps': [ + { + 'name': 'manifest', + 'image': 'plugins/manifest', + 'settings': { + 'auto_tag': 'true', + 'username': 'drone', + 'password': { + 'from_secret': 'docker_password' + }, + 'spec': 'docker/manifest.tmpl', + 'ignore_missing': 'true', + }, + }, + ], + 'depends_on': [], + 'trigger': { + 'event': ['push', 'tag'] + } + } \ No newline at end of file diff --git a/.drone.windows.jsonnet b/.drone.windows.jsonnet deleted file mode 100644 index c07acc1..0000000 --- a/.drone.windows.jsonnet +++ /dev/null @@ -1,74 +0,0 @@ -local windows_pipe = '\\\\\\\\.\\\\pipe\\\\docker_engine'; -local windows_pipe_volume = 'docker_pipe'; -local versions = [ - //'1803', - '1809', -]; -local trigger = { - ref: [ - 'refs/heads/master', - 'refs/tags/**', - ], -}; -local pipeline_name(version) = 'Windows ' + version; - -local pipeline(version, arch) = { - kind: 'pipeline', - name: pipeline_name(version), - - platform: { - os: 'windows', - arch: arch, - version: version, - }, - - steps: [{ - name: 'git', - image: 'plugins/docker:windows-1809', // TODO: This should just use the manifest - settings: { - repo: 'drone/git', - dockerfile: 'docker/Dockerfile.windows.' + version, - auto_tag: true, - auto_tag_suffix: 'windows-' + version + '-' + arch, - - username: { from_secret: 'docker_username' }, - password: { from_secret: 'docker_password' }, - - // Windows specific options - daemon_off: true, - purge: 'false', // TODO: Fix bug where setting false won't generate the yaml value - }, - volumes: [{ name: windows_pipe_volume, path: windows_pipe }], - }], - - volumes: [{ name: windows_pipe_volume, host: { path: windows_pipe } }], - trigger: trigger, -}; - -[ - pipeline(version, 'amd64') - for version in versions -] + [ - { - kind: 'pipeline', - name: 'Image Manifest', - - steps: [{ - name: 'manifest', - image: 'plugins/manifest', - settings: { - spec: 'docker/manifest.tmpl', - ignore_missing: true, - - username: { from_secret: 'docker_username' }, - password: { from_secret: 'docker_password' }, - }, - }], - - depends_on: [ - pipeline_name(version) - for version in versions - ], - trigger: trigger, - }, -] diff --git a/.drone.windows.yml b/.drone.windows.yml deleted file mode 100644 index 0966053..0000000 --- a/.drone.windows.yml +++ /dev/null @@ -1,65 +0,0 @@ ---- -kind: pipeline -name: Windows 1809 - -platform: - os: windows - arch: amd64 - version: 1809 - -steps: -- name: git - image: plugins/docker:windows-1809 - settings: - auto_tag: true - auto_tag_suffix: windows-1809-amd64 - daemon_off: true - dockerfile: docker/Dockerfile.windows.1809 - password: - from_secret: docker_password - purge: false - repo: drone/git - username: - from_secret: docker_username - volumes: - - name: docker_pipe - path: \\\\.\\pipe\\docker_engine - -volumes: -- name: docker_pipe - host: - path: \\\\.\\pipe\\docker_engine - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - ---- -kind: pipeline -name: Image Manifest - -platform: - os: linux - arch: amd64 - -steps: -- name: manifest - 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: -- Windows 1809 - -... diff --git a/.gitignore b/.gitignore index 0488dfe..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +0,0 @@ -.drone.jsonnet -.drone.jsonnet.yml \ No newline at end of file