Skip to content

Commit 21ad93c

Browse files
committed
Revert "chore: try rules_img"
This reverts commit 5658222.
1 parent 5658222 commit 21ad93c

File tree

8 files changed

+98
-24
lines changed

8 files changed

+98
-24
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ go_workspaces/
1414
java-soap/
1515
jest/
1616
nestjs/
17+
node_snapshot_flags/
1718
oci_java_image/
1819
prisma/
1920
rules_nodejs_to_rules_js_migration/

MODULE.bazel

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,30 @@ use_repo(
258258
"swiftpkg_swifterswift",
259259
)
260260

261+
##########################
262+
# Container images
263+
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
264+
oci.pull(
265+
name = "distroless_base",
266+
digest = "sha256:ccaef5ee2f1850270d453fdf700a5392534f8d1a8ca2acda391fbb6a06b81c86",
267+
image = "gcr.io/distroless/base",
268+
platforms = [
269+
"linux/amd64",
270+
"linux/arm64",
271+
],
272+
)
273+
oci.pull(
274+
name = "ubuntu",
275+
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
276+
image = "ubuntu",
277+
platforms = [
278+
"linux/arm64/v8",
279+
"linux/amd64",
280+
],
281+
tag = "latest",
282+
)
283+
use_repo(oci, "distroless_base", "distroless_base_linux_amd64", "distroless_base_linux_arm64", "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")
284+
261285
#########################
262286
# Support for Rust, see https://github.com/bazelbuild/rules_rust
263287
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
@@ -274,5 +298,3 @@ crate.from_cargo(
274298
manifests = ["//npm_packages/napi:Cargo.toml"],
275299
)
276300
use_repo(crate, "crate_index")
277-
278-
include("//tools:container_images.MODULE.bazel")

node_snapshot_flags/BUILD.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary")
2+
3+
js_binary(
4+
name = "snapshot",
5+
entry_point = "snapshot.js",
6+
node_options = [
7+
"--build-snapshot",
8+
# FIXME: this reference to snapshot.blob should appear below in the build-snapshot target
9+
# as that's the one that declares it in outs.
10+
# However I get an error when moving it to env={"NODE_OPTIONS": "--snapshot-blob..."}
11+
"--snapshot-blob=snapshot.blob",
12+
],
13+
fixed_args = ["name", "home"],
14+
)
15+
16+
js_run_binary(
17+
name = "build-snapshot",
18+
tool = "snapshot",
19+
outs = ["snapshot.blob"],
20+
)
21+
22+
js_binary(
23+
name = "index",
24+
entry_point = "index.js",
25+
data = ["snapshot.blob"],
26+
node_options = [
27+
"--snapshot-blob=$(rootpath snapshot.blob)",
28+
],
29+
)

node_snapshot_flags/MODULE.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bazel_dep(name = "rules_nodejs", version = "6.1.0")
2+
bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.6")
3+
4+
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
5+
node.toolchain(node_version = "18.8.0")

node_snapshot_flags/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# user-land snapshots in Node.js v18.8.0
2+
3+
Based on
4+
https://blog.logrocket.com/snapshot-flags-node-js-v18-8/

node_snapshot_flags/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
console.log('current working directory', globalThis.path)
2+
console.log('First Arg', globalThis.firstArg)
3+
console.log('Second Argument', globalThis.secondArg)
4+
console.log('current process Argv', process.argv)
5+
console.log('Global Object', globalThis)

node_snapshot_flags/snapshot.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const path = require('path')
2+
3+
console.log(process.cwd())
4+
globalThis.path = process.cwd()
5+
globalThis.file = __dirname
6+
const name = 'I am geezy'
7+
8+
console.log(process.argv)
9+
globalThis.firstArg = process.argv[2]
10+
globalThis.secondArg = process.argv[3]

oci_go_image/BUILD.bazel

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
load("@aspect_bazel_lib//lib:testing.bzl", "assert_archive_contains")
2+
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
23
load("@container_structure_test//:defs.bzl", "container_structure_test")
34
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
4-
load("@rules_img//img:image.bzl", "image_index", "image_manifest")
5-
load("@rules_img//img:load.bzl", "image_load")
6-
load("@rules_img//img:push.bzl", "image_push")
5+
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_push")
76
load("@tar.bzl", "mutate", "tar")
87

98
go_library(
@@ -42,26 +41,26 @@ assert_archive_contains(
4241
expected = ["app"],
4342
)
4443

45-
image_manifest(
46-
name = "_image",
44+
oci_image(
45+
name = "image",
4746
# This is defined by an oci.pull() call in /MODULE.bazel
4847
base = "@distroless_base",
4948
entrypoint = ["/app"],
5049
# Link the resulting image back to the repository where the build is defined.
5150
labels = {
5251
"org.opencontainers.image.source": "https://github.com/aspect-build/bazel-examples",
5352
},
54-
layers = [":app_layer"],
53+
tars = [":app_layer"],
5554
)
5655

5756
# This is the target that should be released to the target platform
58-
image_index(
59-
name = "image",
60-
manifests = [":_image"],
61-
platforms = [
62-
"@rules_go//go/toolchain:linux_arm64",
63-
"@rules_go//go/toolchain:linux_amd64",
64-
],
57+
platform_transition_filegroup(
58+
name = "transitioned_image",
59+
srcs = [":image"],
60+
target_platform = select({
61+
"@platforms//cpu:arm64": "@rules_go//go/toolchain:linux_arm64",
62+
"@platforms//cpu:x86_64": "@rules_go//go/toolchain:linux_amd64",
63+
}),
6564
)
6665

6766
# $ bazel run //oci_go_image:load
@@ -70,11 +69,11 @@ image_index(
7069
# - "Hello World",
7170
# + "Hello Go",
7271
# )
73-
image_load(
72+
oci_load(
7473
name = "load",
7574
# Use the image built for the target platform
76-
image = ":image",
77-
tag = "gcr.io/example:latest",
75+
image = ":transitioned_image",
76+
repo_tags = ["gcr.io/example:latest"],
7877
)
7978

8079
container_structure_test(
@@ -88,13 +87,12 @@ container_structure_test(
8887
],
8988
)
9089

91-
image_push(
90+
oci_push(
9291
name = "push",
93-
image = ":image",
94-
registry = "ttl.sh",
95-
repository = "/aspect-build/oci_go_image_example",
96-
tags = [
97-
"24h",
92+
image = ":transitioned_image",
93+
remote_tags = [
9894
"latest",
95+
"24h",
9996
],
97+
repository = "ttl.sh/aspect-build/oci_go_image_example",
10098
)

0 commit comments

Comments
 (0)