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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Makefile

APP_NAME=asyncapi-website
CONTAINER_NAME=asyncapi-website-container
PORT=3000
Comment on lines +3 to +5
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


# Build, Run, and Show Logs
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)
Comment on lines +8 to +18
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.


# Clean Docker Images
clean:
@echo "Cleaning up Docker images..."
@docker rmi $(APP_NAME) || true
@docker system prune -f || true
Loading