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

test: test-project switch from mounting to building image with docker #1482

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

nightknighto
Copy link
Contributor

@nightknighto nightknighto commented Apr 8, 2025

Description

In generator's test-project, convert mounting the project to building an image:

  • Adds .gitattributes to enforce all scripts to be downloaded in LF line ending.
  • Adds Dockerfile for building an image of the project
  • Replaces mounting with building in docker compose
  • Adds .dockerignore in the root (the context of the building)
  • Removes now redundant test-entrypoint script

Follow-up issues:

  • optimize Dockerfile.
  • simplify test.sh script.

Related issue(s)

Fixes #1425

Screenshots

Tests passing
image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Streamlined container build and test configurations now enable on-demand, optimized image construction for improved testing reliability.
  • Chores

    • Refined the build process by excluding unnecessary files, resulting in leaner container images.
    • Standardized script formatting for consistent behavior across platforms.
    • Removed an obsolete automation script to simplify the test environment setup.
    • Introduced new configuration files for Docker and Git attributes to enhance project consistency.

Copy link

changeset-bot bot commented Apr 8, 2025

⚠️ No Changeset found

Latest commit: fb6bc4a

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

coderabbitai bot commented Apr 8, 2025

Walkthrough

This pull request introduces new configuration files to enhance the Docker testing workflow for the generator’s test-project. It adds a .dockerignore to exclude unnecessary files during build, a .gitattributes to enforce LF line endings for shell scripts, and a Dockerfile that copies the project into the container and runs tests. In addition, the docker-compose.yml configuration is updated to build the image using the new Dockerfile rather than using a pre-built image. The changes also remove the obsolete test-entrypoint.sh script.

Changes

File(s) Change Summary
.dockerignore
.gitattributes
New files added. .dockerignore excludes Node, log, OS, and IDE files; .gitattributes enforces LF line endings for .sh and .bash scripts.
apps/generator/test/test-project/Dockerfile Introduces a new Dockerfile for the test project using a Node.js base image, copying project files, and running a test script.
apps/generator/test/test-project/docker-compose.yml Updates service configuration to build from the Dockerfile with a build context and NODE_VERSION argument, removing the previous image, volumes, and command directives.
apps/generator/test/test-project/test-entrypoint.sh Removed to eliminate the need for file copying and mounting, streamlining the test workflow.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DockerCompose
    participant Dockerfile
    participant Container
    User->>DockerCompose: Execute docker-compose up
    DockerCompose->>Dockerfile: Invoke image build (with NODE_VERSION arg)
    Dockerfile->>Container: Copy project files & set up environment
    Container->>Container: Run test script (test.sh)
    Container-->>User: Return test results
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix line-ending issues for bash scripts (#1425)
Simplify testing workflow using Dockerfile and updated docker-compose (#1425)
Remove dependency on mounting by eliminating the test-entrypoint.sh script (#1425)

Suggested labels

ready-to-merge

Suggested reviewers

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

Poem

I'm a nimble rabbit, hopping through code,
With Dockerfiles and ignores lightening the load.
LF scripts ensure my carrots are sweet,
No mounting mess – just streamlined and neat.
My whiskers twitch at the changes so bright,
Celebrating smooth tests from morning to night.
Hoppy coding to all in this clever byte!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b825dd0 and a544823.

📒 Files selected for processing (1)
  • apps/generator/test/test-project/docker-compose.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/generator/test/test-project/docker-compose.yml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test generator as dependency with Node 18

🪧 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.

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 (2)
apps/generator/test/test-project/Dockerfile (1)

5-8: Copying Project Context and Script Execution

The COPY . /app instruction leverages the build context provided by the accompanying .dockerignore file to omit unnecessary files. The CMD correctly specifies running the test script (test.sh) with a parameter. If further optimization is needed down the line (for example, reducing image size or adopting multi-stage builds), consider this as an area for optional refactoring.

apps/generator/test/test-project/docker-compose.yml (1)

11-12: Assessing Privileged Mode Usage

The test-project service is configured with privileged: true. Verify that this elevated permission is strictly necessary for the tests to run correctly, as it may introduce security risks. If possible, consider reducing privileges.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b0172d and b825dd0.

📒 Files selected for processing (5)
  • .dockerignore (1 hunks)
  • .gitattributes (1 hunks)
  • apps/generator/test/test-project/Dockerfile (1 hunks)
  • apps/generator/test/test-project/docker-compose.yml (1 hunks)
  • apps/generator/test/test-project/test-entrypoint.sh (0 hunks)
💤 Files with no reviewable changes (1)
  • apps/generator/test/test-project/test-entrypoint.sh
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test generator as dependency with Node 18
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test NodeJS PR - windows-latest
🔇 Additional comments (5)
.gitattributes (1)

1-3: Enforcing Consistent LF Line Endings

The file correctly ensures that all shell script files (with extensions .sh and .bash) use LF line endings. This is a good practice for avoiding cross-platform issues with script execution.

apps/generator/test/test-project/Dockerfile (1)

1-2: Proper Use of Build Arguments and Base Image

Defining ARG NODE_VERSION=18 and using it in the FROM node:${NODE_VERSION} instruction provides flexibility in selecting the Node.js version at build time.

apps/generator/test/test-project/docker-compose.yml (2)

13-17: Transition to Build Configuration

Switching from using a pre-built image to a build directive is well implemented. The build context is set to the project root, the correct Dockerfile is referenced, and the NODE_VERSION argument leverages the ${NODE_IMAGE_TAG} value. Ensure that the .dockerignore file further refines the build context.


21-24: Network Configuration Consistency

The network settings using the bridge driver are maintained consistently. This configuration should work well in your test environment.

.dockerignore (1)

1-38: Comprehensive Exclusion Patterns

The .dockerignore file effectively excludes directories and files that are not necessary for the Docker build context (e.g., node modules, logs, environment files, IDE settings, OS-specific files, and test artifacts). This will optimize the image build process by reducing the build context size.

Copy link

sonarqubecloud bot commented Apr 9, 2025

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.

[FEATURE] Improve generator's test-project docker testing workflow
1 participant