Skip to content

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

Merged
asyncapi-bot merged 13 commits into
asyncapi:masterfrom
nightknighto:docker-test-project-2
Apr 23, 2025
Merged

test: test-project switch from mounting to building image with docker#1482
asyncapi-bot merged 13 commits into
asyncapi:masterfrom
nightknighto:docker-test-project-2

Conversation

@nightknighto

@nightknighto nightknighto commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

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

  • Chores
    • Updated Docker configuration to allow specifying the Node.js version during builds.
    • Enhanced .dockerignore to exclude Docker-related files from build context.
    • Added .gitattributes to enforce consistent line endings for shell scripts.
    • Refined Docker Compose setup for test projects, switching to build-based configuration and simplifying service commands.
    • Removed an obsolete test entrypoint script.
    • Improved script reliability by using absolute paths during test execution.
    • Updated environment variable naming from NODE_IMAGE_TAG to NODE_VERSION in documentation and CI workflows.

@changeset-bot

changeset-bot Bot commented Apr 8, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dc9f852

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

@coderabbitai

coderabbitai Bot commented Apr 8, 2025

Copy link
Copy Markdown

Walkthrough

This set of changes updates the Docker-based testing workflow for the generator's test project. The Dockerfile now accepts a configurable Node.js version via build arguments. The .dockerignore file is enhanced to exclude Dockerfiles and docker-compose files, optimizing the build context. A .gitattributes file is introduced to enforce LF line endings for shell scripts, addressing cross-platform compatibility. The docker-compose.yml for the test project is restructured to use a build context instead of mounting the host directory, and the previously used test-entrypoint.sh script is removed. The test script is slightly adjusted to use absolute paths.

Changes

File(s) Change Summary
.dockerignore Updated to exclude all Dockerfiles and docker-compose files from the build context.
.gitattributes New file added to enforce LF line endings for .sh and .bash scripts.
Dockerfile Added NODE_VERSION build arg; base image now uses this argument for Node.js version.
apps/generator/test/test-project/docker-compose.yml Switched from mounting host to using Docker build context; removed privileged, image, and volumes; set user and command explicitly; removed version and network config.
apps/generator/test/test-project/test-entrypoint.sh Deleted the entrypoint script as it is no longer needed.
apps/generator/test/test-project/test.sh Changed working directory from relative app to absolute /app.
.github/workflows/pr-testing-with-test-project.yml Renamed environment variable from NODE_IMAGE_TAG to NODE_VERSION in Docker Compose command.
apps/generator/test/test-project/README.md Updated environment variable name from NODE_IMAGE_TAG to NODE_VERSION in Docker Compose commands.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Docker Compose
    participant Docker Engine
    participant Container (test-project)
    Developer->>Docker Compose: Run test-project service
    Docker Compose->>Docker Engine: Build image (with NODE_VERSION)
    Docker Engine->>Container (test-project): Start container with /app context
    Container (test-project)->>Container (test-project): Run test.sh in /app
Loading

Assessment against linked issues

Objective Addressed Explanation
Simplify test command and remove unnecessary flags (1)
Fix line-ending problems for shell scripts using .gitattributes (3)
Add Dockerfile, .dockerignore, and update docker-compose to use build context; remove mounting (4)
Remove test-entrypoint.sh and set up CMD/ENTRYPOINT in Docker (4)

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • derberg
  • magicmatatjahu
  • jonaslagoni

Poem

In the warren where Dockerfiles hop,
A rabbit nibbles—line endings, it’ll swap!
Compose now builds, no mounts to see,
Scripts line up with LF, so cross-OS is free.
Test-entrypoint’s gone, the path’s now clear,
For fluffy CI runs—let’s all cheer! 🐇🚀


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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.

@nightknighto

Copy link
Copy Markdown
Contributor Author

Let's put this PR on hold till #1465 is solved. I will probably re-use additions from it.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

24-24: Nitpick: Explicit network driver is redundant
By default, Compose uses the bridge driver. You can safely omit driver: bridge unless you need to override settings.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 21a26de and a95be33.

📒 Files selected for processing (3)
  • Dockerfile (1 hunks)
  • apps/generator/test/test-project/docker-compose.yml (1 hunks)
  • apps/generator/test/test-project/test.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
apps/generator/test/test-project/test.sh

[warning] 54-54: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • 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
  • GitHub Check: Test NodeJS PR - macos-13
🔇 Additional comments (2)
Dockerfile (1)

1-2: Parameterize Node.js version via build argument
Good use of ARG NODE_VERSION to make the base image configurable. Ensure you update any documentation or CI scripts to document the new NODE_VERSION build‑arg.

Do you have a README update or CI step to pass a custom NODE_VERSION? Verify that builds without explicitly passing --build-arg NODE_VERSION still behave as expected.

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

12-18: Verify build-based setup and environment variables
Switching from volume mounts to a build context is solid. Please confirm:

  1. Your CI or local environment defines NODE_IMAGE_TAG, otherwise NODE_VERSION may default unexpectedly.
  2. The pull_policy: build field is supported by your Compose version.
  3. Running the container as root is intentional—consider reverting to a non‑root user post‑build for security.


# Always run these steps
cd app
cd /app

@coderabbitai coderabbitai Bot Apr 22, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle potential cd /app failure
The new absolute path change is correct, but without error handling a failed cd could let subsequent commands run in the wrong directory.
Apply this diff to exit on failure:

- cd /app
+ cd /app || exit 1

This aligns with ShellCheck SC2164.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cd /app
- cd /app
+ cd /app || exit 1
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 54-54: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@nightknighto you don't like rabbit? 😄

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@nightknighto nightknighto Apr 23, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's good in many things, but this suggestion definitely isn't 😂

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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/README.md (2)

6-6: Use correct macOS capitalization.

The official branding for Apple's operating system is macOS, so update the label accordingly.

Apply this diff:

-Linux/MacOS: `NODE_VERSION=18 docker-compose up --abort-on-container-exit --force-recreate`.
+Linux/macOS: `NODE_VERSION=18 docker-compose up --abort-on-container-exit --force-recreate`.
🧰 Tools
🪛 LanguageTool

[grammar] ~6-~6: The operating system from Apple is written “macOS”.
Context: ...e and run the following command: Linux/MacOS: `NODE_VERSION=18 docker-compose up --a...

(MAC_OS)


8-8: Add spacing around the command separator for clarity.

Including spaces around && improves readability and prevents parsing issues in some environments.

Apply this diff:

-Windows: `set NODE_VERSION=18&& docker-compose up --abort-on-container-exit --force-recreate`.
+Windows: `set NODE_VERSION=18 && docker-compose up --abort-on-container-exit --force-recreate`.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a95be33 and c694ed6.

📒 Files selected for processing (3)
  • .github/workflows/pr-testing-with-test-project.yml (1 hunks)
  • apps/generator/test/test-project/README.md (1 hunks)
  • apps/generator/test/test-project/docker-compose.yml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .github/workflows/pr-testing-with-test-project.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/generator/test/test-project/docker-compose.yml
🧰 Additional context used
🪛 LanguageTool
apps/generator/test/test-project/README.md

[grammar] ~6-~6: The operating system from Apple is written “macOS”.
Context: ...e and run the following command: Linux/MacOS: `NODE_VERSION=18 docker-compose up --a...

(MAC_OS)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test generator as dependency with Node 18
  • GitHub Check: Test NodeJS PR - windows-latest

@nightknighto

nightknighto commented Apr 22, 2025

Copy link
Copy Markdown
Contributor Author

@derberg Updated the PR:

  • Removed the extra Dockerfile and re-used the root Dockerfile
  • Removed the redundant network defined in the docker compose. (The default network created functions the same)
  • Renamed "NODE_IMAGE_TAG" env variable to "NODE_VERSION" to unify naming and remove confusion between their names between Dockerfile and Docker Compose.

Ready for review

@derberg

derberg commented Apr 23, 2025

Copy link
Copy Markdown
Member

@nightknighto

Removed the extra Dockerfile

you mean custom entrypoint script?

@nightknighto

Copy link
Copy Markdown
Contributor Author

No, the removal of the script is an old change. I removed the Dockerfile created in an intermediary commit.

@derberg derberg moved this to Todo in Maintainers work Apr 23, 2025
@derberg derberg moved this from Todo to In Progress in Maintainers work Apr 23, 2025
@sonarqubecloud

Copy link
Copy Markdown

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

great stuff, just checked on local with podman, and works like a charm

long running of course 😄 but passing 😄

@derberg

derberg commented Apr 23, 2025

Copy link
Copy Markdown
Member

/rtm

@asyncapi-bot
asyncapi-bot merged commit 4369920 into asyncapi:master Apr 23, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Maintainers work Apr 23, 2025
@derberg derberg moved this from Done to Archive in Maintainers work Apr 30, 2025
@derberg

derberg commented May 6, 2025

Copy link
Copy Markdown
Member

@allcontributors please add @nightknighto for test,infra

@allcontributors

Copy link
Copy Markdown
Contributor

@derberg

I've put up a pull request to add @nightknighto! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Archive

Development

Successfully merging this pull request may close these issues.

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

3 participants