Skip to content

Commit

Permalink
refactor: move oci_go_image to root module (#398)
Browse files Browse the repository at this point in the history
* refactor: move oci_go_image to root module

Add an oci_push target to github container registry - will wire up delivery in a later PR

* chore: update importpath

* add comment

* link back to repo
  • Loading branch information
alexeagle authored Jan 14, 2025
1 parent 9db557f commit b7d38d4
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 49 deletions.
1 change: 0 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ java-soap/
jest/
nestjs/
node_snapshot_flags/
oci_go_image/
oci_java_image/
oci_python_image/
pnpm-workspaces/
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
go_workspaces/**
jest/**
nestjs/**
oci_go_image/**
oci_python_image/**
pnpm-workspaces/**
prisma/**
Expand Down
29 changes: 26 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ bazel_dep(name = "aspect_rules_swc", version = "2.0.0")
bazel_dep(name = "aspect_rules_ts", version = "3.0.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0")
bazel_dep(name = "gazelle", version = "0.36.0")
bazel_dep(name = "container_structure_test", version = "1.19.1")
bazel_dep(name = "gazelle", version = "0.40.0")
bazel_dep(name = "googletest", version = "1.15.2")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_apple", version = "3.0.0")
bazel_dep(name = "rules_buf", version = "0.3.0")
bazel_dep(name = "rules_cc", version = "0.1.0")
bazel_dep(name = "rules_go", version = "0.48.0")
bazel_dep(name = "rules_go", version = "0.50.1")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_jvm_external", version = "6.3")
bazel_dep(name = "rules_multitool", version = "0.12.0")
bazel_dep(name = "rules_oci", version = "2.0.1")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_python", version = "0.40.0")
bazel_dep(name = "rules_python_gazelle_plugin", version = "0.35.0")
Expand Down Expand Up @@ -194,7 +198,12 @@ use_repo(go_sdk, "go_sdk")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(go_deps, "org_golang_google_grpc", "org_golang_google_protobuf")
go_deps.module(
path = "github.com/google/go-cmp",
sum = "h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=",
version = "v0.5.9",
)
use_repo(go_deps, "com_github_google_go_cmp", "org_golang_google_grpc", "org_golang_google_protobuf")

non_module_deps = use_extension("@rules_swift//swift:extensions.bzl", "non_module_deps")
use_repo(
Expand Down Expand Up @@ -223,3 +232,17 @@ use_repo(
swift_deps,
"swiftpkg_swifterswift",
)

##########################
# Container images
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")
1 change: 0 additions & 1 deletion oci_go_image/.bazeliskrc

This file was deleted.

2 changes: 0 additions & 2 deletions oci_go_image/.bazelrc

This file was deleted.

1 change: 0 additions & 1 deletion oci_go_image/.bazelversion

This file was deleted.

2 changes: 0 additions & 2 deletions oci_go_image/.gitignore

This file was deleted.

18 changes: 15 additions & 3 deletions oci_go_image/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ load("@aspect_bazel_lib//lib:testing.bzl", "assert_archive_contains")
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_go//go:def.bzl", "go_binary", "go_library")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_push")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

go_library(
name = "app_lib",
srcs = ["main.go"],
importpath = "example.com/custom_registry/app",
importpath = "github.com/aspect-build/bazel-examples/oci_go_image",
visibility = ["//visibility:private"],
deps = ["@com_github_google_go_cmp//cmp"],
)
Expand Down Expand Up @@ -36,8 +36,13 @@ assert_archive_contains(

oci_image(
name = "image",
# This is defined by an oci.pull() call in /MODULE.bazel
base = "@distroless_base",
entrypoint = ["/app"],
# Link the resulting image back to the repository where the build is defined.
labels = {
"org.opencontainers.image.source": "https://github.com/aspect-build/bazel-examples",
},
tars = [":app_layer"],
)

Expand All @@ -51,7 +56,7 @@ platform_transition_filegroup(
}),
)

# $ bazel run :load
# $ bazel run //oci_go_image:load
# $ docker run --rm gcr.io/example:latest
# string(
# - "Hello World",
Expand All @@ -71,3 +76,10 @@ container_structure_test(
image = ":transitioned_image",
tags = ["requires-docker"],
)

oci_push(
name = "push",
image = ":transitioned_image",
remote_tags = ["latest"],
repository = "ghcr.io/aspect-build/oci_go_image_example",
)
27 changes: 0 additions & 27 deletions oci_go_image/MODULE.bazel

This file was deleted.

1 change: 0 additions & 1 deletion oci_go_image/WORKSPACE.bazel

This file was deleted.

5 changes: 0 additions & 5 deletions oci_go_image/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions oci_go_image/go.sum

This file was deleted.

0 comments on commit b7d38d4

Please sign in to comment.