From d1be7a60247f41a5d51603b2e76d704953889c2d Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 10 Jan 2020 14:53:59 -0800 Subject: [PATCH] Move to starlark builds and fix multi-arch --- .drone.star | 100 +++++++++++++++++++++++++++++++ .drone.yml | 139 ------------------------------------------- manifest-client.tml | 25 ++++++++ manifest-server.tmpl | 25 ++++++++ 4 files changed, 150 insertions(+), 139 deletions(-) create mode 100644 .drone.star delete mode 100644 .drone.yml create mode 100644 manifest-client.tml create mode 100644 manifest-server.tmpl diff --git a/.drone.star b/.drone.star new file mode 100644 index 0000000..0b37dfe --- /dev/null +++ b/.drone.star @@ -0,0 +1,100 @@ +# Build pipelines +def main(ctx): + pipelines = [] + + # Add docker push pipelines + pipelines += push_to_docker(ctx, "client") + pipelines += push_to_docker(ctx, "server") + + return pipelines + + +# Builds a pipeline to push to docker +def push_to_docker(ctx, context): + return [{ + "kind": "pipeline", + "name": "push to docker ({})".format(context), + # Add tests dependency + "depends_on": [], + "trigger": { + "event": ["tag"], + "ref": [ + "refs/heads/master", + "refs/tags/v*", + ], + }, + "steps": [ + push_docker_step(context, "linux-amd64", "x86_64", "library"), + push_docker_step(context, "linux-arm", "arm", "arm32v6"), + push_docker_step(context, "linux-arm64", "aarch64", "arm64v8"), + { + "name": "publish manifest", + "image": "plugins/manifest", + "settings": { + "spec": "manifest-{}.tmpl".format(context), + "auto_tag": True, + "ignore_missing": True, + "username": { + "from_secret": "docker_username", + }, + "password": { + "from_secret": "docker_password", + }, + } + }, + notify_step(), + ], + }] + + +# Build and push docker image +def push_docker_step(context, tag_suffix, arch="amd64", repo="library"): + return { + "name": "build", + "image": "plugins/docker", + "settings": { + "repo": "iamthefij/dockamole-{}".format(context), + "context": context, + "auto_tag": True, + "auto_tag_suffix": tag_suffix, + "username": { + "from_secret": "docker_username", + }, + "password": { + "from_secret": "docker_password", + }, + "build_args": [ + "ARCH={}".format(arch), + "REPO={}".format(repo), + ], + }, + } + + +# Builds a notify step that will notify when the previous step changes +def notify_step(): + return { + "name": "notify", + "image": "drillster/drone-email", + "settings": { + "host": { + "from_secret": "SMTP_HOST", + }, + "username": { + "from_secret": "SMTP_USER", + }, + "password": { + "from_secret": "SMTP_PASS", + }, + "from": "drone@iamthefij.com", + }, + "when": { + "status": [ + "changed", + "failure", + ], + }, + } + + +# vim: ft=python diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 2ca8282..0000000 --- a/.drone.yml +++ /dev/null @@ -1,139 +0,0 @@ -kind: pipeline -name: publish client to docker hub - -trigger: - event: - - push - - tag - ref: - - refs/heads/master - - refs/tags/v* - -steps: - - - name: push image - amd64 - image: plugins/docker - settings: - repo: iamthefij/dockamole-client - context: client - dockerfile: client/Dockerfile - auto_tag: true - auto_tag_suffix: linux-amd64 - username: - from_secret: docker_username - password: - from_secret: docker_password - - - name: push image - arm32v7 - image: plugins/docker - settings: - repo: iamthefij/dockamole-client - context: client - dockerfile: client/Dockerfile - auto_tag: true - auto_tag_suffix: linux-arm32v7 - username: - from_secret: docker_username - password: - from_secret: docker_password - build_args: - - REPO=arm32v7 - - GOARCH=arm - - - name: push image - arm64 - image: plugins/docker - settings: - repo: iamthefij/dockamole-client - context: client - dockerfile: client/Dockerfile - auto_tag: true - auto_tag_suffix: linux-arm64v8 - username: - from_secret: docker_username - password: - from_secret: docker_password - build_args: - - REPO=arm64v8 - - GOARCH=arm - - - name: publish manifest - image: plugins/manifest - settings: - spec: client/manifest.tmpl - auto_tag: true - ignore_missing: true - username: - from_secret: docker_username - password: - from_secret: docker_password - ---- - -kind: pipeline -name: publish server to docker hub - -trigger: - event: - - push - - tag - ref: - - refs/heads/master - - refs/tags/v* - -steps: - - - name: push image - amd64 - image: plugins/docker - settings: - repo: iamthefij/dockamole-server - context: server - dockerfile: server/Dockerfile - auto_tag: true - auto_tag_suffix: linux-amd64 - username: - from_secret: docker_username - password: - from_secret: docker_password - - - name: push image - arm32v7 - image: plugins/docker - settings: - repo: iamthefij/dockamole-server - context: server - dockerfile: server/Dockerfile - auto_tag: true - auto_tag_suffix: linux-arm32v7 - username: - from_secret: docker_username - password: - from_secret: docker_password - build_args: - - REPO=arm32v7 - - GOARCH=arm - - - name: push image - arm64 - image: plugins/docker - settings: - repo: iamthefij/dockamole-server - context: server - dockerfile: server/Dockerfile - auto_tag: true - auto_tag_suffix: linux-arm64v8 - username: - from_secret: docker_username - password: - from_secret: docker_password - build_args: - - REPO=arm64v8 - - GOARCH=arm - - - name: publish manifest - image: plugins/manifest - settings: - spec: server/manifest.tmpl - auto_tag: true - ignore_missing: true - username: - from_secret: docker_username - password: - from_secret: docker_password diff --git a/manifest-client.tml b/manifest-client.tml new file mode 100644 index 0000000..7b53092 --- /dev/null +++ b/manifest-client.tml @@ -0,0 +1,25 @@ +image: iamthefij/dockamole-client:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} +{{#if build.tags}} +tags: +{{#each build.tags}} + - {{this}} +{{/each}} +{{/if}} +manifests: + - + image: iamthefij/dockamole-client:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 + platform: + architecture: amd64 + os: linux + - + image: iamthefij/dockamole-client:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 + platform: + architecture: arm64 + os: linux + variant: v8 + - + image: iamthefij/dockamole-client:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm + platform: + architecture: arm + os: linux + variant: v7 diff --git a/manifest-server.tmpl b/manifest-server.tmpl new file mode 100644 index 0000000..f88118e --- /dev/null +++ b/manifest-server.tmpl @@ -0,0 +1,25 @@ +image: iamthefij/dockamole-server:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} +{{#if build.tags}} +tags: +{{#each build.tags}} + - {{this}} +{{/each}} +{{/if}} +manifests: + - + image: iamthefij/dockamole-server:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 + platform: + architecture: amd64 + os: linux + - + image: iamthefij/dockamole-server:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 + platform: + architecture: arm64 + os: linux + variant: v8 + - + image: iamthefij/dockamole-server:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm + platform: + architecture: arm + os: linux + variant: v7