diff --git a/Dockerfile b/Dockerfile index c11c0f758..d41a73fa6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,12 +16,10 @@ FROM debian:bookworm-slim RUN apt update && apt install --no-install-recommends libvips ca-certificates libjemalloc2 libtcmalloc-minimal4 curl -y && rm -rf /var/lib/apt/lists/* && rm -rf /var/cache/apt/archives/* -# Download and install libam with correct arch -# http://ftp.us.debian.org/debian/pool/main/a/aom/libaom3_3.11.0~rc1-1_amd64.deb -# http://ftp.us.debian.org/debian/pool/main/a/aom/libaom3_3.11.0~rc1-1_arm64.deb -RUN curl -O http://ftp.us.debian.org/debian/pool/main/a/aom/libaom3_3.11.0~rc1-1_$(dpkg --print-architecture).deb && \ - dpkg -i libaom3_3.11.0~rc1-1_$(dpkg --print-architecture).deb && \ - rm libaom3_3.11.0~rc1-1_$(dpkg --print-architecture).deb +COPY ./assets /build/assets +# Install libam with correct arch +RUN dpkg -i /build/assets/libaom3_3.11.0-1_$(dpkg --print-architecture).deb && \ + rm /build/assets/libaom3_3.11.0-1_$(dpkg --print-architecture).deb COPY --from=builder /build/webp-server /usr/bin/webp-server COPY --from=builder /build/config.json /etc/config.json diff --git a/assets/libaom3_3.11.0-1_amd64.deb b/assets/libaom3_3.11.0-1_amd64.deb new file mode 100644 index 000000000..6f05ed667 Binary files /dev/null and b/assets/libaom3_3.11.0-1_amd64.deb differ diff --git a/assets/libaom3_3.11.0-1_arm64.deb b/assets/libaom3_3.11.0-1_arm64.deb new file mode 100644 index 000000000..0ee1f4f67 Binary files /dev/null and b/assets/libaom3_3.11.0-1_arm64.deb differ diff --git a/config/config.go b/config/config.go index 95da7dc61..e5ddc5f04 100644 --- a/config/config.go +++ b/config/config.go @@ -43,19 +43,20 @@ const ( ) var ( - ConfigPath string - Jobs int - DumpSystemd bool - DumpConfig bool - ShowVersion bool - ProxyMode bool - Prefetch bool - Config = NewWebPConfig() - Version = "0.12.0" - WriteLock = cache.New(5*time.Minute, 10*time.Minute) - ConvertLock = cache.New(5*time.Minute, 10*time.Minute) - LocalHostAlias = "local" - RemoteCache *cache.Cache + ConfigPath string + Jobs int + DumpSystemd bool + DumpConfig bool + ShowVersion bool + ProxyMode bool + Prefetch bool // Prefech in go-routine, with WebP Server Go launch normally + PrefetchForeground bool // Standalone prefetch, prefetch and exit + Config = NewWebPConfig() + Version = "0.12.3" + WriteLock = cache.New(5*time.Minute, 10*time.Minute) + ConvertLock = cache.New(5*time.Minute, 10*time.Minute) + LocalHostAlias = "local" + RemoteCache *cache.Cache ) type MetaFile struct { @@ -123,7 +124,8 @@ func NewWebPConfig() *WebpConfig { func init() { flag.StringVar(&ConfigPath, "config", "config.json", "/path/to/config.json. (Default: ./config.json)") - flag.BoolVar(&Prefetch, "prefetch", false, "Prefetch and convert image to WebP format.") + flag.BoolVar(&Prefetch, "prefetch", false, "Prefetch and convert images to optimized format, with WebP Server Go launch normally") + flag.BoolVar(&PrefetchForeground, "prefetch-foreground", false, "Prefetch and convert image to optimized format in foreground, prefetch and exit") flag.IntVar(&Jobs, "jobs", runtime.NumCPU(), "Prefetch thread, default is all.") flag.BoolVar(&DumpConfig, "dump-config", false, "Print sample config.json.") flag.BoolVar(&ShowVersion, "V", false, "Show version information.") diff --git a/webp-server.go b/webp-server.go index 392f4757c..7f4f33d2a 100644 --- a/webp-server.go +++ b/webp-server.go @@ -86,6 +86,10 @@ func main() { } if config.Prefetch { go encoder.PrefetchImages() + } else if config.PrefetchForeground { + // Standalone prefetch, prefetch and exit + encoder.PrefetchImages() + os.Exit(0) } app.Use(etag.New(etag.Config{ Weak: true, @@ -98,5 +102,8 @@ func main() { fmt.Println("WebP Server Go is Running on http://" + listenAddress) - _ = app.Listen(listenAddress) + bindErr := app.Listen(listenAddress) + if bindErr != nil { + log.Fatal("Error starting server: ", bindErr) + } }