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

feat(build/bazel): support OCI ImageIndex tarballs #9219

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 9 additions & 4 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ var tests = []struct {
args: []string{"-p", "target-with-package"},
deployments: []string{"helloweb"},
},
{
description: "bazel oci with multi-arch image tarball",
dir: "testdata/bazel-rules-oci-multi-arch",
deployments: []string{"web"},
},
{
description: "jib",
dir: "testdata/jib",
Expand Down Expand Up @@ -198,7 +203,7 @@ func TestRun(t *testing.T) {
ns, client := SetupNamespace(t)
args := append(test.args, "--cache-artifacts=false")
if test.dir == emptydir {
err := os.MkdirAll(filepath.Join(test.dir, "emptydir"), 0755)
err := os.MkdirAll(filepath.Join(test.dir, "emptydir"), 0o755)
t.Log("Creating empty directory")
if err != nil {
t.Errorf("Error creating empty dir: %s", err)
Expand All @@ -223,7 +228,7 @@ func TestRunTail(t *testing.T) {
t.SkipNow()
}
if test.dir == emptydir {
err := os.MkdirAll(filepath.Join(test.dir, "emptydir"), 0755)
err := os.MkdirAll(filepath.Join(test.dir, "emptydir"), 0o755)
t.Log("Creating empty directory")
if err != nil {
t.Errorf("Error creating empty dir: %s", err)
Expand All @@ -250,7 +255,7 @@ func TestRunTailDefaultNamespace(t *testing.T) {
t.SkipNow()
}
if test.dir == emptydir {
err := os.MkdirAll(filepath.Join(test.dir, "emptydir"), 0755)
err := os.MkdirAll(filepath.Join(test.dir, "emptydir"), 0o755)
t.Log("Creating empty directory")
if err != nil {
t.Errorf("Error creating empty dir: %s", err)
Expand All @@ -266,7 +271,7 @@ func TestRunTailDefaultNamespace(t *testing.T) {
}

func TestRunTailTolerateFailuresUntilDeadline(t *testing.T) {
var tsts = []struct {
tsts := []struct {
description string
dir string
args []string
Expand Down
1 change: 1 addition & 0 deletions integration/testdata/bazel-rules-oci-multi-arch/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --enable-bzlmod
80 changes: 80 additions & 0 deletions integration/testdata/bazel-rules-oci-multi-arch/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_tarball")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

go_library(
name = "app_lib",
srcs = ["main.go"],
importpath = "github.com/GoogleContainerTools/skaffold/v2/integration/testdata/bazel-rules-oci-multi-arch",
visibility = ["//visibility:private"],
deps = [],
)

go_binary(
name = "app",
embed = [":app_lib"],
visibility = ["//visibility:public"],
)

linux_amd64_binary = "app_linux-amd64"

linux_amd64_layer = "{}_layer".format(linux_amd64_binary)

linux_amd64_image = "{}_image".format(linux_amd64_binary)

go_cross_binary(
name = linux_amd64_binary,
platform = "@rules_go//go/toolchain:linux_amd64",
target = target,
)

pkg_tar(
name = linux_amd64_layer,
srcs = [linux_amd64_binary],
)

oci_image(
name = linux_amd64_image,
base = base,
entrypoint = ["/app"],
tars = [linux_amd64_layer],
)

linux_arm64_binary = "app_linux-arm64"

linux_arm64_layer = "{}_layer".format(linux_arm64_binary)

linux_arm64_image = "{}_image".format(linux_arm64_binary)

go_cross_binary(
name = linux_arm64_binary,
platform = "@rules_go//go/toolchain:linux_arm64",
target = target,
)

pkg_tar(
name = linux_arm64_layer,
srcs = [linux_arm64_binary],
)

oci_image(
name = linux_arm64_image,
base = base,
entrypoint = ["/app"],
tars = [linux_arm64_layer],
)

oci_image_index(
name = "image",
images = [
linux_amd64_image,
linux_arm64_image,
],
)

oci_tarball(
name = "image.tar",
format = "oci",
image = ":image",
repo_tags = ["app:latest"],
)
22 changes: 22 additions & 0 deletions integration/testdata/bazel-rules-oci-multi-arch/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module(name = "bazel-rules-oci-multi-arch")

bazel_dep(name = "rules_go", version = "0.43.0")
bazel_dep(name = "rules_oci", version = "1.4.3")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "distroless_base",
digest = "sha256:ccaef5ee2f1850270d453fdf700a5392534f8d1a8ca2acda391fbb6a06b81c86",
image = "gcr.io/distroless/base",
platforms = [
"linux/amd64",
"linux/arm64",
],
)
use_repo(
oci,
"distroless_base",
)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.21")
Empty file.
25 changes: 25 additions & 0 deletions integration/testdata/bazel-rules-oci-multi-arch/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment

metadata:
name: &name hello
labels:
app: *name

spec:
selector:
matchLabels:
app: *name
template:
metadata:
labels:
app: *name
spec:
containers:
- name: app
image: app
ports:
- containerPort: 8080
resources:
requests:
cpu: 200m
7 changes: 7 additions & 0 deletions integration/testdata/bazel-rules-oci-multi-arch/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hey, it's working!")
}
20 changes: 20 additions & 0 deletions integration/testdata/bazel-rules-oci-multi-arch/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: skaffold/v4beta8
kind: Config

metadata:
name: hello

build:
platforms: ["linux/amd64", "linux/arm64"]
artifacts:
- image: image
bazel:
target: //:image.tar

deploy:
kubectl: {}

manifests:
rawYaml:
- deploy.yaml

Loading
Loading