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

feat: replace deb.nodesource.com with n, fixes #5509 #5521

Merged
merged 4 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/content/users/configuration/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,9 @@ Node.js version for the web container’s “system” version.

| Type | Default | Usage
| -- | -- | --
| :octicons-file-directory-16: project | current LTS version | Can be `16`, `18`, or `20`.
| :octicons-file-directory-16: project | current LTS version | any [node version](https://www.npmjs.com/package/n#specifying-nodejs-versions), like `16`, `18.2`, `18.19.2`, etc.

There is no need to configure the `nodejs_version` unless you want to use a major version that is not the default.

`nvm` is also available inside the container and via [`ddev nvm`](../usage/commands.md#nvm), and can be set to any valid version including much older ones.
There is no need to configure `nodejs_version` unless you want a version other than the default version.

## `omit_containers`

Expand Down
2 changes: 1 addition & 1 deletion docs/content/users/extend/customization-extendibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ If you need to create a service configuration for your project, see [Defining Ad

There are many ways to deploy Node.js in any project, so DDEV tries to let you set up any possibility you can come up with.

* You can choose the Node.js version you want to use in `.ddev/config.yaml` with [`nodejs_version`](../configuration/config.md#nodejs_version).
* You can choose any Node.js version you want (including minor and older versions) in `.ddev/config.yaml` with [`nodejs_version`](../configuration/config.md#nodejs_version).
* [`ddev nvm`](../usage/commands.md#nvm) gives you the full capabilities of [Node Version Manager](https://github.com/nvm-sh/nvm).
* [`ddev npm`](../usage/commands.md#npm) and [`ddev yarn`](../usage/commands.md#yarn) provide shortcuts to the `npm` and `yarn` commands inside the container, and their caches are persistent.
* You can run Node.js daemons using [`web_extra_daemons`](#running-extra-daemons-in-the-web-container).
Expand Down
14 changes: 2 additions & 12 deletions pkg/ddevapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,6 @@ func (app *DdevApp) ValidateConfig() error {
return fmt.Errorf("unsupported webserver type: %s, DDEV (%s) only supports the following webserver types: %s", app.WebserverType, runtime.GOARCH, nodeps.GetValidWebserverTypes()).(invalidWebserverType)
}

if !nodeps.IsValidNodeVersion(app.NodeJSVersion) {
util.Warning("Node.js version '%s' is not currently supported by DDEV, ignoring and using default version '%v'.", app.NodeJSVersion, nodeps.NodeJSDefault)
util.Warning("Use `ddev config --auto` to fix, or use `ddev nvm` to support an arbitrary Node.js version.")
app.NodeJSVersion = nodeps.NodeJSDefault
}

if !nodeps.IsValidOmitContainers(app.OmitContainers) {
return fmt.Errorf("unsupported omit_containers: %s, DDEV (%s) only supports the following for omit_containers: %s", app.OmitContainers, runtime.GOARCH, nodeps.GetValidOmitContainers()).(InvalidOmitContainers)
}
Expand Down Expand Up @@ -932,12 +926,8 @@ func (app *DdevApp) RenderComposeYAML() (string, error) {
extraWebContent := "\nRUN mkdir -p /home/$username && chown $username /home/$username && chmod 600 /home/$username/.pgpass"
extraWebContent = extraWebContent + "\nENV NVM_DIR=/home/$username/.nvm"
if app.NodeJSVersion != nodeps.NodeJSDefault {
extraWebContent = extraWebContent + "\nRUN (apt-get remove -y nodejs || true) && (apt purge nodejs || true)"
extraWebContent = extraWebContent + "\nRUN curl -sSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor > /usr/share/keyrings/nodesource.gpg"
extraWebContent = extraWebContent + fmt.Sprintf("\nRUN echo \"deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_%s.x nodistro main\" > /etc/apt/sources.list.d/nodesource.list", app.NodeJSVersion)
extraWebContent = extraWebContent + "\nRUN echo 'disk usage problems: ' && df -h /tmp && ls -l /var/lib/apt/lists\n"
extraWebContent = extraWebContent + "\nRUN apt-get update >/dev/null && apt-get install -y nodejs >/dev/null\n" +
"RUN npm install --unsafe-perm=true --global gulp-cli yarn || ( npm config set unsafe-perm true && npm install --global gulp-cli yarn )"
extraWebContent = extraWebContent + "\nRUN npm install -g n"
extraWebContent = extraWebContent + fmt.Sprintf("\nRUN n install %s", app.NodeJSVersion)
}

// Add supervisord config for WebExtraDaemons
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddevapp/nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/ddev/ddev/pkg/ddevapp"
"github.com/ddev/ddev/pkg/exec"
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/testcommon"
"github.com/ddev/ddev/pkg/util"
asrt "github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -41,7 +40,8 @@ func TestNodeJSVersions(t *testing.T) {
err = app.Start()
require.NoError(t, err)

for _, v := range nodeps.GetValidNodeVersions() {
// Testing some random versions, both complete and incomplete
for _, v := range []string{"6", "10", "14.20", "16.0.0", "20"} {
app.NodeJSVersion = v
err = app.Restart()
assert.NoError(err)
Expand Down
12 changes: 7 additions & 5 deletions pkg/ddevapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ const ConfigInstructions = `
# To reinstall Composer after the image was built, run "ddev debug refresh".

# nodejs_version: "18"
# change from the default system Node.js version to another supported version, like 16, 18, 20.
# Note that you can use 'ddev nvm' or nvm inside the web container to provide nearly any
# Node.js version, including v6, etc.
# You only need to configure this if you are not using nvm and you want to use a major
# version that is not the default.
# change from the default system Node.js version to any other version.
# Numeric version numbers can be complete (i.e. 18.15.0) or
# incomplete (18, 17.2, 16). 'lts' and 'latest' can be used as well along with
# other named releases.
# see https://www.npmjs.com/package/n#specifying-nodejs-versions
# Note that you can continue using 'ddev nvm' or nvm inside the web container
# to change the project's installed node version if you need to.

# additional_hostnames:
# - somename
Expand Down
12 changes: 0 additions & 12 deletions pkg/nodeps/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ var ValidWebserverTypes = map[string]bool{
WebserverNginxGunicorn: true,
}

var ValidNodeJSVersions = []string{"16", "18", "20"}

// App types
const (
AppTypeNone = ""
Expand Down Expand Up @@ -138,16 +136,6 @@ func GetValidPHPVersions() []string {
return s
}

// GetValidNodeVersions is a helper function that returns a list of valid nodejs versions.
func GetValidNodeVersions() []string {
return ValidNodeJSVersions
}

// IsValidNodeVersion is a helper function to determine if a NodeJS version is valid
func IsValidNodeVersion(v string) bool {
return ArrayContainsString(GetValidNodeVersions(), v)
}

// IsValidDatabaseVersion checks if the version is valid for the provided database type
func IsValidDatabaseVersion(dbType string, dbVersion string) bool {
switch dbType {
Expand Down