Skip to content

Commit

Permalink
feat: helper function with docker cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
  • Loading branch information
smuu committed Dec 18, 2024
1 parent e90f3af commit eb5505d
Showing 1 changed file with 10 additions and 35 deletions.
45 changes: 10 additions & 35 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
# Define the path to your docker-compose.yml file
DOCKER_COMPOSE_FILE := "ci/docker-compose.yml"

# Helper function to use correct docker compose command
docker_compose_cmd := if `uname -s` == "Linux" { "docker compose" } else { "docker-compose" }

celestia-up:
#!/usr/bin/env bash
set -euo pipefail
echo "Cleaning up any existing Docker resources..."
if [ "$(uname -s)" = "Linux" ]; then \
docker compose -f {{DOCKER_COMPOSE_FILE}} down -v --remove-orphans; \
else \
docker-compose -f {{DOCKER_COMPOSE_FILE}} down -v --remove-orphans; \
fi
{{docker_compose_cmd}} -f {{DOCKER_COMPOSE_FILE}} down -v --remove-orphans

echo "Building Docker images..."
if [ "$(uname -s)" = "Linux" ]; then \
docker compose -f {{DOCKER_COMPOSE_FILE}} build; \
else \
docker-compose -f {{DOCKER_COMPOSE_FILE}} build; \
fi
{{docker_compose_cmd}} -f {{DOCKER_COMPOSE_FILE}} build

echo "Spinning up a fresh Docker Compose stack..."
if [ "$(uname -s)" = "Linux" ]; then \
docker compose -f {{DOCKER_COMPOSE_FILE}} up -d --force-recreate --renew-anon-volumes; \
else \
docker-compose -f {{DOCKER_COMPOSE_FILE}} up -d --force-recreate --renew-anon-volumes; \
fi
{{docker_compose_cmd}} -f {{DOCKER_COMPOSE_FILE}} up -d --force-recreate --renew-anon-volumes

echo "Waiting for services to be ready..."
timeout=120
Expand All @@ -33,11 +24,7 @@ celestia-up:
bridge_node_ready=false

while true; do
if [ "$(uname -s)" = "Linux" ]; then \
logs=$(docker compose -f {{DOCKER_COMPOSE_FILE}} logs); \
else \
logs=$(docker-compose -f {{DOCKER_COMPOSE_FILE}} logs); \
fi
logs=$( {{docker_compose_cmd}} -f {{DOCKER_COMPOSE_FILE}} logs )

if [[ $logs == *"Configuration finished. Running a light node"* ]]; then
light_node_ready=true
Expand All @@ -59,11 +46,7 @@ celestia-up:

if [ $elapsed -ge $timeout ]; then
echo "Timeout waiting for services to be ready. Check the logs for more information."
if [ "$(uname -s)" = "Linux" ]; then \
docker compose -f {{DOCKER_COMPOSE_FILE}} logs; \
else \
docker-compose -f {{DOCKER_COMPOSE_FILE}} logs; \
fi
{{docker_compose_cmd}} -f {{DOCKER_COMPOSE_FILE}} logs
exit 1
fi

Expand All @@ -74,18 +57,10 @@ celestia-up:
echo "Celestia stack is up and running!"

celestia-down:
if [ "$(uname -s)" = "Linux" ]; then \
docker compose -f {{DOCKER_COMPOSE_FILE}} down -v --remove-orphans; \
else \
docker-compose -f {{DOCKER_COMPOSE_FILE}} down -v --remove-orphans; \
fi
{{docker_compose_cmd}} -f {{DOCKER_COMPOSE_FILE}} down -v --remove-orphans

celestia-logs:
if [ "$(uname -s)" = "Linux" ]; then \
docker compose -f {{DOCKER_COMPOSE_FILE}} logs -f; \
else \
docker-compose -f {{DOCKER_COMPOSE_FILE}} logs -f; \
fi
{{docker_compose_cmd}} -f {{DOCKER_COMPOSE_FILE}} logs -f

# Command to run integration tests with a fresh Docker setup
integration-test:
Expand Down

0 comments on commit eb5505d

Please sign in to comment.