Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions e2e/language/other_test.go → e2e/language/others_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,25 @@ import (
var _ = Describe("rust", Ordered, func() {
testcase := "e2e"

Describe("Should install rust lang successfully", func() {
exampleName := "rust"
Describe("Should install rust/golang/nodejs successfully", func() {
exampleName := "others"
e := e2e.NewExample(e2e.BuildContextDirWithName(exampleName), testcase)
BeforeAll(e.BuildImage(true))
BeforeEach(e.RunContainer())
It("Should have cargo installed", func() {
res, err := e.ExecRuntimeCommand("show")
It("Should have go installed", func() {
res, err := e.ExecRuntimeCommand("go version")
Expect(err).To(BeNil())
Expect(res).To(ContainSubstring("go version"))
})
It("Should have rust installed", func() {
res, err := e.ExecRuntimeCommand("rust version")
Expect(err).To(BeNil())
Expect(res).To(ContainSubstring("toolchain"))
})
AfterEach(e.DestroyContainer())
})

Describe("Should install golang successfully", func() {
exampleName := "golang"
e := e2e.NewExample(e2e.BuildContextDirWithName(exampleName), testcase)
BeforeAll(e.BuildImage(true))
BeforeEach(e.RunContainer())
It("Should have go installed", func() {
res, err := e.ExecRuntimeCommand("version")
It("Should have nodejs installed", func() {
res, err := e.ExecRuntimeCommand("nodejs version")
Expect(err).To(BeNil())
Expect(res).To(ContainSubstring("go version"))
Expect(res).To(ContainSubstring("v"))
})
AfterEach(e.DestroyContainer())
})
Expand Down
12 changes: 0 additions & 12 deletions e2e/language/testdata/golang/build.envd

This file was deleted.

16 changes: 16 additions & 0 deletions e2e/language/testdata/others/build.envd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# syntax=v1


def build():
base(dev=True)
install.go()
install.rust()
install.nodejs()
shell("fish")
runtime.command(
commands={
"go version": "go version",
"rust version": "rustup show",
"nodejs version": "node --version",
}
)
12 changes: 0 additions & 12 deletions e2e/language/testdata/rust/build.envd

This file was deleted.

8 changes: 8 additions & 0 deletions envd/api/v1/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def go(version: Optional[str] = "1.25.3"):
"""


def nodejs(version: Optional[str] = "25.1.0"):
"""Install NodeJS programming language.

Args:
version (Optional[str]): NodeJS version, such as '25.1.0'.
"""


def codex(version: Optional[str] = "0.55.0"):
"""Install Codex agent.

Expand Down
1 change: 1 addition & 0 deletions pkg/lang/frontend/starlark/v1/install/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
ruleJulia = "install.julia"
ruleRust = "install.rust"
ruleGo = "install.go"
ruleNodeJS = "install.nodejs"

// packages
ruleSystemPackage = "install.apt_packages"
Expand Down
14 changes: 14 additions & 0 deletions pkg/lang/frontend/starlark/v1/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var Module = &starlarkstruct.Module{
"julia": starlark.NewBuiltin(ruleJulia, ruleFuncJulia),
"rust": starlark.NewBuiltin(ruleRust, ruleFuncRust),
"go": starlark.NewBuiltin(ruleGo, ruleFuncGo),
"nodejs": starlark.NewBuiltin(ruleNodeJS, ruleFuncNodeJS),
// packages
"apt_packages": starlark.NewBuiltin(ruleSystemPackage, ruleFuncSystemPackage),
"python_packages": starlark.NewBuiltin(rulePyPIPackage, ruleFuncPyPIPackage),
Expand Down Expand Up @@ -152,6 +153,19 @@ func ruleFuncGo(thread *starlark.Thread, _ *starlark.Builtin,
return starlark.None, nil
}

func ruleFuncNodeJS(thread *starlark.Thread, _ *starlark.Builtin,
args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
logger.Debugf("rule `%s` is invoked", ruleNodeJS)

var version string
if err := starlark.UnpackArgs(ruleNodeJS, args, kwargs, "version?", &version); err != nil {
return nil, err
}

ir.NodeJS(version)
return starlark.None, nil
}

func ruleFuncPyPIPackage(thread *starlark.Thread, _ *starlark.Builtin,
args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var name *starlark.List
Expand Down
10 changes: 10 additions & 0 deletions pkg/lang/ir/v1/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func Golang(version string) {
g.Languages = append(g.Languages, golang)
}

func NodeJS(version string) {
g := DefaultGraph.(*generalGraph)

nodejs := ir.Language{Name: "nodejs"}
if len(version) > 0 {
nodejs.Version = &version
}
g.Languages = append(g.Languages, nodejs)
}

func PyPIPackage(deps []string, requirementsFile string, wheels []string) error {
g := DefaultGraph.(*generalGraph)

Expand Down
47 changes: 47 additions & 0 deletions pkg/lang/ir/v1/nodejs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2025 The envd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1

import (
"github.com/moby/buildkit/client/llb"
)

// from https://nodejs.org/download/release/
const (
nodejsDefaultVersion = "25.1.0"
nodejsTempDir = "/tmp/nodejs"
nodejsHomeDir = "/opt/nodejs"
nodejsHomeBin = "/opt/nodejs/bin"
)

func (g *generalGraph) installNodeJS(root llb.State, version *string) llb.State {
nodejsVersion := nodejsDefaultVersion
if version != nil {
nodejsVersion = *version
}

base := llb.Image(builderImage)
builder := base.Run(
llb.Shlexf(`sh -c "mkdir %[1]s && wget -qO- https://nodejs.org/download/release/v%[2]s/node-v%[2]s-linux-$(uname -m | sed -e 's/x86_64/x64/').tar.xz | tar -xJ --strip-components=1 -C %[1]s || exit 1"`, nodejsTempDir, nodejsVersion),
llb.WithCustomNamef("[internal] download nodejs %s", nodejsVersion),
).Root()

root = root.File(
llb.Copy(builder, nodejsTempDir, nodejsHomeDir),
llb.WithCustomNamef("[internal] prepare nodejs %s", nodejsVersion),
)
g.RuntimeEnvPaths = append(g.RuntimeEnvPaths, nodejsHomeBin)
return root
}
4 changes: 4 additions & 0 deletions pkg/lang/ir/v1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func (g *generalGraph) compileLanguage(root llb.State) (llb.State, error) {
root = g.installRust(root, language.Version)
case "go":
root = g.installGolang(root, language.Version)
case "nodejs":
root = g.installNodeJS(root, language.Version)
}
}
return root, err
Expand All @@ -189,6 +191,8 @@ func (g *generalGraph) compileLanguage(root llb.State) (llb.State, error) {
lang = g.installRust(root, language.Version)
case "go":
lang = g.installGolang(root, language.Version)
case "nodejs":
lang = g.installNodeJS(root, language.Version)
}
langs = append(langs, lang)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/types/envd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ var BaseAptPackage = []string{
"make",
"zsh",
"locales",
"gpg", // used by r-lang
"gpg", // used by r-lang
"libatomic1", // used by nodejs
}

type EnvdImage struct {
Expand Down
Loading