shssoichiro / oxipng

Multithreaded PNG optimizer written in Rust
MIT License
2.95k stars 125 forks source link

Improved Docker image + publish on `ghcr.io` #642

Open AFCMS opened 1 month ago

AFCMS commented 1 month ago

Fix #610

I also changed the WORKDIR from /src to /work, because if got me confused with the use of the src folder for the project source in the first stage of the Dockerfile. It doesn't impact anything anyways since you can mount the file where you want and have the program options point to it.

How to test? After checking out the branch and making sure you have QEMU installed to build/test

# Docker sadly doesn't have yet the way to have locally a tag with multiple platforms
# despite being able to pass multiple platforms to the build command, so we have to use two distinct tags.
docker build --platform=linux/amd64 --tag test-oxipng-amd:latest --load .
docker build --platform=linux/arm64 --tag test-oxipng-arm:latest --load .

docker run --rm test-oxipng-amd:latest --version
docker run --rm test-oxipng-arm:latest --version

# Run on some files
docker run --rm -it -v $(pwd):/work test-oxipng-amd:latest -a /work/tests/files/apng_file.png
docker run --rm -it -v $(pwd):/work test-oxipng-arm:latest -a /work/tests/files/apng_file.png

# Remove the images
docker image rm test-oxipng-amd:latest
docker image rm test-oxipng-arm:latest

For the workflow, see the GitHub Actions logs. If you want to test the ghcr.io publishing you can merge the branch into a fork and see the result.

AFCMS commented 1 month ago

I don't have a really specific usecase, I did this PR mostly as a training for both Docker and Rust :sweat_smile: (I use the tool with cargo install usually)

Anyways, I think the benefit of a Docker container over the portable binary is that you don't need to go to the download page, extract the binary and then go back regularly to check if there is any new version. With Docker you can just run the command in documentation with the latest image and the --pull=always flag, so it will download or update if needed and run the program automatically.

AlexTMjugador commented 1 month ago

Thanks for the comment @AFCMS, I do indeed realize now that the convenience of unifying software distribution through Docker containers can be valuable. Let's wait a bit for Josh's view on using GitHub Packages before merging :rocket:

andrews05 commented 1 month ago

I wonder if it would be better for someone to maintain this externally from the main repo...

AlexTMjugador commented 1 month ago

I wonder if it would be better for someone to maintain this externally from the main repo...

I think it's more discoverable and official-looking to use the same repository both for Docker images and development, but anyone is free to create a repository for hosting their own OxiPNG Docker images of course.