Fix dev containers + add start script
This commit is contained in:
parent
b517cd40a9
commit
30f4bc6fa6
5 changed files with 91 additions and 35 deletions
1
backend/.gitignore
vendored
1
backend/.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
||||||
/composer.lock
|
/composer.lock
|
||||||
|
/.composer
|
||||||
/.phpunit.cache
|
/.phpunit.cache
|
||||||
/node_modules
|
/node_modules
|
||||||
/public/build
|
/public/build
|
||||||
|
|
|
||||||
25
backend/docker-compose.override.yml
Normal file
25
backend/docker-compose.override.yml
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
volumes:
|
||||||
|
- '.:/var/www/html:Z'
|
||||||
|
|
||||||
|
mysql:
|
||||||
|
image: 'docker.io/library/mysql:8.0'
|
||||||
|
environment:
|
||||||
|
MYSQL_USER: '${DB_USERNAME}'
|
||||||
|
MYSQL_PASSWORD: '${DB_PASSWORD}'
|
||||||
|
volumes:
|
||||||
|
- 'sail-mysql:/var/lib/mysql:Z'
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
image: 'docker.io/library/node:22-alpine'
|
||||||
|
working_dir: /app
|
||||||
|
command: sh -c "npm install && npm run dev -- --host"
|
||||||
|
volumes:
|
||||||
|
- '../frontend:/app:Z'
|
||||||
|
ports:
|
||||||
|
- '5173:5173'
|
||||||
|
networks:
|
||||||
|
- sail
|
||||||
|
depends_on:
|
||||||
|
- backend
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
services:
|
services:
|
||||||
laravel.test:
|
backend:
|
||||||
build:
|
build:
|
||||||
context: './vendor/laravel/sail/runtimes/8.4'
|
context: './vendor/laravel/sail/runtimes/8.4'
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
|
@ -18,22 +18,24 @@ services:
|
||||||
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
|
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
|
||||||
IGNITION_LOCAL_SITES_PATH: '${PWD}'
|
IGNITION_LOCAL_SITES_PATH: '${PWD}'
|
||||||
volumes:
|
volumes:
|
||||||
- '.:/var/www/html'
|
- '.:/var/www/html:Z'
|
||||||
networks:
|
networks:
|
||||||
- sail
|
- sail
|
||||||
depends_on:
|
depends_on:
|
||||||
- mysql
|
- mysql
|
||||||
mysql:
|
mysql:
|
||||||
image: 'mysql/mysql-server:8.0'
|
image: 'docker.io/mysql/mysql-server:8.0'
|
||||||
ports:
|
ports:
|
||||||
- '${FORWARD_DB_PORT:-3306}:3306'
|
- '${FORWARD_DB_PORT:-3306}:3306'
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
|
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
|
||||||
MYSQL_ROOT_HOST: '%'
|
MYSQL_ROOT_HOST: '%'
|
||||||
MYSQL_DATABASE: '${DB_DATABASE}'
|
MYSQL_DATABASE: '${DB_DATABASE}'
|
||||||
|
MYSQL_USER: '${DB_USERNAME}'
|
||||||
|
MYSQL_PASSWORD: '${DB_PASSWORD}'
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: 1
|
MYSQL_ALLOW_EMPTY_PASSWORD: 1
|
||||||
volumes:
|
volumes:
|
||||||
- 'sail-mysql:/var/lib/mysql'
|
- 'sail-mysql:/var/lib/mysql:Z'
|
||||||
networks:
|
networks:
|
||||||
- sail
|
- sail
|
||||||
healthcheck:
|
healthcheck:
|
||||||
|
|
|
||||||
|
|
@ -79,36 +79,65 @@ else
|
||||||
echo -e "${GREEN}✓ Backend dependencies already installed${NC}\n"
|
echo -e "${GREEN}✓ Backend dependencies already installed${NC}\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fix docker-compose.yml for Podman (needs full registry paths)
|
# Check if database volume exists - if not, we're doing fresh initialization
|
||||||
if [ "$CONTAINER_CLI" = "podman" ]; then
|
FRESH_DB=false
|
||||||
echo -e "${YELLOW}Patching docker-compose.yml for Podman compatibility...${NC}"
|
if ! $CONTAINER_CLI volume inspect sail-mysql &>/dev/null && ! $CONTAINER_CLI volume inspect backend_sail-mysql &>/dev/null; then
|
||||||
sed -i "s|image: 'mysql/mysql-server:|image: 'docker.io/mysql/mysql-server:|g" docker-compose.yml
|
FRESH_DB=true
|
||||||
|
echo -e "${YELLOW}Fresh database initialization detected${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start Laravel Sail (database + backend services)
|
# Start containers using compose directly (docker-compose.override.yml is automatically used)
|
||||||
echo -e "${YELLOW}Starting Laravel Sail containers...${NC}"
|
echo -e "${YELLOW}Starting backend containers...${NC}"
|
||||||
if ./vendor/bin/sail up -d 2>&1 | tee /tmp/sail-up.log; then
|
if $CONTAINER_CLI compose up -d 2>&1 | tee /tmp/compose-up.log; then
|
||||||
echo -e "${GREEN}✓ Containers started${NC}\n"
|
echo -e "${GREEN}✓ Containers started${NC}\n"
|
||||||
else
|
else
|
||||||
echo -e "${RED}✗ Failed to start containers. Check /tmp/sail-up.log for details${NC}"
|
echo -e "${RED}✗ Failed to start containers. Check /tmp/compose-up.log for details${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Wait for database to be ready
|
# Wait for database to be ready
|
||||||
echo -e "${YELLOW}Waiting for database to be ready...${NC}"
|
echo -e "${YELLOW}Waiting for database to be ready...${NC}"
|
||||||
sleep 5
|
MAX_ATTEMPTS=30
|
||||||
|
ATTEMPT=0
|
||||||
|
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
|
||||||
|
if $CONTAINER_CLI compose exec mysql mysqladmin ping -h localhost --silent 2>/dev/null; then
|
||||||
|
echo -e "${GREEN}✓ Database is ready${NC}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
ATTEMPT=$((ATTEMPT + 1))
|
||||||
|
echo -e "${YELLOW}Waiting for database... (attempt $ATTEMPT/$MAX_ATTEMPTS)${NC}"
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
|
||||||
|
echo -e "${RED}✗ Database failed to become ready${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Give MySQL extra time on fresh initialization to create users
|
||||||
|
if [ "$FRESH_DB" = true ]; then
|
||||||
|
echo -e "${YELLOW}Waiting for fresh database to complete initialization...${NC}"
|
||||||
|
sleep 10
|
||||||
|
else
|
||||||
|
sleep 3
|
||||||
|
fi
|
||||||
|
|
||||||
# Run migrations
|
# Run migrations
|
||||||
echo -e "${YELLOW}Running database migrations...${NC}"
|
echo -e "${YELLOW}Running database migrations...${NC}"
|
||||||
./vendor/bin/sail artisan migrate --force
|
$CONTAINER_CLI compose exec backend php artisan migrate --force
|
||||||
|
|
||||||
# Check if database has data
|
# Check if database has data
|
||||||
TABLE_COUNT=$(./vendor/bin/sail artisan tinker --execute="echo \DB::table('users')->count();")
|
echo -e "${YELLOW}Checking if database needs seeding...${NC}"
|
||||||
|
TABLE_COUNT=$($CONTAINER_CLI compose exec backend php artisan tinker --execute="echo \DB::table('users')->count();" 2>/dev/null | tail -1 | tr -d '[:space:]' || echo "0")
|
||||||
|
# Default to 0 if not a number
|
||||||
|
if ! [[ "$TABLE_COUNT" =~ ^[0-9]+$ ]]; then
|
||||||
|
TABLE_COUNT=0
|
||||||
|
fi
|
||||||
if [ "$TABLE_COUNT" -eq "0" ]; then
|
if [ "$TABLE_COUNT" -eq "0" ]; then
|
||||||
echo -e "${YELLOW}Database is empty. Run seeders? (y/n)${NC}"
|
echo -e "${YELLOW}Database is empty. Run seeders? (y/n)${NC}"
|
||||||
read -r response
|
read -r response
|
||||||
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
|
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
|
||||||
./vendor/bin/sail artisan db:seed
|
$CONTAINER_CLI compose exec backend php artisan db:seed
|
||||||
echo -e "${GREEN}✓ Database seeded${NC}\n"
|
echo -e "${GREEN}✓ Database seeded${NC}\n"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
@ -116,28 +145,15 @@ fi
|
||||||
echo -e "${GREEN}✓ Backend setup complete${NC}"
|
echo -e "${GREEN}✓ Backend setup complete${NC}"
|
||||||
echo -e "${GREEN}Backend API running at: http://localhost:8000${NC}\n"
|
echo -e "${GREEN}Backend API running at: http://localhost:8000${NC}\n"
|
||||||
|
|
||||||
# Frontend setup
|
|
||||||
echo -e "${GREEN}=== Frontend Setup ===${NC}"
|
|
||||||
cd "$PROJECT_ROOT/frontend"
|
|
||||||
|
|
||||||
if [ ! -d "node_modules" ]; then
|
|
||||||
echo -e "${YELLOW}Installing frontend dependencies (npm)...${NC}"
|
|
||||||
npm install
|
|
||||||
echo -e "${GREEN}✓ Frontend dependencies installed${NC}\n"
|
|
||||||
else
|
|
||||||
echo -e "${GREEN}✓ Frontend dependencies already installed${NC}\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "${GREEN}✓ Frontend setup complete${NC}\n"
|
|
||||||
|
|
||||||
# Display summary
|
# Display summary
|
||||||
echo -e "${GREEN}=== Development Environment Ready ===${NC}"
|
echo -e "${GREEN}=== Development Environment Ready ===${NC}"
|
||||||
echo -e "${GREEN}Backend API:${NC} http://localhost:8000"
|
echo -e "${GREEN}Backend API:${NC} http://localhost:8000"
|
||||||
echo -e "${GREEN}Frontend:${NC} http://localhost:5173 (start with: cd frontend && npm run dev)"
|
echo -e "${GREEN}Frontend:${NC} http://localhost:5173"
|
||||||
echo -e "${GREEN}Database:${NC} MySQL on localhost:3306"
|
echo -e "${GREEN}Database:${NC} MySQL on localhost:3306"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
echo -e "${YELLOW}To start the frontend dev server, run:${NC}"
|
echo -e "${YELLOW}Note:${NC} Frontend container will install dependencies and start automatically."
|
||||||
echo -e " cd frontend && npm run dev"
|
echo -e "${YELLOW}To view frontend logs:${NC}"
|
||||||
|
echo -e " cd backend && $CONTAINER_CLI compose logs -f frontend"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
echo -e "${YELLOW}To stop backend services:${NC}"
|
echo -e "${YELLOW}To stop all services:${NC}"
|
||||||
echo -e " cd backend && ./vendor/bin/sail down"
|
echo -e " cd backend && $CONTAINER_CLI compose down"
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,16 @@ import tsconfigPaths from "vite-tsconfig-paths";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
|
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
"/api": {
|
||||||
|
target: "http://localhost:8000",
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
"/sanctum": {
|
||||||
|
target: "http://localhost:8000",
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue