Fix dev containers + add start script

This commit is contained in:
myrmidex 2025-10-14 17:25:09 +02:00
parent b517cd40a9
commit 30f4bc6fa6
5 changed files with 91 additions and 35 deletions

1
backend/.gitignore vendored
View file

@ -1,4 +1,5 @@
/composer.lock
/.composer
/.phpunit.cache
/node_modules
/public/build

View 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

View file

@ -1,5 +1,5 @@
services:
laravel.test:
backend:
build:
context: './vendor/laravel/sail/runtimes/8.4'
dockerfile: Dockerfile
@ -18,22 +18,24 @@ services:
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
IGNITION_LOCAL_SITES_PATH: '${PWD}'
volumes:
- '.:/var/www/html'
- '.:/var/www/html:Z'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql/mysql-server:8.0'
image: 'docker.io/mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- 'sail-mysql:/var/lib/mysql:Z'
networks:
- sail
healthcheck:

View file

@ -79,36 +79,65 @@ else
echo -e "${GREEN}✓ Backend dependencies already installed${NC}\n"
fi
# Fix docker-compose.yml for Podman (needs full registry paths)
if [ "$CONTAINER_CLI" = "podman" ]; then
echo -e "${YELLOW}Patching docker-compose.yml for Podman compatibility...${NC}"
sed -i "s|image: 'mysql/mysql-server:|image: 'docker.io/mysql/mysql-server:|g" docker-compose.yml
# Check if database volume exists - if not, we're doing fresh initialization
FRESH_DB=false
if ! $CONTAINER_CLI volume inspect sail-mysql &>/dev/null && ! $CONTAINER_CLI volume inspect backend_sail-mysql &>/dev/null; then
FRESH_DB=true
echo -e "${YELLOW}Fresh database initialization detected${NC}"
fi
# Start Laravel Sail (database + backend services)
echo -e "${YELLOW}Starting Laravel Sail containers...${NC}"
if ./vendor/bin/sail up -d 2>&1 | tee /tmp/sail-up.log; then
# Start containers using compose directly (docker-compose.override.yml is automatically used)
echo -e "${YELLOW}Starting backend containers...${NC}"
if $CONTAINER_CLI compose up -d 2>&1 | tee /tmp/compose-up.log; then
echo -e "${GREEN}✓ Containers started${NC}\n"
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
fi
# Wait for database to be ready
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
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
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
echo -e "${YELLOW}Database is empty. Run seeders? (y/n)${NC}"
read -r response
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"
fi
fi
@ -116,28 +145,15 @@ fi
echo -e "${GREEN}✓ Backend setup complete${NC}"
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
echo -e "${GREEN}=== Development Environment Ready ===${NC}"
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 ""
echo -e "${YELLOW}To start the frontend dev server, run:${NC}"
echo -e " cd frontend && npm run dev"
echo -e "${YELLOW}Note:${NC} Frontend container will install dependencies and start automatically."
echo -e "${YELLOW}To view frontend logs:${NC}"
echo -e " cd backend && $CONTAINER_CLI compose logs -f frontend"
echo -e ""
echo -e "${YELLOW}To stop backend services:${NC}"
echo -e " cd backend && ./vendor/bin/sail down"
echo -e "${YELLOW}To stop all services:${NC}"
echo -e " cd backend && $CONTAINER_CLI compose down"

View file

@ -5,4 +5,16 @@ import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig({
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
server: {
proxy: {
"/api": {
target: "http://localhost:8000",
changeOrigin: true,
},
"/sanctum": {
target: "http://localhost:8000",
changeOrigin: true,
},
},
},
});