mirror of
https://github.com/dunglas/frankenphp
synced 2024-11-21 07:10:24 +00:00
fix: do not extract embedded app on every execution (#488)
* Do not extract embedded app on every execution * Add app_checksum.txt to .dockerignore * Rename embeddedAppHash to embeddedAppChecksum * Remove check for empty directory
This commit is contained in:
parent
3bdd6fd072
commit
6f108a4203
@ -11,3 +11,4 @@
|
||||
!testdata/*.txt
|
||||
!build-static.sh
|
||||
!app.tar
|
||||
!app_checksum.txt
|
||||
|
0
app_checksum.txt
Normal file
0
app_checksum.txt
Normal file
@ -122,6 +122,7 @@ cd ../..
|
||||
# Embed PHP app, if any
|
||||
if [ -n "${EMBED}" ] && [ -d "${EMBED}" ]; then
|
||||
tar -cf app.tar -C "${EMBED}" .
|
||||
md5 -q app.tar > app_checksum.txt
|
||||
fi
|
||||
|
||||
if [ "${os}" = "linux" ]; then
|
||||
@ -139,6 +140,7 @@ cd ../..
|
||||
|
||||
if [ -d "${EMBED}" ]; then
|
||||
truncate -s 0 app.tar
|
||||
truncate -s 0 app_checksum.txt
|
||||
fi
|
||||
|
||||
"dist/${bin}" version
|
||||
|
19
embed.go
19
embed.go
@ -3,9 +3,7 @@ package frankenphp
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
_ "embed"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -25,21 +23,22 @@ var EmbeddedAppPath string
|
||||
//go:embed app.tar
|
||||
var embeddedApp []byte
|
||||
|
||||
//go:embed app_checksum.txt
|
||||
var embeddedAppChecksum []byte
|
||||
|
||||
func init() {
|
||||
if len(embeddedApp) == 0 {
|
||||
// No embedded app
|
||||
return
|
||||
}
|
||||
|
||||
h := md5.Sum(embeddedApp)
|
||||
appPath := filepath.Join(os.TempDir(), "frankenphp_"+hex.EncodeToString(h[:]))
|
||||
appPath := filepath.Join(os.TempDir(), "frankenphp_"+strings.TrimSuffix(string(embeddedAppChecksum[:]), "\n"))
|
||||
|
||||
if err := os.RemoveAll(appPath); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := untar(appPath); err != nil {
|
||||
os.RemoveAll(appPath)
|
||||
panic(err)
|
||||
if _, err := os.Stat(appPath); os.IsNotExist(err) {
|
||||
if err := untar(appPath); err != nil {
|
||||
os.RemoveAll(appPath)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
EmbeddedAppPath = appPath
|
||||
|
Loading…
Reference in New Issue
Block a user