Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Optimize dockerfiles for production images #4302

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

vitoyucepi
Copy link
Collaborator

@vitoyucepi vitoyucepi commented Jan 7, 2025

Summary

This PR improves the Dockerfiles by creating smaller production images.

Details

  • Added a new stage for ADD, COPY, and download files.
  • Removed the tini process manager because it is unnecessary to run Liquidsoap as the main process. Also, some Debian dependencies, such as exim, are not installed due to --no-install-recommends.
  • Used RUN syntax that matches official images, making the Dockerfiles easier to read and understand.
  • Deleted apt lists from the final Debian container images to make them smaller.

Additionally

Size difference:

  • savonet/liquidsoap-alpine:rolling-release-v2.3.x: from 295MB to 278MB
  • savonet/liquidsoap:rolling-release-v2.3.x: from 795MB to 697MB

Refactored GitHub actions workflow to use docker/login-action and docker/build-push-action instead of docker login and build-docker.sh.

Renamed Dockerfiles:

  • Dockerfile.production to debian.dockerfile;
  • Dockerfile.alpine-production to alpine.dockerfile;
  • Dockerfile.website to website.dockerfile.
The list of packages removed from the debian-based image
alsa-topology-conf
alsa-ucm-conf
bsd-mailx
cron
cron-daemon-common
dbus
dbus-bin
dbus-daemon
dbus-session-bus-common
dbus-system-bus-common
dirmngr
exim4-base
exim4-config
exim4-daemon-light
ffmpeg
gnupg
gnupg-l10n
gnupg-utils
gpg
gpg-agent
gpg-wks-client
gpg-wks-server
gpgconf
gpgsm
i965-va-driver:amd64
intel-media-va-driver:amd64
krb5-locales
libaacs0:amd64
libapparmor1:amd64
libassuan0:amd64
libdecor-0-plugin-1-cairo:amd64
libevent-2.1-7:amd64
libgdk-pixbuf2.0-bin
libglib2.0-data
libgnutls-dane0:amd64
libgpm2:amd64
libidn12:amd64
libigdgmm12:amd64
libksba8:amd64
libldap-common
liblockfile-bin
liblockfile1:amd64
libnpth0:amd64
libnsl2:amd64
libproc2-0:amd64
libreadline8:amd64
librsvg2-common:amd64
libsasl2-modules:amd64
libunbound8:amd64
libvdpau-va-gl1:amd64
logrotate
mesa-va-drivers:amd64
mesa-vdpau-drivers:amd64
netbase
pinentry-curses
procps
psmisc
publicsuffix
readline-common
sensible-utils
tini
va-driver-all:amd64
vdpau-driver-all:amd64
xdg-user-dirs

@toots
Copy link
Member

toots commented Jan 7, 2025

This looks great. Nice trick on the multistage images, we wrote them long time ago when this wasn't available, it's great to see it used now.

@vitoyucepi vitoyucepi force-pushed the refactor/dockerfiles branch from 876a911 to 69400c9 Compare January 7, 2025 19:13
@vitoyucepi
Copy link
Collaborator Author

vitoyucepi commented Jan 7, 2025

Where should containers be pushed to?

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        if: needs.build_details.outputs.publish_docker_image == 'true'
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Login to container registries
        run: |
          echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USER }}" --password-stdin
          echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u "${{ github.actor }}" --password-stdin ghcr.io

Copy link
Member

@toots toots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@toots toots enabled auto-merge January 7, 2025 23:35
auto-merge was automatically disabled January 8, 2025 04:56

Head branch was pushed to by a user without write access

@vitoyucepi vitoyucepi changed the title refactor: Optimize dockerfiles for production images WIP: refactor: Optimize dockerfiles for production images Jan 8, 2025
@vitoyucepi vitoyucepi marked this pull request as draft January 8, 2025 05:24
@vitoyucepi vitoyucepi changed the title WIP: refactor: Optimize dockerfiles for production images refactor: Optimize dockerfiles for production images Jan 8, 2025
@vitoyucepi vitoyucepi force-pushed the refactor/dockerfiles branch 5 times, most recently from b2c29f9 to 9b987be Compare January 8, 2025 09:28
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@vitoyucepi vitoyucepi force-pushed the refactor/dockerfiles branch from 9b987be to 880b42e Compare January 8, 2025 14:57
vitoyucepi and others added 4 commits January 8, 2025 15:05
Create a separate stage to download files and mount it as a volume
later.
Remove tini as it's not needed to run liquidsoap as main process.
Use RUN syntax similar to that used for official images.
Remove apt lists from the resulting Debian container images.
Replace the build-docker.sh script with a GitHub action to standardize
the ci workflow and reduce complexity.
@vitoyucepi vitoyucepi force-pushed the refactor/dockerfiles branch from 880b42e to 6204a1e Compare January 8, 2025 15:24
@vitoyucepi vitoyucepi marked this pull request as ready for review January 8, 2025 15:24
@vitoyucepi
Copy link
Collaborator Author

@toots,
The PR is ready, I would like to see rebase and merge instead of squash and merge.

@toots toots merged commit b13bc07 into savonet:main Jan 8, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants