Skip to content

Commit

Permalink
multi-arch build pipeline (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhoglund authored Dec 29, 2023
1 parent fb51933 commit 842c934
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 96 deletions.
139 changes: 139 additions & 0 deletions .drone.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
def version(ctx):
# use git commit if this is not a tag event
if ctx.build.event != "tag":
return "git-{}".format(commit(ctx))

return ctx.build.ref.removeprefix("refs/tags/")


def version_tag(ctx, arch):
return "{}-{}".format(version(ctx), arch)


def commit(ctx):
return ctx.build.commit[:7]


def new_pipeline(name, arch, **kwargs):
pipeline = {
"kind": "pipeline",
"name": name,
"platform": {
"arch": arch,
},
"steps": [],
}

pipeline.update(kwargs)

return pipeline


def pipeline_test(ctx):
cache_volume = {"name": "cache", "temp": {}}
cache_mount = {"name": "cache", "path": "/go"}

# licensed-go image only supports amd64
return new_pipeline(
name="test",
arch="amd64",
trigger={"branch": ctx.repo.branch},
volumes=[cache_volume],
workspace={"path": "/go/src/github.com/{}".format(ctx.repo.slug)},
steps=[
{
"commands": ["make test"],
"image": "golangci/golangci-lint",
"name": "test",
"volumes": [cache_mount],
},
{
"commands": ["licensed cache", "licensed status"],
"image": "public.ecr.aws/kanopy/licensed-go",
"name": "license-check",
},
{
"image": "plugins/kaniko-ecr",
"name": "build",
"pull": "always",
"settings": {"no_push": True},
"volumes": [cache_mount],
"when": {"event": ["pull_request"]},
},
],
)


def pipeline_build(ctx, arch):
return new_pipeline(
depends_on=["test"],
name="publish-{}".format(arch),
arch=arch,
steps=[
{
"environment": {
"GIT_COMMIT": commit(ctx),
"VERSION": version(ctx),
},
"image": "plugins/kaniko-ecr",
"name": "publish",
"pull": "always",
"settings": {
"access_key": {"from_secret": "ecr_access_key"},
"secret_key": {"from_secret": "ecr_secret_key"},
"registry": {"from_secret": "ecr_registry"},
"repo": ctx.repo.name,
"tags": [version_tag(ctx, arch)],
"build_args": ["VERSION", "GIT_COMMIT"],
"create_repository": True,
},
}
],
)


def pipeline_manifest(ctx):
targets = [version(ctx)]

# only use "latest" for tagged releases
if ctx.build.event == "tag":
targets.append("latest")

return new_pipeline(
depends_on=["publish-amd64", "publish-arm64"],
name="publish-manifest",
arch="arm64",
steps=[
{
"name": "manifest",
"image": "public.ecr.aws/kanopy/buildah-plugin:v0.1.1",
"settings": {
"access_key": {"from_secret": "ecr_access_key"},
"secret_key": {"from_secret": "ecr_secret_key"},
"registry": {"from_secret": "ecr_registry"},
"repo": ctx.repo.name,
"manifest": {
"sources": [
version_tag(ctx, "amd64"),
version_tag(ctx, "arm64"),
],
"targets": targets,
},
},
},
],
)


def main(ctx):
pipelines = [pipeline_test(ctx)]

# only perform image builds for "push" and "tag" events
if ctx.build.event == "tag" or (
ctx.build.branch == ctx.repo.branch and ctx.build.event == "push"
):
pipelines.append(pipeline_build(ctx, "amd64"))
pipelines.append(pipeline_build(ctx, "arm64"))
pipelines.append(pipeline_manifest(ctx))

return pipelines
96 changes: 0 additions & 96 deletions .drone.yml

This file was deleted.

0 comments on commit 842c934

Please sign in to comment.