diff --git a/compose.yml b/compose.yml index 73d0a0b..af88c53 100644 --- a/compose.yml +++ b/compose.yml @@ -18,7 +18,7 @@ volumes: services: midnight-node-testnet: - container_name: midnight + container_name: midnight-node restart: unless-stopped image: ${MIDNIGHT_NODE_IMAGE} ports: diff --git a/midnight-node.sh b/midnight-node.sh index e2648d0..cbcfda6 100755 --- a/midnight-node.sh +++ b/midnight-node.sh @@ -6,4 +6,4 @@ if [ -z "$MIDNIGHT_NODE_IMAGE" ]; then exit 1 fi -docker exec -t midnight /midnight-node "$@" +docker exec -t midnight /midnight-node "$@" \ No newline at end of file diff --git a/midnight-shell.sh b/midnight-shell.sh index 20fa48d..8f98f8b 100755 --- a/midnight-shell.sh +++ b/midnight-shell.sh @@ -1,11 +1,30 @@ #!/usr/bin/env bash -# -# This will mount the ./data dir and allow you to run a series of midnight commands -# -# To register an SPO: -# -# ./midnight-node wizards generate-keys -# ./midnight-node wizards register1 USE Ogmios hostname: host.docker.internal -# -docker exec -it midnight bash +# Define container name +CONTAINER_NAME="midnight" + +# Check if the container already exists +if [ $(docker ps -a -f name=^${CONTAINER_NAME}$ --format '{{.Names}}' | grep -w ${CONTAINER_NAME} | wc -l) -eq 0 ]; then + echo "Container '${CONTAINER_NAME}' does not exist. Creating and starting it..." + + # Run the container with the specified configuration + docker run -it \ + --name ${CONTAINER_NAME} \ + -e CFG_PRESET="${CFG_PRESET}" \ + -e DB_SYNC_POSTGRES_CONNECTION_STRING="${DB_SYNC_POSTGRES_CONNECTION_STRING}" \ + -v ./data:/data \ + -v "./envs/${CFG_PRESET}/pc-chain-config.json:/pc-chain-config.json" \ + --entrypoint bash \ + "${MIDNIGHT_NODE_IMAGE}" +else + echo "Container '${CONTAINER_NAME}' already exists. Opening an interactive shell..." + + # Check if the container is running, if not, start it + if [ $(docker ps -f name=^${CONTAINER_NAME}$ --format '{{.Names}}' | grep -w ${CONTAINER_NAME} | wc -l) -eq 0 ]; then + echo "Starting container '${CONTAINER_NAME}'..." + docker start ${CONTAINER_NAME} + fi + + # Open an interactive shell in the container + docker exec -it ${CONTAINER_NAME} /bin/bash +fi \ No newline at end of file