From 8b37829595edd0ae65c9ed93d61da7a93ddb9e3f Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Mon, 16 Dec 2024 14:51:22 +0100 Subject: [PATCH 1/4] copy dir --- pkg/dockerbuild/spec.go | 5 +---- pkg/dockerbuild/tarcopy.go | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pkg/dockerbuild/spec.go b/pkg/dockerbuild/spec.go index a20b21b418..4a6f51d424 100644 --- a/pkg/dockerbuild/spec.go +++ b/pkg/dockerbuild/spec.go @@ -384,11 +384,8 @@ func (b *imageSpecBuilder) Describe(cfg DescribeConfig) (*ImageSpec, error) { // If we have any JS outputs that need the local runtime, copy it into the image. { for _, out := range cfg.Compile.Outputs { + // TODO this code ... 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") diff --git a/pkg/dockerbuild/tarcopy.go b/pkg/dockerbuild/tarcopy.go index 43fbc335be..bd06ada631 100644 --- a/pkg/dockerbuild/tarcopy.go +++ b/pkg/dockerbuild/tarcopy.go @@ -124,12 +124,32 @@ func (tc *tarCopier) CopyDir(desc *dirCopyDesc) error { isSymlink, _ = xos.IsWindowsJunctionPoint(pathStr) } + fi, err := d.Info() + if err != nil { + return errors.WithStack(err) + } + if isSymlink { target, err := os.Readlink(string(path)) if err != nil { return errors.WithStack(err) } + if strings.HasSuffix(target, "encore.dev") { + fi, err = os.Stat(target) + if err != nil { + return errors.WithStack(err) + } + + err = tc.CopyDir(&dirCopyDesc{ + Spec: desc.Spec, + SrcPath: HostPath(target), + DstPath: dstPath, + ExcludeSrcPaths: map[HostPath]bool{}, + }) + return errors.Wrap(err, "add encore.dev") + } + link, err = tc.rewriteSymlink(desc, path, HostPath(target)) if err != nil { return errors.WithStack(err) @@ -137,12 +157,9 @@ func (tc *tarCopier) CopyDir(desc *dirCopyDesc) error { // Drop the symlink return nil } - } - fi, err := d.Info() - if err != nil { - return errors.WithStack(err) } + err = tc.CopyFile(dstPath, path, fi, link) return errors.Wrap(err, "add file") }) From b8ae4de5183d996264e02428724d936b5f6f7eec Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Tue, 17 Dec 2024 12:23:52 +0100 Subject: [PATCH 2/4] todo --- pkg/dockerbuild/spec.go | 2 +- pkg/dockerbuild/tarcopy.go | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pkg/dockerbuild/spec.go b/pkg/dockerbuild/spec.go index 4a6f51d424..f8d17e4ad1 100644 --- a/pkg/dockerbuild/spec.go +++ b/pkg/dockerbuild/spec.go @@ -384,8 +384,8 @@ func (b *imageSpecBuilder) Describe(cfg DescribeConfig) (*ImageSpec, error) { // If we have any JS outputs that need the local runtime, copy it into the image. { for _, out := range cfg.Compile.Outputs { - // TODO this code ... if _, ok := out.(*builder.JSBuildOutput); ok { + // TODO copy runtime to /encore or something instead // 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") diff --git a/pkg/dockerbuild/tarcopy.go b/pkg/dockerbuild/tarcopy.go index bd06ada631..3804337b77 100644 --- a/pkg/dockerbuild/tarcopy.go +++ b/pkg/dockerbuild/tarcopy.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "encr.dev/internal/env" "encr.dev/pkg/xos" "encr.dev/v2/compiler/build" "github.com/cockroachdb/errors" @@ -124,30 +125,22 @@ func (tc *tarCopier) CopyDir(desc *dirCopyDesc) error { isSymlink, _ = xos.IsWindowsJunctionPoint(pathStr) } - fi, err := d.Info() - if err != nil { - return errors.WithStack(err) - } - if isSymlink { target, err := os.Readlink(string(path)) if err != nil { return errors.WithStack(err) } - if strings.HasSuffix(target, "encore.dev") { - fi, err = os.Stat(target) - if err != nil { - return errors.WithStack(err) - } - + // if the target is encore.dev in the runtime path, copy the files instead + // of linking + if target == filepath.Join(env.EncoreRuntimesPath(), "js", "encore.dev") { err = tc.CopyDir(&dirCopyDesc{ Spec: desc.Spec, SrcPath: HostPath(target), DstPath: dstPath, ExcludeSrcPaths: map[HostPath]bool{}, }) - return errors.Wrap(err, "add encore.dev") + return errors.Wrap(err, "add encore.dev package") } link, err = tc.rewriteSymlink(desc, path, HostPath(target)) @@ -160,6 +153,10 @@ func (tc *tarCopier) CopyDir(desc *dirCopyDesc) error { } + fi, err := d.Info() + if err != nil { + return errors.WithStack(err) + } err = tc.CopyFile(dstPath, path, fi, link) return errors.Wrap(err, "add file") }) From 72825ba306fe3636cc4bc4d4acb1ff6cfc3f3ec9 Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Wed, 18 Dec 2024 09:51:44 +0100 Subject: [PATCH 3/4] add runtime to /encore instead of mirroring host file system --- pkg/dockerbuild/spec.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/dockerbuild/spec.go b/pkg/dockerbuild/spec.go index f8d17e4ad1..489537f7e9 100644 --- a/pkg/dockerbuild/spec.go +++ b/pkg/dockerbuild/spec.go @@ -385,10 +385,9 @@ func (b *imageSpecBuilder) Describe(cfg DescribeConfig) (*ImageSpec, error) { { for _, out := range cfg.Compile.Outputs { if _, ok := out.(*builder.JSBuildOutput); ok { - // TODO copy runtime to /encore or something instead // 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") + 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) From ac4c865e13466da8ed6254ae783c6d0ceca4cfa1 Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Wed, 18 Dec 2024 09:53:31 +0100 Subject: [PATCH 4/4] comment --- pkg/dockerbuild/tarcopy.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/dockerbuild/tarcopy.go b/pkg/dockerbuild/tarcopy.go index 3804337b77..d906a9f2b2 100644 --- a/pkg/dockerbuild/tarcopy.go +++ b/pkg/dockerbuild/tarcopy.go @@ -131,8 +131,7 @@ func (tc *tarCopier) CopyDir(desc *dirCopyDesc) error { return errors.WithStack(err) } - // if the target is encore.dev in the runtime path, copy the files instead - // of linking + // copy the files instead of linking if its the encore.dev package if target == filepath.Join(env.EncoreRuntimesPath(), "js", "encore.dev") { err = tc.CopyDir(&dirCopyDesc{ Spec: desc.Spec, @@ -150,7 +149,6 @@ func (tc *tarCopier) CopyDir(desc *dirCopyDesc) error { // Drop the symlink return nil } - } fi, err := d.Info()