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

Optimize Dockerfile apt task #2671

Closed
wants to merge 1 commit into from
Closed

Optimize Dockerfile apt task #2671

wants to merge 1 commit into from

Conversation

benjisho
Copy link

@benjisho benjisho commented Apr 20, 2023

Background

Build process is currently taking 11 steps to complete, this change will optimize the apt tasks in Dockerfile, making it finish in just 8 steps.

Changes

  • Combined apt commands into a single RUN instruction. - This makes the build process shorter from 11 steps to 8 steps.
  • Added comments for clarity within the RUN command.

Documentation

  • No documentation needed, functions remain the same

Test Plan

Tested it on my personal Ubuntu VM.
You may test it on your environment, just replacing the lines in the Dockerfile accordingly

Before:

# Install git
RUN apt-get -y update
RUN apt-get -y install git chromium-driver

# Install Xvfb and other dependencies for headless browser testing
RUN apt-get update \
    && apt-get install -y wget gnupg2 libgtk-3-0 libdbus-glib-1-2 dbus-x11 xvfb ca-certificates

# Install Firefox / Chromium
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
    && apt-get update \
    && apt-get install -y chromium firefox-esr

After:

# Install git, Xvfb, Firefox, Chromium and other dependencies for headless browser testing
RUN apt-get update \
    # Install chromium-driver + Xvfb and other dependencies for headless browser testing
    && apt-get -y install git chromium-driver wget gnupg2 libgtk-3-0 libdbus-glib-1-2 dbus-x11 xvfb ca-certificates \
    # Install Firefox / Chromium
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
    # Update package index and install Chromium and Firefox
    && apt-get update \
    && apt-get install -y chromium firefox-esr

PR Quality Checklist

  • [v] My pull request is atomic and focuses on a single change.
  • [v] I have thoroughly tested my changes with multiple different prompts.
  • [v] I have considered potential risks and mitigations for my changes.
  • I have documented my changes clearly and comprehensively. - No documentation needed, functions remain the same
  • [v] I have not snuck in any "extra" small tweaks changes

@benjisho benjisho marked this pull request as ready for review April 20, 2023 13:04
@Pwuts
Copy link
Member

Pwuts commented Apr 20, 2023

Partial duplicate of #1199 (which we're already processing).

Also as a general comment: keeping the layers small and in descending order of build time helps caching. A better optimization would be:

  1. Install necessary build tools (e.g. wget)
  2. Install chromium-driver (includes chromium) -> 350 packages, 250MB
  3. Install remaining browser-related packages -> 42 packages, 91MB
  4. Install git and other small utilities -> small step

@Pwuts Pwuts closed this Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants