From e4db7bd30c1df10820ea77673abdf293044387cf Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Tue, 8 Aug 2023 20:56:53 +0100 Subject: [PATCH] Add example of multi-arch oci_tarball --- examples/multi_arch_go/BUILD | 66 ++++++++++++++++++++++++++++++++++ examples/multi_arch_go/main.go | 7 ++++ 2 files changed, 73 insertions(+) create mode 100644 examples/multi_arch_go/BUILD create mode 100644 examples/multi_arch_go/main.go diff --git a/examples/multi_arch_go/BUILD b/examples/multi_arch_go/BUILD new file mode 100644 index 00000000..c7dd90ba --- /dev/null +++ b/examples/multi_arch_go/BUILD @@ -0,0 +1,66 @@ +load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("@rules_pkg//:pkg.bzl", "pkg_tar") +load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push", "oci_tarball") + +go_library( + name = "lib", + srcs = ["main.go"], + importpath = "main", +) + +go_binary( + name = "bin-x86_64", + embed = [":lib"], + goos = "linux", + goarch = "amd64", +) + +pkg_tar( + name = "bin-x86_64_tar", + srcs = [":bin-x86_64"], + package_dir = "usr/local/bin", +) + +go_binary( + name = "bin-arm64", + embed = [":lib"], + goos = "linux", + goarch = "arm64", +) + +pkg_tar( + name = "bin-arm64_tar", + srcs = [":bin-arm64"], + package_dir = "usr/local/bin", +) + +oci_image( + name = "image-x86_64", + base = "@ubuntu_linux_amd64", + entrypoint = ["/usr/local/bin/bin-x86_64"], + tars = [":bin-x86_64_tar"], +) + +oci_image( + name = "image-arm64", + base = "@ubuntu_linux_arm64_v8", + entrypoint = ["/usr/local/bin/bin-arm64"], + tars = [":bin-arm64_tar"], +) + +oci_image_index( + name = "image-multiarch", + images = [ + ":image-arm64", + ":image-x86_64", + ], +) + +oci_tarball( + name = "image-multiarch-tar", + image = ":image-multiarch", + repo_tags = [ + "docker.com/example:latest", + ], +) diff --git a/examples/multi_arch_go/main.go b/examples/multi_arch_go/main.go new file mode 100644 index 00000000..84dcf5cb --- /dev/null +++ b/examples/multi_arch_go/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("yo") +}