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:
Pierre du Plessis 2024-01-21 19:13:08 +02:00 committed by GitHub
parent 3bdd6fd072
commit 6f108a4203
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 10 deletions

View File

@ -11,3 +11,4 @@
!testdata/*.txt
!build-static.sh
!app.tar
!app_checksum.txt

0
app_checksum.txt Normal file
View File

View 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

View File

@ -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