Skip to content

Commit

Permalink
Merge pull request #26 from YuriiDorosh/features/scripts
Browse files Browse the repository at this point in the history
Features/scripts
  • Loading branch information
YuriiDorosh committed Mar 9, 2024
2 parents 74d555a + 22f26b7 commit 24ee1e9
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,31 @@ nginx_docker_restart:

# Connect to the Nginx container
nginx_shell:
docker-compose exec nginx sh
docker-compose exec nginx sh

# Scripts Commands
#-------------------------------------------------

# Start the project with optional environment argument (e.g., make start_project ENV=production)
start_project:
./scripts/start_project.sh $(ENV)

# Stop the project
stop_project:
./scripts/stop_project.sh

# Restart the project
restart_project:
./scripts/restart_project.sh

# Run migrations
migrate:
./scripts/run_migrations.sh

# Run seeders (use SEEDER=seeder_name to specify a seeder)
seed:
./scripts/run_seed.sh $(SEEDER)

# Clear Redis cache with confirmation
clear_cache:
./scripts/clear_cache.sh
3 changes: 3 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```bash
chmod +x *.sh
```
15 changes: 15 additions & 0 deletions scripts/check_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Check for Docker
if ! command -v docker &> /dev/null; then
echo "Docker could not be found. Please install Docker."
exit 1
fi

# Check for Docker Compose
if ! command -v docker-compose &> /dev/null; then
echo "Docker Compose could not be found. Please install Docker Compose."
exit 1
fi

echo "Docker and Docker Compose are installed."
10 changes: 10 additions & 0 deletions scripts/clear_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

read -p "Are you sure you want to clear the Redis cache? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
docker-compose exec redis redis-cli FLUSHALL
echo "Redis cache cleared."
else
echo "Operation cancelled."
fi
4 changes: 4 additions & 0 deletions scripts/run_migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Running migrations..."
docker-compose exec app php spark migrate
11 changes: 11 additions & 0 deletions scripts/run_seed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

SEEDER=${1:-} # Optional seeder name as first argument

if [ -z "$SEEDER" ]; then
echo "Running all seeders..."
docker-compose exec app php spark db:seed
else
echo "Running seeder: $SEEDER"
docker-compose exec app php spark db:seed $SEEDER
fi
10 changes: 10 additions & 0 deletions scripts/start_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Load Environment or use default
ENVIRONMENT=${1:-development}

# Check Docker and Docker Compose availability
./scripts/check_docker.sh || exit 1

echo "Starting project in $ENVIRONMENT mode..."
docker-compose -f docker-compose.yml -f docker-compose.$ENVIRONMENT.yml up -d

0 comments on commit 24ee1e9

Please sign in to comment.