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

build: switch backend base image - part 1 #1416

Merged
merged 6 commits into from
Jan 24, 2025
Merged

build: switch backend base image - part 1 #1416

merged 6 commits into from
Jan 24, 2025

Conversation

ab-smith
Copy link
Contributor

@ab-smith ab-smith commented Jan 24, 2025

Part one is to switch to slim (debian) instead of alpine for the dependencies issues
Part two will be to switch to multi stage build to optimize the size even more

  • starting point
  • update dockerignore
  • wip

Summary by CodeRabbit

  • Docker Configuration

    • Updated .dockerignore to exclude additional cache and temporary files
    • Migrated Dockerfile from Alpine to slim Debian-based Python image
    • Improved dependency installation and locale support
  • Dependency Management

    • Updated matplotlib dependency to use more flexible version specification
  • Chores

    • Streamlined Docker build process and dependency installation

Copy link

coderabbitai bot commented Jan 24, 2025

Walkthrough

This pull request introduces modifications to the Docker configuration and dependency management in the backend project. The changes include updating the Dockerfile to use a slim Debian-based Python image, refining the .dockerignore file to exclude more build and cache-related files, and adjusting the matplotlib dependency in pyproject.toml to use a more flexible version specification. These updates aim to improve the project's containerization and dependency management strategies.

Changes

File Change Summary
backend/.dockerignore Added patterns to ignore .DS_Store, db, __pycache__/, .pytest_cache__/, .ruff_cache__/, static/, and pytest-report.html
backend/Dockerfile Switched from Alpine to slim Debian base image, consolidated environment variables, updated package installation to use apt-get, modified Poetry installation process
backend/pyproject.toml Updated matplotlib dependency from fixed version 3.9.3 to compatible version ^3.9.3

Poem

🐰 A Docker dance of changes light,
Slim images taking gentle flight,
Caches hidden, dependencies free,
Matplotlib's version now more carefree,
Coding magic with a rabbit's might! 🚀


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ab-smith ab-smith changed the title refactor: switch backend base image - part 1 build: switch backend base image - part 1 Jan 24, 2025
backend/Dockerfile Show resolved Hide resolved
backend/Dockerfile Outdated Show resolved Hide resolved
@ab-smith ab-smith marked this pull request as ready for review January 24, 2025 16:18
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
backend/Dockerfile (1)

12-41: 🛠️ Refactor suggestion

Optimize package installation and locale generation.

The package installation and locale generation can be optimized for better cache utilization and readability.

  1. Separate OS preparation from app build commands:
 RUN apt-get update && apt-get install -y \
     libyaml-cpp-dev \
     libffi-dev \
     libglib2.0-0 \
     pango-1.0 \
     libcairo2 \
     locales \
     tzdata \
     gettext \
     fontconfig \
     fonts-freefont-ttf \
     zlib1g-dev \
     && apt-get clean \
-    && rm -rf /var/lib/apt/lists/* \
-    && locale-gen en_US.UTF-8 \
-    && locale-gen ar_SA.UTF-8 \
-    && locale-gen fr_FR.UTF-8 \
-    && locale-gen pt_PT.UTF-8 \
-    && locale-gen es_ES.UTF-8 \
-    && locale-gen de_DE.UTF-8 \
-    && locale-gen nl_NL.UTF-8 \
-    && locale-gen it_IT.UTF-8 \
-    && locale-gen pl_PL.UTF-8 \
-    && locale-gen ro_RO.UTF-8 \
-    && locale-gen hi_IN.UTF-8 \
-    && locale-gen ur_PK.UTF-8 \
-    && locale-gen cs_CZ.UTF-8 \
-    && locale-gen sv_SE.UTF-8 \
-    && locale-gen id_ID.UTF-8 \
-    && pip install --no-cache-dir --upgrade pip poetry==2.0.1
+    && rm -rf /var/lib/apt/lists/*

+RUN locale-gen en_US.UTF-8 ar_SA.UTF-8 fr_FR.UTF-8 pt_PT.UTF-8 es_ES.UTF-8 \
+    de_DE.UTF-8 nl_NL.UTF-8 it_IT.UTF-8 pl_PL.UTF-8 ro_RO.UTF-8 hi_IN.UTF-8 \
+    ur_PK.UTF-8 cs_CZ.UTF-8 sv_SE.UTF-8 id_ID.UTF-8

+RUN pip install --no-cache-dir --upgrade pip poetry==2.0.1
  1. Consider adding comments to explain the purpose of each package group.
🧹 Nitpick comments (3)
backend/.dockerignore (1)

2-14: LGTM! Consider adding more patterns for Python development.

The added patterns effectively exclude cache directories and temporary files, which helps reduce the Docker build context size and improve build performance.

Consider adding these additional patterns commonly used in Python projects:

+.coverage
+htmlcov/
+.mypy_cache/
+.env
+*.egg-info/
+dist/
+build/
backend/Dockerfile (2)

43-46: Consider multi-stage build for production image.

The current setup installs development dependencies in the final image. This will be addressed in part 2 with multi-stage builds.

For part 2, consider:

  1. Using multi-stage builds to separate build and runtime dependencies
  2. Creating a dedicated build stage for compiling dependencies
  3. Copying only necessary files to the final stage

48-49: Add comment explaining the warning about local files.

The comment about watching out for local files during dev could be more descriptive.

-#watch out for local files during dev and maintenance of .dockerignore
+# Ensure .dockerignore is properly maintained to exclude unnecessary files
+# that might be present in local development environment
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c01d2e9 and 15aec5d.

⛔ Files ignored due to path filters (1)
  • backend/poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • backend/.dockerignore (1 hunks)
  • backend/Dockerfile (1 hunks)
  • backend/pyproject.toml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: test (3.12)
  • GitHub Check: build (3.12)
  • GitHub Check: startup-functional-test (3.12)
🔇 Additional comments (1)
backend/Dockerfile (1)

1-8: LGTM! Environment variables are well organized.

The switch to slim Debian base image and the consolidation of environment variables improve maintainability. The environment variables follow best practices for Poetry configuration.

backend/pyproject.toml Show resolved Hide resolved
@eric-intuitem eric-intuitem self-requested a review January 24, 2025 18:24
Copy link
Collaborator

@eric-intuitem eric-intuitem left a comment

Choose a reason for hiding this comment

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

LGTM

@ab-smith ab-smith merged commit c681577 into main Jan 24, 2025
19 checks passed
@ab-smith ab-smith deleted the switch_base_image branch January 24, 2025 18:32
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2025
@ab-smith ab-smith added the perf label Jan 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants