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

Download correct app-host for the target RID in order to support cross-compilation #320

Closed
njlr opened this issue Dec 6, 2022 · 6 comments

Comments

@njlr
Copy link
Contributor

njlr commented Dec 6, 2022

Full repro here: https://github.com/njlr/rules-dotnet-publish-docker

load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_dotnet//dotnet:defs.bzl", "fsharp_binary", "publish_binary")

fsharp_binary(
  name = "app",
  srcs = [
    "Program.fs",
  ],
  target_frameworks = [
    "net6.0",
  ],
  deps = [
    "@paket.main//microsoft.netcore.app.ref",
    "@paket.main//fsharp.core",
  ],
  visibility = [
    "//visibility:public",
  ],
)

publish_binary(
  name = "app_linux_x64",
  binary = ":app",
  target_framework = "net6.0",
  self_contained = True,
  runtime_identifier = "linux-x64",
  runtime_packs = [
    "@paket.main//microsoft.netcore.app.runtime.linux-x64",
  ],
)

pkg_tar(
  name = "app_linux_x64_archive",
  srcs = [
    ":app_linux_x64",
  ],
  strip_prefix = "app_linux_x64/publish/linux-x64",
  include_runfiles = True,
)

container_image(
  name = "image_debian",
  base = "@dotnet_runtime_deps_6_0_10//image",
  directory = "/home",
  workdir = "/home",
  entrypoint = "/home/app",
  tars = [
    ":app_linux_x64_archive",
  ],
)

publish_binary(
  name = "app_alpine_x64",
  binary = ":app",
  target_framework = "net6.0",
  self_contained = True,
  runtime_identifier = "alpine-x64",
  runtime_packs = [
    "@paket.main//microsoft.netcore.app.runtime.linux-musl-x64",
  ],
)

pkg_tar(
  name = "app_alpine_x64_archive",
  srcs = [
    ":app_alpine_x64",
  ],
  strip_prefix = "app_alpine_x64/publish/alpine-x64",
  include_runfiles = True,
)

container_image(
  name = "image_alpine",
  base = "@dotnet_runtime_deps_alpine_3_16//image",
  directory = "/home",
  workdir = "/home",
  entrypoint = "/home/app",
  tars = [
    ":app_alpine_x64_archive",
  ],
)

The Debian based image works fine:

$ bazel run //:image_debian

$ docker run -it --rm bazel:image_debian                  
Hello, world. 

However, running the Alpine image gives an error:

$ bazel run //:image_alpine

$ docker run -it --rm bazel:image_alpine
/bin/sh: line 0: /home/app: not found

Note that the file does exist, this is the error Alpine gives when the binary format is not properly recognized!

@purkhusid
Copy link
Collaborator

Ah yeah, this makes sense. Currently we are only using the app host that is part of the host SDK. We need to stop doing to that and instead download the correct nuget package depending on the RID e.g. https://www.nuget.org/packages/runtime.linux-x64.Microsoft.NETCore.DotNetAppHost for linux-x64

By doing that we also solve cross compiling as this is pretty much the same issue.

@purkhusid
Copy link
Collaborator

I'm thinking that we might just want to start with just having an apphost attribute to begin with and the end user supplies the correct apphost nuget package. At some point I would like the rules to automatically resolve these "infrastructure" NuGet packages .

@njlr njlr changed the title [Next] Publish is somehow incorrect for Alpine Linux Download correct app-host for the target in order to support cross-compilation Mar 21, 2023
@njlr njlr changed the title Download correct app-host for the target in order to support cross-compilation Download correct app-host for the target RID in order to support cross-compilation Mar 21, 2023
@njlr njlr mentioned this issue Apr 3, 2024
@purkhusid
Copy link
Collaborator

This should not be working in the latest release.

@njlr
Copy link
Contributor Author

njlr commented Apr 4, 2024

Thanks!

I believe that some runtime packs are missing to enable this.

The alpine-x64 RID maps to linux-musl-x64, which has the runtime pack Microsoft.NETCore.App.Runtime.linux-musl-x64

Would it simply be a matter of adding these to here? https://github.com/bazelbuild/rules_dotnet/blob/master/dotnet/private/sdk/gen/runtime-packs.json

@purkhusid
Copy link
Collaborator

@njlr I just merged a change that adds the packs, I'm doing a 0.15.1 release in a bit.

@njlr
Copy link
Contributor Author

njlr commented Apr 4, 2024

@njlr I just merged a change that adds the packs, I'm doing a 0.15.1 release in a bit.

This works! Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants