Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for multi arch images #21

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions .drone.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
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": "main"},
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.branch == "main" and ctx.build.event in ["push", "tag"]:
pipelines.append(pipeline_build(ctx, "amd64"))
pipelines.append(pipeline_build(ctx, "arm64"))
pipelines.append(pipeline_manifest(ctx))

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

This file was deleted.