Use firstOrCreate instead of create so db:seed can run safely on container restart without duplicate key violation.
123 lines
3.5 KiB
Markdown
123 lines
3.5 KiB
Markdown
# Deployment & Infrastructure
|
|
|
|
## Prerequisites
|
|
|
|
- Docker ^19.*
|
|
- Docker Compose
|
|
- Make (optional, for Makefile commands)
|
|
|
|
## Environment Configuration
|
|
|
|
### Root `.env` (Docker-level)
|
|
|
|
Located at `/root/sides/tckdev/.env`:
|
|
|
|
```
|
|
POSTGRES_DB="tckdev"
|
|
POSTGRES_USER="tck"
|
|
POSTGRES_PASSWORD="projectdev##1"
|
|
PGADMIN_EMAIL="tck68000@gmail.com"
|
|
PGADMIN_PASSWORD="projectdev##1"
|
|
```
|
|
|
|
### Application `.env` (Laravel-level)
|
|
|
|
Located at `/root/sides/tckdev/src/.env`:
|
|
|
|
Key configuration:
|
|
- `APP_URL=https://sides.tck.com.my`
|
|
- `DB_CONNECTION=pgsql` → `DB_HOST=192.168.0.211` (direct IP, not Docker service name)
|
|
- `SESSION_DRIVER=database`
|
|
- `CACHE_STORE=database`
|
|
- `QUEUE_CONNECTION=database`
|
|
- `MAIL_MAILER=smtp` via Gmail SMTP (`sideskupang@gmail.com`)
|
|
- Firebase FCM credentials at `storage/app/firebase/sides-b4abb-3604a7cf7584.json`
|
|
|
|
## Initial Setup
|
|
|
|
### From Scratch (New Project)
|
|
|
|
```bash
|
|
make create-project
|
|
```
|
|
|
|
This runs:
|
|
1. Creates `src/` directory
|
|
2. Builds Docker images
|
|
3. Starts containers
|
|
4. Runs `composer create-project laravel/laravel .`
|
|
5. Generates application key
|
|
6. Creates storage link
|
|
7. Sets permissions
|
|
8. Installs npm dependencies
|
|
|
|
### From Existing Code (Clone)
|
|
|
|
```bash
|
|
make init
|
|
```
|
|
|
|
This runs:
|
|
1. Builds and starts containers
|
|
2. `composer install`
|
|
3. Copies `.env.example` to `.env`
|
|
4. Generates application key
|
|
5. Creates storage link
|
|
6. Sets permissions
|
|
7. `npm install`
|
|
8. `php artisan migrate:fresh --seed`
|
|
|
|
## Makefile Commands Reference
|
|
|
|
| Command | Description |
|
|
|---------|-------------|
|
|
| `make up` | Start containers (detached) |
|
|
| `make down` | Stop containers, remove orphans |
|
|
| `make down-v` | Stop containers, remove volumes |
|
|
| `make build` | Build Docker images |
|
|
| `make remake` | Full destroy + reinit |
|
|
| `make destroy` | Remove all containers, images, volumes |
|
|
| `make stop` | Stop containers |
|
|
| `make restart` | Down + up |
|
|
| `make ps` | Show container status |
|
|
| `make logs` | Show all container logs |
|
|
| `make logs-watch` | Follow all logs |
|
|
| `make log-app` | Show app container logs |
|
|
| `make log-db` | Show database logs |
|
|
| `make app` | Shell into app container |
|
|
| `make web` | Shell into web container |
|
|
| `make migrate` | Run migrations |
|
|
| `make fresh` | Fresh migration with seed |
|
|
| `make seed` | Run seeders |
|
|
| `make tinker` | Open Laravel tinker |
|
|
| `make test` | Run PHPUnit tests |
|
|
| `make cache` | Optimize autoload + cache |
|
|
| `make cache-clear` | Clear all caches |
|
|
|
|
## Access Points
|
|
|
|
| Service | URL |
|
|
|---------|-----|
|
|
| Application | http://localhost:80 |
|
|
| pgAdmin | http://localhost:5050 |
|
|
| Adminer | http://localhost:6060 |
|
|
| PostgreSQL | localhost:5432 |
|
|
|
|
## Database Connection Discrepancy
|
|
|
|
**Important**: The `docker-compose.yml` defines a `postgres` service, but `src/.env` connects to `192.168.0.211` — an external PostgreSQL host, not the Docker container. This means:
|
|
|
|
- In **development/local**: The app may connect to an external database instead of the Docker postgres container
|
|
- The Docker postgres service is still available at `postgres:5432` for inter-container communication
|
|
- The Python autoscript also connects to `192.168.0.211` directly
|
|
|
|
To use the Docker PostgreSQL, change `DB_HOST=postgres` in `src/.env`.
|
|
|
|
## Production Notes
|
|
|
|
- `APP_DEBUG=true` is set in `.env` — should be `false` in production
|
|
- `URL::forceScheme('https')` is enabled globally in `AppServiceProvider`
|
|
- The app URL is `https://sides.tck.com.my`
|
|
- Gmail SMTP is used for password reset emails
|
|
- Firebase credentials JSON file is stored in `storage/app/firebase/`
|