Skip to content

Commit e2c0d36

Browse files
authored
feat: reduce container size (#4)
1 parent c26a5a5 commit e2c0d36

7 files changed

Lines changed: 69 additions & 19 deletions

File tree

.github/workflows/pull-request.yaml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,44 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12+
env:
13+
IMAGE_INPUT_FILE: ./samples/bees.png
14+
IMAGE_OUTPUT_FILE: ./samples/bees-out-pr.jpg
1215
steps:
1316
- uses: actions/checkout@v6
1417

1518
- name: Build image
16-
run: docker build .
19+
run: docker build -t docker-google-guetzli .
20+
21+
- name: Run image
22+
run: |
23+
docker run --rm -v $(pwd):/data docker-google-guetzli \
24+
--quality 85 ${{ env.IMAGE_INPUT_FILE }} ${{ env.IMAGE_OUTPUT_FILE }}
25+
26+
- name: Validate output
27+
run: |
28+
if [ ! -f ${{ env.IMAGE_OUTPUT_FILE }} ]; then
29+
echo "ERROR: output file does not exist"
30+
exit 1
31+
fi
32+
33+
if [ ! -s ${{ env.IMAGE_OUTPUT_FILE }} ]; then
34+
echo "ERROR: output file is empty"
35+
exit 1
36+
fi
37+
38+
input_size=$(stat -c%s ${{ env.IMAGE_INPUT_FILE }})
39+
output_size=$(stat -c%s ${{ env.IMAGE_OUTPUT_FILE }})
40+
41+
if [ "$output_size" -ge "$input_size" ]; then
42+
echo "ERROR: output file ($output_size bytes) is not smaller than input ($input_size bytes)"
43+
exit 1
44+
fi
45+
46+
mime_type=$(file --mime-type -b ${{ env.IMAGE_OUTPUT_FILE }})
47+
if [ "$mime_type" != "image/jpeg" ]; then
48+
echo "ERROR: output file has unexpected MIME type: $mime_type (expected image/jpeg)"
49+
exit 1
50+
fi
51+
52+
echo "OK: $input_size bytes -> $output_size bytes"

Dockerfile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
FROM alpine:latest
2-
3-
WORKDIR /opt/google
1+
FROM alpine:3.21 AS builder
42

53
RUN apk --no-cache add \
64
libpng-dev \
@@ -12,10 +10,21 @@ ARG VERSION="v1.0.1"
1210

1311
RUN git clone https://github.com/google/guetzli.git \
1412
--branch "${VERSION}" \
15-
--depth 1
13+
--depth 1 \
14+
/opt/google/guetzli
15+
16+
RUN cd /opt/google/guetzli && make
17+
18+
19+
FROM alpine:3.21
20+
21+
RUN apk --no-cache add \
22+
libpng \
23+
libstdc++ \
24+
libgcc
1625

17-
RUN cd guetzli && make
26+
COPY --from=builder /opt/google/guetzli/bin/Release/guetzli /usr/local/bin/guetzli
1827

1928
WORKDIR /data
2029

21-
ENTRYPOINT ["/opt/google/guetzli/bin/Release/guetzli"]
30+
ENTRYPOINT ["guetzli"]

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,30 @@ docker run --rm -v $(pwd):/data ghcr.io/jveldboom/docker-google-guetzli:latest \
1212
## Run Examples
1313
```sh
1414
docker run --rm -v $(pwd):/data ghcr.io/jveldboom/docker-google-guetzli:latest \
15-
--quality 85 ./samples/bees.png ./samples/bees-out.png
15+
--quality 85 ./samples/bees.png ./samples/bees-out.jpg
1616
```
1717

1818
Original | Processed with 85%
1919
:------------: | :-------------:
20-
![Original](./samples/bees.png)<br>177 KB | ![Original](./samples/bees-out.png)<br> 22 KB
21-
![Original](./samples/rose.jpg)<br>219 KB | ![Original](./samples/rose-out.png)<br> 103 KB
20+
![Original](./samples/bees.png)<br>177 KB | ![Processed](./samples/bees-out.jpg)<br> 22 KB
21+
![Original](./samples/rose.jpg)<br>219 KB | ![Processed](./samples/rose-out.jpg)<br> 103 KB
22+
23+
## Performance
24+
Guetzli is intentionally slow — it tries many encodings to find the best compression. Expect processing to take **1 minute or more per megapixel**. It is best suited for batch or offline processing, not real-time use.
2225

23-
## TODO
24-
- [ ] create pull request workflow
25-
- [ ] include .dockerignore to reduce image size
26-
- [ ] see if we can reduce overall container size
26+
It also requires a minimum of **300 MB of memory per megapixel** of input image.
2727

28+
## Contributing
29+
30+
### Build the image locally
2831
```sh
29-
# dockerfile
30-
apk add --no-cache --virtual .build-deps
32+
# build the image locally
33+
docker build -t docker-google-guetzli .
3134

32-
...
35+
# run locally built image
36+
docker run --rm -v $(pwd):/data docker-google-guetzli \
37+
--quality 85 ./samples/bees.png ./samples/bees-out.png
3338

34-
apk del --no-cache .build-deps
35-
rm -rf /var/tmp/* /tmp/* /opt/build
39+
# check size
40+
docker image ls docker-google-guetzli
3641
```
101 KB
Loading

samples/self-portrait-out.jpg

718 KB
Loading

samples/self-portrait.jpg

1.28 MB
Loading

0 commit comments

Comments
 (0)