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

Fixup #2

Draft
wants to merge 1 commit into
base: od-dockerize-nextjs
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
9 changes: 9 additions & 0 deletions frontend/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bazel_dep(name = "aspect_rules_ts", version = "2.2.0")
bazel_dep(name = "aspect_rules_rollup", version = "1.0.2")
bazel_dep(name = "aspect_rules_webpack", version = "0.14.0")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "rules_nodejs", version = "5.8.2")
bazel_dep(name = "rules_oci", version = "1.7.5")

pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm", dev_dependency = True)
Expand Down Expand Up @@ -43,6 +44,14 @@ oci.pull(
image = "node:20-slim",
platforms = [
"linux/amd64",
"linux/arm64/v8",
],
)
use_repo(oci, "debian_node")

node = use_extension(
"@rules_nodejs//nodejs:extensions.bzl",
"node",
dev_dependency = True,
)
use_repo(node, "nodejs_toolchains")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed on MacOS under bzlmod to run

--extra_toolchains=@nodejs_toolchains//:linux_arm64_toolchain_target

WORKSPACE does not have this issue on transitions

45 changes: 43 additions & 2 deletions frontend/next.js/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,57 @@ build_test(
],
)

platform(
name = "linux_amd64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

platform(
name = "linux_arm64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
)

next_bin.next_binary(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a js_run_devserver binary which is for local development and won't work in a container, what you want for the image is just a js_binary which is what next_bin.next_binary is under the hood

name = "next_js_start",
fixed_args = ["start"],
chdir = package_name(),
data = [
"//next.js/pages",
"//next.js/public",
"//next.js/styles",
":next",
"next.config.js",
"package.json",
":node_modules/@bazel-example/one",
":node_modules/is-even",
":node_modules/next",
":node_modules/react",
":node_modules/react-dom",
":node_modules/typescript",
],
)

js_image_layer(
name = "layers",
binary = ":next_start",
binary = ":next_js_start",
platform = select({
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For transitioning the target platform to linux for for the container runtime so the image can be built locally on a mac

"@platforms//cpu:arm64": ":linux_arm64",
"@platforms//cpu:x86_64": ":linux_amd64",
}),
root = "/app",
)

oci_image(
name = "image",
base = "@debian_node",
cmd = ["/app/next.js/next_start"],
cmd = ["/app/next.js/next_js_start"],
workdir = "/app/next.js/next_js_start.runfiles/_main",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workdir must be set to the root of the runfiles tree in the container

entrypoint = ["/bin/bash"],
tars = [
":layers",
Expand Down