Skip to content

Commit e4532f4

Browse files
committed
refactor(base.mk): enhance make run command for improved user interaction
Added a provisional enhancement to the `run` target in base.mk to improve the user experience before modularizing the Docker run commands into separate functions. Now the user is notified about the container's idle state and connection details before proceeding. This sets the foundation for future improvements.
1 parent 1b90cfd commit e4532f4

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

example/base.mk

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,41 @@ clean:
8787
# and restart biospring or tune certain parameters from UnityMol during
8888
# an interactive simulation (for example IMPALA scale or Input Force, or
8989
# even viscosity).
90-
run :
91-
@echo "Run BioSpring"
92-
docker run -p 8888:8888 --rm --init -v $(PWD):/data $(IMAGE) \
93-
$(BIOSPRING) -s $(NC) \
94-
-c $(MSP) \
95-
--wait --port 8888 \
96-
--sasa-classifier biospring
90+
run:
91+
@echo "Starting BioSpring in detached mode..."
92+
@CONTAINER_ID=$$(docker run -d --rm -p 8888:8888 --name biospring-container --init -v $(PWD):/data $(IMAGE) $(BIOSPRING) -s $(NC) -c $(MSP) --wait --port 8888 --sasa-classifier biospring); \
93+
if [ -z "$$CONTAINER_ID" ]; then \
94+
echo "$(RED)❌ Failed to start the container.$(RESET)"; \
95+
exit 1; \
96+
fi; \
97+
HOSTNAME=$$(hostname); \
98+
echo "$(GREEN)✅ BioSpring container started successfully!$(RESET)"; \
99+
echo ""; \
100+
echo "$(YELLOW)⚠️ Before continuing, please note that the BioSpring program is running in idle mode within the container, waiting for a connection. By proceeding, we will reattach to the container and display BioSpring's logs in real-time. Afterward, you can use the following information to connect:$(RESET)"; \
101+
echo ""; \
102+
echo " - On the local machine: $(GREEN)localhost:8888$(RESET) or $(GREEN)127.0.0.1:8888$(RESET)"; \
103+
echo " - On the network: $(GREEN)$$HOSTNAME:8888$(RESET)"; \
104+
trap 'docker ps -q --filter "id=$$CONTAINER_ID" | grep -q . && docker stop $$CONTAINER_ID || true; \
105+
echo "$(YELLOW)⚠️ Program interrupted manually (SIGINT/SIGTERM).$(RESET)"; exit 130' INT TERM; \
106+
while true; do \
107+
read -p "🟢 Continue (c) or Kill the container (k)? " choice; \
108+
case $$choice in \
109+
[cC]) \
110+
echo "$(GREEN)Showing logs and attaching to the container...$(RESET)"; \
111+
docker logs -f $$CONTAINER_ID & \
112+
DOCKER_LOGS_PID=$$!; \
113+
docker attach $$CONTAINER_ID; \
114+
break;; \
115+
[kK]) \
116+
echo "$(RED)Killing the container...$(RESET)"; \
117+
if docker ps -q --filter "id=$$CONTAINER_ID" | grep -q .; then \
118+
docker stop $$CONTAINER_ID; \
119+
fi; \
120+
exit 0;; \
121+
*) \
122+
echo "$(YELLOW)Invalid input. Enter 'c' to continue or 'k' to kill.$(RESET)";; \
123+
esac; \
124+
done
97125

98126
# Run the BioSpring simulation without waiting for the connection
99127
run_now:
@@ -156,4 +184,4 @@ usage:
156184
@echo "Step 5: Server side"
157185
@echo " CTRL + C to stop the server running the simulation"
158186
@echo " make clean"
159-
@echo "------------------------------------------------------------------------------"
187+
@echo "------------------------------------------------------------------------------"

0 commit comments

Comments
 (0)