Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ volumes:

services:
midnight-node-testnet:
container_name: midnight
container_name: midnight-node
restart: unless-stopped
image: ${MIDNIGHT_NODE_IMAGE}
ports:
Expand Down
9 changes: 2 additions & 7 deletions midnight-node.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/usr/bin/env bash

if [ -z "$MIDNIGHT_NODE_IMAGE" ]; then
echo "Error: Env var MIDNIGHT_NODE_IMAGE is not set or is empty"
echo "Please install direnv and run 'direnv allow' to activate it."
exit 1
fi

docker exec -t midnight /midnight-node "$@"
# Docker compose up midnight-node interactively in shell.
docker compose -f compose.yml up
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before midnight-node.sh could be run with arguments. It's going to ignore all arguments with this definition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the previous command it wants the container running...

What if we simply delete midnight-node.sh and just have midnight-shell.sh to simply assist with the registration part, then they can docker compose up midnight node?

Copy link
Copy Markdown
Contributor Author

@stevanlohja stevanlohja Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated midnight-node script

37 changes: 28 additions & 9 deletions midnight-shell.sh
Original file line number Diff line number Diff line change
@@ -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