node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
599 stars 117 forks source link

How to run unofficial node node-v18.16.1-linux-x64-musl.tar.gz on alpine? #294

Open jansu76 opened 9 months ago

jansu76 commented 9 months ago

I want to use gradle-node-plugin to install node on alpine linux. Using this advice https://github.com/node-gradle/gradle-node-plugin/issues/51#issuecomment-623097695 combined with this https://github.com/node-gradle/gradle-node-plugin/blob/main/docs/faq.md#is-this-plugin-compatible-with-centralized-repositories-declaration I managed to get a working configuration that downloads the correct binary package from https://unofficial-builds.nodejs.org/download/release/v18.16.1/node-v18.16.1-linux-x64-musl.tar.gz

build.gradle:

node {
    download = true
    version = "18.16.1"
    distBaseUrl = null;
    }
}

settings.gradle

dependencyResolutionManagement {
    repositories {
        repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

        // Declare the Node.js download repository
        ivy {
            name = "Node.js"
            setUrl("https://unofficial-builds.nodejs.org/download/release/")
            patternLayout {
                artifact("v[revision]/[artifact](-v[revision]-linux-x64-musl).[ext]")
            }
            metadataSources {
                artifact()
            }
            content {
                includeModule("org.nodejs", "node")
            }
        }
    }
}

However, npmInstall fails since it tries to look for the binary in the wrong directory. Can I do something to fix this?

> Task :clean
> Task :nodeSetup
> Task :npmSetup SKIPPED
> Task :npmInstall FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':npmInstall'.
> A problem occurred starting process 'command '/mydir/frontend/.gradle/nodejs/node-v18.16.1-linux-x64/bin/node''

Binary is in node-v18.16.1-linux-x64-musl, not in node-v18.16.1-linux-x64.

deepy commented 9 months ago

In it's current state I don't think there's a solution, I'm currently doing a refactor related to the configurable components in this plugin and will tackle this as part of that

deepy commented 9 months ago

If all your linux systems use musl and you have the ability to setup an internal mirror I guess there's technically a workaround available by repackaging it

jansu76 commented 9 months ago

there's technically a workaround available by repackaging it

To make sure I understand, do you mean taking an unofficial build, and changing it so that the binary is in node-v18.16.1-linux-x64/bin/node instead of node-v18.16.1-linux-x64-musl/bin/node?

deepy commented 9 months ago

Yeah, it's not a pretty solution though and could easily lead to some confusion