Skip to content
Merged
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
20 changes: 14 additions & 6 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ import (
"time"
)

// EmbeddedAppPath contains the path of the embedded PHP application (empty if none)
// EmbeddedAppPath contains the path of the embedded PHP application (empty if none).
// It can be set at build time using -ldflags to override the default extraction path:
//
// go build -ldflags "-X github.com/dunglas/frankenphp.EmbeddedAppPath=/app" ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there no simpler way than hijacking ldflags for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the benefit? It's a niche use, and ldflags are designed for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's true. We should expose it in build-static.sh though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already exposed through XCADDY_ARGS.

//
// When set, the embedded app is extracted to this fixed path instead of a temp
// directory with a checksum suffix. This is useful when the app contains
// pre-compiled artifacts (e.g. OPcache file cache) that reference absolute paths
// and need a predictable extraction location.
var EmbeddedAppPath string

//go:embed app.tar
Expand All @@ -32,14 +40,14 @@ func init() {
return
}

appPath := filepath.Join(os.TempDir(), "frankenphp_"+string(embeddedAppChecksum))
if EmbeddedAppPath == "" {
EmbeddedAppPath = filepath.Join(os.TempDir(), "frankenphp_"+string(embeddedAppChecksum))
}

if err := untar(appPath); err != nil {
_ = os.RemoveAll(appPath)
if err := untar(EmbeddedAppPath); err != nil {
_ = os.RemoveAll(EmbeddedAppPath)
panic(err)
}

EmbeddedAppPath = appPath
}

// untar reads the tar file from r and writes it into dir.
Expand Down
Loading