From 9decf24fa8e15060f05ef95ab45b2e13bd9567d5 Mon Sep 17 00:00:00 2001 From: DJ Carpenter <59489977+djcarpe@users.noreply.github.com> Date: Fri, 23 Feb 2024 09:06:40 -0600 Subject: [PATCH] fix - update hacker-news-headlines.gpt Enable re-running by checking for the mongodb container and either starting it or running it. Signed-off-by: DJ Carpenter <59489977+djcarpe@users.noreply.github.com> --- examples/hacker-news-headlines.gpt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/examples/hacker-news-headlines.gpt b/examples/hacker-news-headlines.gpt index 97878e13..7955371b 100644 --- a/examples/hacker-news-headlines.gpt +++ b/examples/hacker-news-headlines.gpt @@ -16,7 +16,24 @@ description: starts a MongoDB database #!/usr/bin/env bash -docker run --rm -d -p 27017:27017 --name mongodb mongo:latest +# The name of your container +CONTAINER_NAME=mongodb + +# Check if the container already exists +if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then + echo "Container ${CONTAINER_NAME} exists." + + # Check if the container is already running + if ! docker ps --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then + echo "Starting existing container ${CONTAINER_NAME}." + docker start ${CONTAINER_NAME} + else + echo "Container ${CONTAINER_NAME} is already running." + fi +else + echo "Container ${CONTAINER_NAME} does not exist. Running a new one." + docker run --rm -d -p 27017:27017 --name ${CONTAINER_NAME} mongo:latest +fi --- name: mongo_command