-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughA new Changes
Assessment against linked issues
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for asyncapi-website ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚨 Try these New Features:
|
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3417--asyncapi-website.netlify.app/ |
There was a problem hiding this 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
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) |
There was a problem hiding this comment.
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.
APP_NAME=asyncapi-website | ||
CONTAINER_NAME=asyncapi-website-container | ||
PORT=3000 |
There was a problem hiding this comment.
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.
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 |
I am in favor of using a |
@anshgoyalevil i can write a windows powershell script which mimics the same make file which i wrote , |
PR Title:
feat: Add Makefile for streamlined development environment setup
Description:
Makefile
to automate Docker-related commands, simplifying the setup process for contributors.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.Related issue(s):
Resolves #3416
Summary by CodeRabbit
Makefile
to simplify the build and execution process for the Dockerizedasyncapi-website
application.These changes enhance user experience by streamlining application management.