Move to starlark builds and fix multi-arch

This commit is contained in:
IamTheFij 2020-01-10 14:53:59 -08:00
parent 7e1b593757
commit d1be7a6024
4 changed files with 150 additions and 139 deletions

100
.drone.star Normal file
View File

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

View File

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

25
manifest-client.tml Normal file
View File

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

25
manifest-server.tmpl Normal file
View File

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