Skip to content

Commit

Permalink
Add prefetch-foreground
Browse files Browse the repository at this point in the history
  • Loading branch information
n0vad3v committed Nov 24, 2024
1 parent a08b6e6 commit 98ea9ba
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
10 changes: 4 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added assets/libaom3_3.11.0-1_amd64.deb
Binary file not shown.
Binary file added assets/libaom3_3.11.0-1_arm64.deb
Binary file not shown.
30 changes: 16 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.")
Expand Down
9 changes: 8 additions & 1 deletion webp-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}

0 comments on commit 98ea9ba

Please sign in to comment.