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

Remove symlinking of encore.dev package #1662

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2,220 changes: 1,338 additions & 882 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions cli/cmd/encore/app/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,19 @@ func gogetEncore(dir string) error {
}

func npmInstallEncore(dir string) error {
verToInstall := version.Version
args := []string{"install"}
if version.Channel == version.DevBuild {
verToInstall = "latest"
args = append(args, filepath.Join(env.EncoreRuntimesPath(), "js", "encore.dev"))
} else {
args = append(args, fmt.Sprintf("encore.dev@%s", strings.TrimPrefix(version.Version, "v")))
}

// First install the 'encore.dev' package.
cmd := exec.Command("npm", "install", fmt.Sprintf("encore.dev@%s", verToInstall))
cmd := exec.Command("npm", args...)
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
err = fmt.Errorf("'npm install encore.dev@%s' failed: %v: %s", verToInstall, err, out)
err = fmt.Errorf("installing encore.dev package failed: %v: %s", err, out)
}

// Then run 'npm install'.
Expand Down
4 changes: 4 additions & 0 deletions cli/daemon/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"

"encr.dev/internal/version"
"encr.dev/pkg/builder"
"encr.dev/pkg/builder/builderimpl"
"encr.dev/pkg/fns"
Expand Down Expand Up @@ -42,6 +43,9 @@ func (s *Server) DumpMeta(ctx context.Context, req *daemonpb.DumpMetaRequest) (*
KeepOutput: false,
Revision: vcsRevision.Revision,
UncommittedChanges: vcsRevision.Uncommitted,

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}

bld := builderimpl.Resolve(app.Lang(), expSet)
Expand Down
4 changes: 4 additions & 0 deletions cli/daemon/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"encr.dev/cli/daemon/apps"
"encr.dev/internal/env"
"encr.dev/internal/version"
"encr.dev/pkg/appfile"
"encr.dev/pkg/builder"
"encr.dev/pkg/builder/builderimpl"
Expand Down Expand Up @@ -52,6 +53,9 @@ func Docker(ctx context.Context, app *apps.Instance, req *daemonpb.ExportRequest
KeepOutput: false,
Revision: vcsRevision.Revision,
UncommittedChanges: vcsRevision.Uncommitted,

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}
appLang := app.Lang()
bld := builderimpl.Resolve(appLang, expSet)
Expand Down
4 changes: 4 additions & 0 deletions cli/daemon/run/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cockroachdb/errors"

"encr.dev/cli/daemon/apps"
"encr.dev/internal/version"
"encr.dev/pkg/builder"
"encr.dev/pkg/builder/builderimpl"
"encr.dev/pkg/cueutil"
Expand Down Expand Up @@ -56,6 +57,9 @@ func (mgr *Manager) Check(ctx context.Context, p CheckParams) (buildDir string,
KeepOutput: p.CodegenDebug,
Revision: vcsRevision.Revision,
UncommittedChanges: vcsRevision.Uncommitted,

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}

bld := builderimpl.Resolve(p.App.Lang(), expSet)
Expand Down
4 changes: 4 additions & 0 deletions cli/daemon/run/exec_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
encoreEnv "encr.dev/internal/env"
"encr.dev/internal/lookpath"
"encr.dev/internal/optracker"
"encr.dev/internal/version"
"encr.dev/pkg/builder"
"encr.dev/pkg/builder/builderimpl"
"encr.dev/pkg/cueutil"
Expand Down Expand Up @@ -90,6 +91,9 @@ func (mgr *Manager) ExecScript(ctx context.Context, p ExecScriptParams) (err err
Revision: vcsRevision.Revision,
UncommittedChanges: vcsRevision.Uncommitted,
MainPkg: option.Some(p.MainPkg),

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}

parse, err := bld.Parse(ctx, builder.ParseParams{
Expand Down
4 changes: 4 additions & 0 deletions cli/daemon/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"encr.dev/cli/daemon/run/infra"
"encr.dev/cli/daemon/secret"
"encr.dev/internal/optracker"
"encr.dev/internal/version"
"encr.dev/pkg/builder"
"encr.dev/pkg/builder/builderimpl"
"encr.dev/pkg/cueutil"
Expand Down Expand Up @@ -349,6 +350,9 @@ func (r *Run) buildAndStart(ctx context.Context, tracker *optracker.OpTracker, i
KeepOutput: false,
Revision: vcsRevision.Revision,
UncommittedChanges: vcsRevision.Uncommitted,

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}

// A context that is canceled when the proc exits.
Expand Down
4 changes: 4 additions & 0 deletions cli/daemon/run/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"encr.dev/cli/daemon/run/infra"
"encr.dev/cli/daemon/secret"
"encr.dev/internal/optracker"
"encr.dev/internal/version"
"encr.dev/pkg/builder"
"encr.dev/pkg/builder/builderimpl"
"encr.dev/pkg/cueutil"
Expand Down Expand Up @@ -132,6 +133,9 @@ func (mgr *Manager) testSpec(ctx context.Context, bld builder.Impl, expSet *expe
KeepOutput: params.CodegenDebug,
Revision: vcsRevision.Revision,
UncommittedChanges: vcsRevision.Uncommitted,

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}

parse, err := bld.Parse(ctx, builder.ParseParams{
Expand Down
4 changes: 4 additions & 0 deletions cli/daemon/userfacing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cockroachdb/errors"

"encr.dev/cli/daemon/apps"
"encr.dev/internal/version"
"encr.dev/pkg/builder"
"encr.dev/pkg/builder/builderimpl"
"encr.dev/pkg/fns"
Expand Down Expand Up @@ -45,6 +46,9 @@ func (s *Server) genUserFacing(ctx context.Context, app *apps.Instance) error {
KeepOutput: false,
Revision: vcsRevision.Revision,
UncommittedChanges: vcsRevision.Uncommitted,

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}

bld := builderimpl.Resolve(app.Lang(), expSet)
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"encr.dev/cli/daemon/run/infra"
"encr.dev/cli/daemon/secret"
. "encr.dev/internal/optracker"
"encr.dev/internal/version"
"encr.dev/pkg/builder"
"encr.dev/pkg/builder/builderimpl"
"encr.dev/pkg/cueutil"
Expand Down Expand Up @@ -231,6 +232,9 @@ func testBuild(t testing.TB, appRoot string, env []string) (*builder.ParseResult
KeepOutput: false,
Revision: vcsRevision.Revision,
UncommittedChanges: vcsRevision.Uncommitted,

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}

parse, err := bld.Parse(ctx, builder.ParseParams{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module encr.dev

go 1.23.0

toolchain go1.23.2
toolchain go1.23.3

require (
cloud.google.com/go/storage v1.43.0
Expand Down
4 changes: 4 additions & 0 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"encore.dev/appruntime/exported/experiments"
"encr.dev/cli/daemon/apps"
"encr.dev/internal/optracker"
"encr.dev/internal/version"
"encr.dev/pkg/cueutil"
"encr.dev/pkg/fns"
"encr.dev/pkg/option"
Expand Down Expand Up @@ -81,6 +82,9 @@ func DefaultBuildInfo() BuildInfo {
KeepOutput: false,
Revision: "",
UncommittedChanges: false,

// Use the local JS runtime if this is a development build.
UseLocalJSRuntime: version.Channel == version.DevBuild,
}
}

Expand Down
32 changes: 22 additions & 10 deletions pkg/dockerbuild/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,28 @@ func (b *imageSpecBuilder) Describe(cfg DescribeConfig) (*ImageSpec, error) {
{
for _, out := range cfg.Compile.Outputs {
if _, ok := out.(*builder.JSBuildOutput); ok {
// Include the encore.dev package, at the same location.
runtimeSrc := cfg.Runtimes.Join("js", "encore.dev")
b.spec.CopyData[runtimeSrc.ToImage()] = runtimeSrc

// Add the encore-runtime.node file, and set the environment variable to point to it.
nativeRuntimeHost := cfg.NodeRuntime.GetOrElse(cfg.Runtimes.Join("js", "encore-runtime.node"))
nativeRuntimeImg := nativeRuntimeHost.ToImage().Dir().Join("encore-runtime.node")
b.spec.CopyData[nativeRuntimeImg] = nativeRuntimeHost
b.spec.Env = append(b.spec.Env, fmt.Sprintf("ENCORE_RUNTIME_LIB=%s", nativeRuntimeImg))
b.addPrio(nativeRuntimeImg)
if nativeRuntimeHost, ok := cfg.NodeRuntime.Get(); ok {
// Add the encore-runtime.node file, and set the environment variable to point to it.
nativeRuntimeImg := ImagePath("/encore/runtimes/js/encore-runtime.node")
b.spec.CopyData[nativeRuntimeImg] = nativeRuntimeHost
b.spec.Env = append(b.spec.Env, fmt.Sprintf("ENCORE_RUNTIME_LIB=%s", nativeRuntimeImg))
b.addPrio(nativeRuntimeImg)

// Copy the encore.dev package.
nativePackageHost := cfg.Runtimes.Join("js", "encore.dev")
nativePackageImg := ImagePath("/encore/runtimes/js/encore.dev")
b.spec.CopyData[nativePackageImg] = nativePackageHost
} else {
// Copy the whole js runtime.
runtimeHost := cfg.Runtimes.Join("js")
runtimeImg := ImagePath("/encore/runtimes/js")
b.spec.CopyData[runtimeImg] = runtimeHost

nativeRuntimeImg := runtimeImg.Join("encore-runtime.node")
b.spec.Env = append(b.spec.Env, fmt.Sprintf("ENCORE_RUNTIME_LIB=%s", nativeRuntimeImg))
b.addPrio(nativeRuntimeImg)
}

break
}
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/dockerbuild/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ func TestBuild_Node(t *testing.T) {
c.Assert(spec, qt.CmpEquals(opts...), &ImageSpec{
Entrypoint: []string{"/artifacts/0/build/entrypoint"},
Env: []string{
"ENCORE_RUNTIME_LIB=/host/runtimes/js/encore-runtime.node",
"ENCORE_RUNTIME_LIB=/encore/runtimes/js/encore-runtime.node",
},
WorkingDir: "/",
BuildInfo: BuildInfoSpec{InfoPath: defaultBuildInfoPath},
WriteFiles: map[ImagePath][]byte{defaultMetaPath: meta},
CopyData: map[ImagePath]HostPath{
"/artifacts/0/build": "/host/artifacts",
"/artifacts/0/package.json": "/host/package.json",
"/artifacts/0/node_modules": "/host/node_modules",
"/host/runtimes/js/encore.dev": "/host/runtimes/js/encore.dev",
"/host/runtimes/js/encore-runtime.node": "/host/runtimes/js/encore-runtime.node",
"/artifacts/0/build": "/host/artifacts",
"/artifacts/0/package.json": "/host/package.json",
"/artifacts/0/node_modules": "/host/node_modules",
"/encore/runtimes/js": "/host/runtimes/js",
},
BundleSource: option.Option[BundleSourceSpec]{},
Supervisor: option.None[SupervisorSpec](),
Expand All @@ -67,7 +66,7 @@ func TestBuild_Node(t *testing.T) {
StargzPrioritizedFiles: []ImagePath{
"/artifacts/0/package.json",
"/artifacts/0/build/entrypoint",
"/host/runtimes/js/encore-runtime.node",
"/encore/runtimes/js/encore-runtime.node",
},
})
}
Expand Down
16 changes: 15 additions & 1 deletion runtimes/core/src/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ impl ServiceRegistry {
Ok((req, resp_schema)) => {
let fut = http_client.execute(req);
match fut.await {
Ok(resp) => resp_schema.extract(resp).await,
Ok(resp) => {
if !resp.status().is_success() {
return Err(extract_error(resp).await);
}
resp_schema.extract(resp).await
}
Err(e) => Err(api::Error::internal(e)),
}
}
Expand Down Expand Up @@ -526,3 +531,12 @@ where
Ok(())
}
}

async fn extract_error(resp: reqwest::Response) -> api::Error {
match resp.bytes().await {
Ok(bytes) => serde_json::from_slice(&bytes).unwrap_or_else(|err| {
api::Error::invalid_argument("unable to parse error response", err)
}),
Err(err) => api::Error::invalid_argument("unable to read response body", err),
}
}
2 changes: 1 addition & 1 deletion runtimes/core/src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Error {
pub code: ErrCode,
pub message: String,
pub internal_message: Option<String>,
pub details: Option<serde_json::Map<String, serde_json::Value>>,
pub details: Option<Box<serde_json::Map<String, serde_json::Value>>>,

#[serde(skip_serializing)]
pub stack: Option<StackTrace>,
Expand Down
Loading
Loading