Kovah / LinkAce

LinkAce is a self-hosted archive to collect links of your favorite websites.
https://www.linkace.org
GNU General Public License v3.0
2.5k stars 159 forks source link

Reduce release image size #799

Closed rare-magma closed 1 week ago

rare-magma commented 1 month ago

Dev packages are not needed after the initial build. This results in a significant reduction in image size. current release-base size: 739.5 MB after this change: 288MB

Kovah commented 1 month ago

Thanks for taking the time to look at the Docker images!

From my test, both dev packages were needed for the backup feature to work properly. Otherwise neither Zip files would be created and Postgres database couldn't be dumped. Can you verify that?

rare-magma commented 1 month ago

@Kovah I can confirm libzip-dev is needed at least for this command: https://github.com/Kovah/LinkAce/blob/main/resources/docker/dockerfiles/release-multiplatform.Dockerfile#L78

I've changed the dockerfile to keep it and to install postgresql-client instead of the whole database. The resulting image is around 288MB Backups seem to be working fine: mariadb:

/app # php artisan backup:run
Starting backup...
Dumping database linkace...
Determining files to backup...
Zipping 1083 files and directories...
Created zip containing 1083 files and directories. Size is 1.68 MB
Copying zip to disk named local_backups...
Successfully copied zip to disk named local_backups.
Sending notification failed
Backup completed!

I haven't tested it with postgres/sqlite

Kovah commented 1 month ago

Thanks for taking a look at this. I will test the Postgres backup as soon as I can.

Kovah commented 1 week ago

I am pushing this to a possible next relase. I wasn't able to successfully create any Postgres backups. It might be possible to completely remove the binaries in future images, as it seems difficult to get everything correct. 😕

rare-magma commented 1 week ago

@Kovah did you face any particular issue/error? I just tried to generate a backup after setting up a Linkace instance with postgres and it seems to work as expected. I ran podman exec -it linkace_app_1 php artisan backup:run and it generated the same output as an image with the dev packages

Kovah commented 1 week ago

I sadly closed the terminal already, but first it complained that no postgres-client binaries could be found, despite being installed just a minute before. After installing them again, it complained that there is a mismatch between the installed client version (v13) and the server (v16).

Postgres at its best again. /s

This seems to mean that users need to have a matching Postgres server running for the client binaries installed. And if it's that strict, we can just leave it out completely.

rare-magma commented 1 week ago

which postgres version are you running? We can pin the package versions so they match the recommended postgres version in the docker compose examples like so:

...
RUN apk add --no-cache mariadb-client postgresql14-client postgresql14-dev sqlite zip libzip-dev; \
...
docker-compose:
...

  pg-db:
    image: docker.io/library/postgres:14
    environment:
...
Kovah commented 1 week ago

It seems that installing some old client cannot connect to newer Postgres version. But having a new client can connect to any version, including older ones. Merged this and publish it with the next release.

Many thanks for your time!

zhangyoufu commented 5 days ago

The v1.15.1 image on Docker Hub did not reflect this change.

@Kovah pushed linkace/base-image:php-8.3-reduced-size image week ago. But the release process is still using linkace/base-image:php-8.3-alpine as base image.

Kovah commented 5 days ago

Thanks for the heads up, just forgot to push the new base image. Will rerun as soon as it's available.