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

chore(docker): improve Dockerfile for smaller image and better PDF support #1475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Hemanthbugata
Copy link

@Hemanthbugata Hemanthbugata commented Apr 6, 2025


✨ Description

This PR improves the existing Dockerfile used for building the AsyncAPI Generator CLI image by addressing performance, stability, and usability issues found in the current implementation.

✅ Changes Introduced

  1. Improved Layer Caching and Build Performance

    • Replaced apk --update add with apk add --no-cache to eliminate the need for manual cache cleanup and reduce image size.
  2. Better Support for Chromium & PDF Generation

    • Added missing dependencies (nss, freetype, harfbuzz, ttf-freefont, etc.) required for Chromium to run correctly, especially when generating PDFs with templates like html-template.
  3. Improved Runtime Flexibility

    • Added CMD ["--help"] to work in conjunction with the ENTRYPOINT. This allows users to run arbitrary ag commands with better Docker UX, while still defaulting to help output when no args are provided.

🐛 Problem with the Old Version

  • Chromium-based PDF generation fails silently or throws obscure errors due to missing runtime libraries.
  • Image layers are sub-optimal due to leftover package cache.
  • Limited CLI flexibility due to hard ENTRYPOINT.

🧪 Test Results

Built and tested locally:

docker build -t asyncapi-gen:test .
docker run --rm asyncapi-gen:test --version
docker run --rm asyncapi-gen:test generate --help

All tests passed and CLI is functional with improved runtime behavior.


Summary by CodeRabbit

  • Chores
    • Updated the container setup with additional dependencies for enhanced performance.
    • Refined the default startup behavior by including a help command for improved user guidance.

Copy link

changeset-bot bot commented Apr 6, 2025

⚠️ No Changeset found

Latest commit: 2c23681

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Copy link

sonarqubecloud bot commented Apr 6, 2025

@Hemanthbugata Hemanthbugata changed the title This a Updated Dockerfile pull request update dockerfile Apr 6, 2025
@Hemanthbugata Hemanthbugata changed the title update dockerfile chore(docker): improve Dockerfile for smaller image and better PDF support Apr 6, 2025
Copy link

coderabbitai bot commented Apr 6, 2025

Walkthrough

This pull request updates the Dockerfile in the generator application. The changes include modifications to the dependency installation process by adding libraries (nss, freetype, harfbuzz, ca-certificates, and ttf-freefont) and removing the --update flag. Additionally, outdated comments about Chromium and Git have been removed. An explicit CMD instruction with a default argument of --help has been added, while the ENTRYPOINT remains unchanged. There are no alterations to exported or public entities.

Changes

File(s) Change Summary
apps/…/Dockerfile Updated dependency installation to include nss, freetype, harfbuzz, ca-certificates, and ttf-freefont; removed --update flag; removed obsolete comments; added explicit CMD --help command.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant DE as Docker Engine
    participant C as Container
    U->>DE: Execute "docker run" command
    DE->>C: Start container using updated Dockerfile
    C->>C: Run ENTRYPOINT
    C->>C: Apply default CMD argument (--help)
    C-->>U: Display help output
Loading

Suggested labels

ready-to-merge

Suggested reviewers

  • magicmatatjahu
  • asyncapi-bot-eve
  • derberg
  • jonaslagoni

Poem

Oh, what a joyful day in code-land,
A rabbit hops with glee and delight,
Dependencies refreshed and commands in hand,
Container starts with --help shining bright,
May our changes grow strong like carrots at night!
🥕🐰 Happy coding, with leaps of insight!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@Hemanthbugata
Copy link
Author

@derberg, hi , check the updated Dockerfile for improved caching, better build performance, and enhanced support for Chromium and PDF generation and run flexibility

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: 0

🧹 Nitpick comments (1)
apps/generator/Dockerfile (1)

10-18: Optimized Dependency Installation and Layer Caching
The updated RUN command now uses apk add --no-cache instead of the outdated --update flag. This change eliminates the need for manual cache cleanup, reducing the overall image size and improving build performance. Moreover, the inclusion of additional dependencies (nss, freetype, harfbuzz, ca-certificates, and ttf-freefont) is essential for the correct operation of Chromium, especially for PDF generation.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 85ddcd7 and 2c23681.

📒 Files selected for processing (1)
  • apps/generator/Dockerfile (1 hunks)
🔇 Additional comments (2)
apps/generator/Dockerfile (2)

1-9: Base Image and Environment Variables Configuration
The base image (node:18-alpine) and the environment variables for Puppeteer are properly set up. Using PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true in conjunction with the manual installation of Chromium helps keep the image lightweight and ensures that the system’s Chromium is used rather than downloading another copy.


21-22: Enhanced Command Flexibility with Default CMD Instruction
By setting ENTRYPOINT to ["ag"] and appending CMD ["--help"], the Dockerfile now provides a sensible default behavior while allowing users to override the default command with custom arguments when invoking the container. This pattern improves the CLI's usability and runtime flexibility.

# Install git, chromium, and required libs
RUN apk add --no-cache \
git \
chromium \
Copy link
Contributor

Choose a reason for hiding this comment

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

hey @Hemanthbugata any relevant links or screenshots or docs from where you have taken the reference of these packages to be installed.

Copy link
Author

Choose a reason for hiding this comment

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

@Hemanthbugata Hemanthbugata requested a review from ItshMoh April 7, 2025 09:31
@derberg
Copy link
Member

derberg commented Apr 7, 2025

Can you reference what existing issue is this PR addressing?

Also, did you look into existing issues and PRs to see if you are not duplicating the efforts of other contributors?

@nightknighto
Copy link
Contributor

🐛 Problem with the Old Version
1- Chromium-based PDF generation fails silently or throws obscure errors due to missing runtime libraries.
2- Image layers are sub-optimal due to leftover package cache.
3- Limited CLI flexibility due to hard ENTRYPOINT.

For point 1, I didn't test myself, but I doubt it would have gone unnoticed all that long if there were indeed problems like those.

For point 2, there are no leftover package cache, they are removed manually. You made it look better in code, but it wasn't a problem.

For point 3, well you didn't really do anything about the entrypoint, just added a default value for CMD. The default value is nice, but it doesn't address the "problem" you mentioned, which isn't really a problem as the hard entrypoint here is correct.

Most importantly, as @derberg said, you didn't open an issue first to discuss your problems and the solutions you want to implement. You should open issues first, discuss, get approved, then open PRs.

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.

4 participants