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

feat: add a makefile for local docker env setup #3417

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

Conversation

YashGupt29
Copy link

@YashGupt29 YashGupt29 commented Nov 20, 2024

PR Title:

feat: Add Makefile for streamlined development environment setup

Description:

  • feat: Added a Makefile to automate Docker-related commands, simplifying the setup process for contributors.
  • Introduced the following targets:
    • make build: To build the Docker image.
    • make run: To build and run the Docker container.
    • make clean: To remove Docker images and clean up resources.
  • This change improves efficiency, reduces errors, and enhances consistency for all contributors.

Related issue(s):

Resolves #3416

Summary by CodeRabbit

  • New Features
    • Introduced a Makefile to simplify the build and execution process for the Dockerized asyncapi-website application.
    • Added commands to run the application in a Docker container and clean up unused Docker resources.

These changes enhance user experience by streamlining application management.

Copy link

coderabbitai bot commented Nov 20, 2024

Walkthrough

A new Makefile has been introduced to streamline the development environment for the asyncapi-website Dockerized application. This Makefile includes variables for application configuration and defines targets for building, running, and cleaning the Docker environment. The run target manages the Docker container lifecycle, while the clean target handles image and object cleanup, both with error handling to ensure smooth operation.

Changes

File Change Summary
Makefile Introduced a new Makefile with variables APP_NAME, CONTAINER_NAME, PORT, and targets run, clean.

Assessment against linked issues

Objective Addressed Explanation
Introduce a Makefile to simplify and streamline the process of setting up the development environment. (#3416)
Provide predefined targets to automate the Docker workflow, including make run and make clean. (#3416)

Poem

🐇 In the garden where the code does play,
A Makefile hops in to save the day.
With run and clean, it makes things neat,
No more long commands, just a simple treat!
So come, dear friends, let’s build and cheer,
For a smoother path, the rabbit holds dear! 🥕✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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

Copy link

netlify bot commented Nov 20, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c82ca31
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67417c26340c47000857ac2f
😎 Deploy Preview https://deploy-preview-3417--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.77%. Comparing base (bc2ab51) to head (c82ca31).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3417   +/-   ##
=======================================
  Coverage   67.77%   67.77%           
=======================================
  Files          21       21           
  Lines         664      664           
=======================================
  Hits          450      450           
  Misses        214      214           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Nov 20, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 32
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3417--asyncapi-website.netlify.app/

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

🧹 Outside diff range and nitpick comments (3)
Makefile (3)

15-18: Add health check and improve volume mounting.

The current implementation doesn't verify if the container started successfully, and the volume path handling could be improved.

Apply this diff to enhance container management:

-	@docker run -d --name $(CONTAINER_NAME) -v "$$(pwd)":/async -p $(PORT):$(PORT) $(APP_NAME)
-	@sleep 2 # Allow container to start
+	@docker run -d --name $(CONTAINER_NAME) \
+		--network $(DOCKER_NETWORK) \
+		--platform $(DOCKER_PLATFORM) \
+		-v "$${PWD}":/async \
+		-p $(PORT):$(PORT) \
+		$(APP_NAME)
+	@echo "Waiting for container to be healthy..."
+	@timeout 30s sh -c 'until docker ps --filter "name=$(CONTAINER_NAME)" --format "{{.Status}}" | grep -q "Up"; do sleep 1; done'
 	@echo "Displaying Docker logs..."
 	@docker logs -f $(CONTAINER_NAME)

21-24: Enhance cleanup operations with safety measures.

The clean target should include container cleanup and provide options for selective cleaning with confirmation prompts.

Apply this diff to improve cleanup operations:

-# Clean Docker Images
-clean:
-	@echo "Cleaning up Docker images..."
-	@docker rmi $(APP_NAME) || true
-	@docker system prune -f || true
+# Cleanup targets
+clean: clean-container clean-image
+
+clean-container:
+	@echo "Cleaning up container..."
+	@docker stop $(CONTAINER_NAME) || true
+	@docker rm $(CONTAINER_NAME) || true
+
+clean-image:
+	@echo "Cleaning up Docker image..."
+	@docker rmi $(APP_NAME) || true
+
+clean-all:
+	@echo "This will remove all unused Docker resources. Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
+	@docker system prune

1-2: Add comprehensive documentation and usage examples.

The Makefile would benefit from detailed documentation about available targets, usage examples, and prerequisites.

Add this documentation at the beginning of the file:

 # Makefile
+
+# Prerequisites:
+#   - Docker installed and running
+#   - Make utility installed
+#
+# Available targets:
+#   make build         - Build Docker image
+#   make run          - Build and run container
+#   make clean        - Remove container and image
+#   make clean-all    - Deep clean Docker resources
+#
+# Examples:
+#   make build PORT=8080
+#   make run DOCKER_NETWORK=custom-network
+#   make clean
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bf857b3 and c03759f.

📒 Files selected for processing (1)
  • Makefile (1 hunks)

Comment on lines +8 to +18
run:
@echo "Building Docker image..."
@docker build -t $(APP_NAME) .
@echo "Stopping and removing any existing container..."
@docker stop $(CONTAINER_NAME) || true
@docker rm $(CONTAINER_NAME) || true
@echo "Starting Docker container..."
@docker run -d --name $(CONTAINER_NAME) -v "$$(pwd)":/async -p $(PORT):$(PORT) $(APP_NAME)
@sleep 2 # Allow container to start
@echo "Displaying Docker logs..."
@docker logs -f $(CONTAINER_NAME)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Separate build and run targets for better modularity.

The run target combines building and running. These should be separate targets for better control and modularity.

Apply this diff to restructure the targets:

+.PHONY: build run clean
+
+# Build Docker Image
+build:
+	@echo "Building Docker image..."
+	@docker build -t $(APP_NAME) -f $(DOCKER_FILE) $(DOCKER_CONTEXT)
+
 # Build, Run, and Show Logs
-run:
-	@echo "Building Docker image..."
-	@docker build -t $(APP_NAME) .
+run: build
 	@echo "Stopping and removing any existing container..."
 	@docker stop $(CONTAINER_NAME) || true
 	@docker rm $(CONTAINER_NAME) || true

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +3 to +5
APP_NAME=asyncapi-website
CONTAINER_NAME=asyncapi-website-container
PORT=3000
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make variables configurable and add essential Docker settings.

The variables should be overridable from the command line, and additional Docker-related settings would be beneficial.

Apply this diff to improve variable declarations:

-APP_NAME=asyncapi-website
-CONTAINER_NAME=asyncapi-website-container
-PORT=3000
+APP_NAME ?= asyncapi-website
+CONTAINER_NAME ?= asyncapi-website-container
+PORT ?= 3000
+
+# Docker configuration
+DOCKER_FILE ?= Dockerfile
+DOCKER_CONTEXT ?= .
+DOCKER_NETWORK ?= bridge
+DOCKER_PLATFORM ?= linux/amd64
📝 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
APP_NAME=asyncapi-website
CONTAINER_NAME=asyncapi-website-container
PORT=3000
APP_NAME ?= asyncapi-website
CONTAINER_NAME ?= asyncapi-website-container
PORT ?= 3000
# Docker configuration
DOCKER_FILE ?= Dockerfile
DOCKER_CONTEXT ?= .
DOCKER_NETWORK ?= bridge
DOCKER_PLATFORM ?= linux/amd64

@anshgoyalevil anshgoyalevil changed the title feat:added a makefile for streamlining the development process feat: add a makefile for local docker env setup Nov 21, 2024
@anshgoyalevil
Copy link
Member

I am in favor of using a Makefile but it doesn't suit AsyncAPI website repository. Make isn't installed by default on windows and it is the only OS which a person would use docker on to run AsyncAPI website locally.

@YashGupt29
Copy link
Author

@anshgoyalevil i can write a windows powershell script which mimics the same make file which i wrote ,
this will be solely for windows and this makefile will be for linux users we can do like this because the docker commands are so big and it is very tedious to open the docs of the repo and than use it in dev env for contribution

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] : add a makefile for local docker env setup
3 participants