diff --git a/internal/static/TransformServerless.go b/internal/static/TransformServerless.go index 5ea2826ec..debf950ba 100644 --- a/internal/static/TransformServerless.go +++ b/internal/static/TransformServerless.go @@ -10,17 +10,10 @@ import ( ) // TransformServerless copies the static files from output to .zeabur/output/static and creates a config.json file for SPA -func TransformServerless(image, workdir string, meta types.PlanMeta, isHTMLStatic bool) error { - if isHTMLStatic { - err := utils.CopyFromSource(path.Join(workdir, meta["outputDir"])+"/.", path.Join(workdir, ".zeabur/output/static")) - if err != nil { - return err - } - } else { - err := utils.CopyFromImage(image, path.Join("/src", meta["outputDir"])+"/.", path.Join(workdir, ".zeabur/output/static")) - if err != nil { - return err - } +func TransformServerless(image, workdir string, meta types.PlanMeta) error { + err := utils.CopyFromImage(image, path.Join("/usr/share/nginx/html/static", meta["outputDir"])+"/.", path.Join(workdir, ".zeabur/output/static")) + if err != nil { + return err } config := types.ZeaburOutputConfig{Containerized: false, Routes: make([]types.ZeaburOutputConfigRoute, 0)} diff --git a/internal/static/static.go b/internal/static/static.go index 3476ff9eb..90d890a48 100644 --- a/internal/static/static.go +++ b/internal/static/static.go @@ -23,10 +23,6 @@ RUN echo "server { listen 8080; root /usr/share/nginx/html/static; absolute_redi EXPOSE 8080`, nil } - if meta["framework"] == "html-static" { - return `HTML-STATIC`, nil - } - dockerfile := `FROM docker.io/library/nginx:alpine as runtime WORKDIR /usr/share/nginx/html/static COPY . . diff --git a/internal/utils/copy_from_source.go b/internal/utils/copy_from_source.go deleted file mode 100644 index 55d10f753..000000000 --- a/internal/utils/copy_from_source.go +++ /dev/null @@ -1,42 +0,0 @@ -package utils - -import ( - "fmt" - "os" - "os/exec" - "strings" -) - -// CopyFromSource copies a directory from source code to the host -func CopyFromSource(dirInSrc, destOnHost string) error { - if err := os.MkdirAll(".tmp", 0755); err != nil { - return fmt.Errorf("create directory: %w", err) - } - defer func() { - removeCmd := exec.Command("rm", "-rf", ".tmp") - removeCmd.Stderr = os.Stderr - if err := removeCmd.Run(); err != nil { - fmt.Println(err) - } - }() - var stderr strings.Builder - tempCopyCmd := exec.Command("cp", "-r", dirInSrc, ".tmp") - tempCopyCmd.Stderr = &stderr - err := tempCopyCmd.Run() - if err != nil { - return fmt.Errorf("copy from source code: %s: %w", stderr.String(), err) - } - - if err := os.MkdirAll(destOnHost, 0o755); err != nil { - return fmt.Errorf("create directory: %w", err) - } - copyCmd := exec.Command("cp", "-r", ".tmp/.", destOnHost) - - copyCmd.Stderr = &stderr - err = copyCmd.Run() - if err != nil { - return fmt.Errorf("copy from source code: %s: %w", stderr.String(), err) - } - - return nil -} diff --git a/pkg/zeaburpack/image.go b/pkg/zeaburpack/image.go index 1d4d9d9d9..9cab4746e 100644 --- a/pkg/zeaburpack/image.go +++ b/pkg/zeaburpack/image.go @@ -35,9 +35,6 @@ func buildImage(opt *buildImageOptions) error { resolvedVars := envexpander.ResolveEnvVariable(opt.UserVars) refConstructor := newReferenceConstructor(opt.ProxyRegistry) - if opt.Dockerfile == "HTML-STATIC" { - return nil - } lines := strings.Split(opt.Dockerfile, "\n") stageLines := make([]int, 0) diff --git a/pkg/zeaburpack/main.go b/pkg/zeaburpack/main.go index 0948034bf..a6ff047fb 100644 --- a/pkg/zeaburpack/main.go +++ b/pkg/zeaburpack/main.go @@ -202,7 +202,7 @@ func Build(opt *BuildOptions) error { if t == types.PlanTypeNodejs && m["outputDir"] != "" { println("Transforming build output to serverless format ...") - err = static.TransformServerless(*opt.ResultImage, *opt.Path, m, false) + err = static.TransformServerless(*opt.ResultImage, *opt.Path, m) if err != nil { println("Failed to transform serverless: " + err.Error()) handleBuildFailed(err) @@ -210,9 +210,9 @@ func Build(opt *BuildOptions) error { } } - if t == types.PlanTypeStatic && m["framework"] == "html-static" { + if t == types.PlanTypeStatic { println("Transforming build output to serverless format ...") - err = static.TransformServerless(*opt.ResultImage, *opt.Path, m, true) + err = static.TransformServerless(*opt.ResultImage, *opt.Path, m) if err != nil { println("Failed to transform static serverless: " + err.Error()) handleBuildFailed(err) @@ -225,8 +225,9 @@ func Build(opt *BuildOptions) error { handleLog("\033[90m" + "To run the image, use the following command:" + "\033[0m") if t == types.PlanTypeNodejs && m["outputDir"] != "" { handleLog("npx serve .zeabur/output/static") - } else if t == types.PlanTypeStatic && m["framework"] == "html-static" { - handleLog("npx serve .zeabur/output/static") + } else if t == types.PlanTypeStatic { + handleLog("docker run -p 8080:8080 -it " + *opt.ResultImage) + handleLog("or you can find generated static file in .zeabur/output/static") } else { handleLog("docker run -p 8080:8080 -it " + *opt.ResultImage) }