Skip to content

Commit e696ee9

Browse files
authored
Add prefetch-foreground (#365)
1 parent a08b6e6 commit e696ee9

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ FROM debian:bookworm-slim
1616

1717
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/*
1818

19-
# Download and install libam with correct arch
20-
# http://ftp.us.debian.org/debian/pool/main/a/aom/libaom3_3.11.0~rc1-1_amd64.deb
21-
# http://ftp.us.debian.org/debian/pool/main/a/aom/libaom3_3.11.0~rc1-1_arm64.deb
22-
RUN curl -O http://ftp.us.debian.org/debian/pool/main/a/aom/libaom3_3.11.0~rc1-1_$(dpkg --print-architecture).deb && \
23-
dpkg -i libaom3_3.11.0~rc1-1_$(dpkg --print-architecture).deb && \
24-
rm libaom3_3.11.0~rc1-1_$(dpkg --print-architecture).deb
19+
COPY ./assets /build/assets
20+
# Install libam with correct arch
21+
RUN dpkg -i /build/assets/libaom3_3.11.0-1_$(dpkg --print-architecture).deb && \
22+
rm /build/assets/libaom3_3.11.0-1_$(dpkg --print-architecture).deb
2523

2624
COPY --from=builder /build/webp-server /usr/bin/webp-server
2725
COPY --from=builder /build/config.json /etc/config.json

assets/libaom3_3.11.0-1_amd64.deb

1.79 MB
Binary file not shown.

assets/libaom3_3.11.0-1_arm64.deb

1.61 MB
Binary file not shown.

config/config.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ const (
4343
)
4444

4545
var (
46-
ConfigPath string
47-
Jobs int
48-
DumpSystemd bool
49-
DumpConfig bool
50-
ShowVersion bool
51-
ProxyMode bool
52-
Prefetch bool
53-
Config = NewWebPConfig()
54-
Version = "0.12.0"
55-
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
56-
ConvertLock = cache.New(5*time.Minute, 10*time.Minute)
57-
LocalHostAlias = "local"
58-
RemoteCache *cache.Cache
46+
ConfigPath string
47+
Jobs int
48+
DumpSystemd bool
49+
DumpConfig bool
50+
ShowVersion bool
51+
ProxyMode bool
52+
Prefetch bool // Prefech in go-routine, with WebP Server Go launch normally
53+
PrefetchForeground bool // Standalone prefetch, prefetch and exit
54+
Config = NewWebPConfig()
55+
Version = "0.12.3"
56+
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
57+
ConvertLock = cache.New(5*time.Minute, 10*time.Minute)
58+
LocalHostAlias = "local"
59+
RemoteCache *cache.Cache
5960
)
6061

6162
type MetaFile struct {
@@ -123,7 +124,8 @@ func NewWebPConfig() *WebpConfig {
123124

124125
func init() {
125126
flag.StringVar(&ConfigPath, "config", "config.json", "/path/to/config.json. (Default: ./config.json)")
126-
flag.BoolVar(&Prefetch, "prefetch", false, "Prefetch and convert image to WebP format.")
127+
flag.BoolVar(&Prefetch, "prefetch", false, "Prefetch and convert images to optimized format, with WebP Server Go launch normally")
128+
flag.BoolVar(&PrefetchForeground, "prefetch-foreground", false, "Prefetch and convert image to optimized format in foreground, prefetch and exit")
127129
flag.IntVar(&Jobs, "jobs", runtime.NumCPU(), "Prefetch thread, default is all.")
128130
flag.BoolVar(&DumpConfig, "dump-config", false, "Print sample config.json.")
129131
flag.BoolVar(&ShowVersion, "V", false, "Show version information.")

webp-server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func main() {
8686
}
8787
if config.Prefetch {
8888
go encoder.PrefetchImages()
89+
} else if config.PrefetchForeground {
90+
// Standalone prefetch, prefetch and exit
91+
encoder.PrefetchImages()
92+
os.Exit(0)
8993
}
9094
app.Use(etag.New(etag.Config{
9195
Weak: true,
@@ -98,5 +102,8 @@ func main() {
98102

99103
fmt.Println("WebP Server Go is Running on http://" + listenAddress)
100104

101-
_ = app.Listen(listenAddress)
105+
bindErr := app.Listen(listenAddress)
106+
if bindErr != nil {
107+
log.Fatal("Error starting server: ", bindErr)
108+
}
102109
}

0 commit comments

Comments
 (0)