diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 076bb42..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,30 +0,0 @@
-FROM php:8.3-apache
-
-# Install dependencies and PHP extensions
-RUN apt-get update && apt-get install -y \
- libpq-dev \
- curl \
- git \
- libzip-dev \
- && curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
- && apt-get install -y nodejs \
- && docker-php-ext-install pdo pdo_pgsql pcntl zip
-
-# Enable Apache mod_rewrite
-RUN a2enmod rewrite
-
-# Set working directory
-WORKDIR /var/www/html
-
-# Copy only package files, install node deps (faster caches)
-COPY package*.json ./
-RUN npm ci --unsafe-perm
-
-# Make git accept repo path (prevents dubious ownership)
-RUN git config --global --add safe.directory /var/www/html
-
-# Now copy app code
-COPY . .
-
-# Install composer
-COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
\ No newline at end of file
diff --git a/README.md b/README.md
index 6200be9..b8f0fc7 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
Clone the repo.
-### 1a. Docker (Recommended)
+### 1a. Laravel Sail / Docker (Recommended)
It's recommended to use Docker to set up the development environment. It's literally one command:
@@ -12,48 +12,38 @@ It's recommended to use Docker to set up the development environment. It's liter
docker compose up -d
```
-From this point onward, run all shell commands inside the `ewaste-backend-laravel-1` container. The easiest way to do this is through your IDE's Docker extension, but the manual way is:
+From this point onward, run all shell commands with the `./vendor/bin/sail` prefix so they get run inside the container. You might want to set up a shell alias in `~/.bashrc` to remove the relative path:
```bash
-docker exec -it ewaste-backend-laravel-1 /bin/bash
+alias sail='./vendor/bin/sail '
```
### 1b. Manual
-Alternatively, you can install PHP 8 (with the relevant extensions), PHP Composer, and Postgres on your system, then go into this directory and run:
+Alternatively, you can install PHP 8 (with the [relevant extensions](https://stackoverflow.com/questions/40815984/how-to-install-all-required-php-extensions-for-laravel)), PHP Composer, and Postgres on your system, then go into this directory and run:
```bash
composer install
```
+Don't use the `sail` prefix if you install it this way.
+
### 2. Migrations
Apply all migrations to the database:
```bash
-php artisan migrate
+sail php artisan migrate
```
**Note:** this step has to be redone every time a new database migration is written.
### 3. Generate key
-Your .env should look something like this prior to running the command:
-
-```
-DB_CONNECTION=pgsql
-DB_HOST=db
-DB_PORT=5432
-DB_DATABASE=laravel
-DB_USERNAME=laravel
-DB_PASSWORD=secret
-APP_KEY=
-```
-
-Generate Artisan key necessary for accessing endpoint:
+Copy the `.env.example` file to `.env`. Generate the application encryption key:
```bash
-exec laravel php artisan key:generate
+sail php artisan key:generate
```
## Development
@@ -61,24 +51,18 @@ exec laravel php artisan key:generate
### Dev Server
-To start the Laravel dev server, run this *inside* the Docker container:
+Start the Laravel dev server with this command:
```bash
-composer run dev
+sail php artisan serve --host=0.0.0.0
```
-Then you can go to http://localhost:8000 in your browser, like it says. The site will live update any time you make changes.
+Then you can go to http://localhost/ in your browser (if using Sail) or http://localhost:8000/ (for manual installs). The site will live update any time you make changes.
### Changing Docker Configs
-If you change the Dockerfile, run this *outside* the Docker container:
-
-```bash
-docker compose up --build -d
-```
-
-If you change the docker-compose.yml file, run this *outside* the Docker container:
+If you change the compose.yml file, run this in your shell (not with Sail):
```bash
docker compose restart
-```
\ No newline at end of file
+```
diff --git a/compose.yaml b/compose.yaml
new file mode 100644
index 0000000..52ebb1e
--- /dev/null
+++ b/compose.yaml
@@ -0,0 +1,56 @@
+services:
+ laravel.test:
+ build:
+ context: ./vendor/laravel/sail/runtimes/8.4
+ dockerfile: Dockerfile
+ args:
+ WWWGROUP: '${WWWGROUP}'
+ image: sail-8.4/app
+ extra_hosts:
+ - 'host.docker.internal:host-gateway'
+ ports:
+ - '${APP_PORT:-80}:80'
+ - '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
+ environment:
+ WWWUSER: '${WWWUSER}'
+ LARAVEL_SAIL: 1
+ XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
+ XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
+ IGNITION_LOCAL_SITES_PATH: '${PWD}'
+ volumes:
+ - '.:/var/www/html'
+ networks:
+ - sail
+ depends_on:
+ - pgsql
+ pgsql:
+ image: 'postgres:18-alpine'
+ ports:
+ - '${FORWARD_DB_PORT:-5432}:5432'
+ environment:
+ PGPASSWORD: '${DB_PASSWORD:-secret}'
+ POSTGRES_DB: '${DB_DATABASE}'
+ POSTGRES_USER: '${DB_USERNAME}'
+ POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
+ volumes:
+ - 'sail-pgsql:/var/lib/postgresql/data'
+ - './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql'
+ networks:
+ - sail
+ healthcheck:
+ test:
+ - CMD
+ - pg_isready
+ - '-q'
+ - '-d'
+ - '${DB_DATABASE}'
+ - '-U'
+ - '${DB_USERNAME}'
+ retries: 3
+ timeout: 5s
+networks:
+ sail:
+ driver: bridge
+volumes:
+ sail-pgsql:
+ driver: local
diff --git a/composer.json b/composer.json
index de2977e..15a33d1 100644
--- a/composer.json
+++ b/composer.json
@@ -18,7 +18,7 @@
"laravel/boost": "^1.6",
"laravel/pail": "^1.2.2",
"laravel/pint": "^1.24",
- "laravel/sail": "^1.41",
+ "laravel/sail": "*",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"pestphp/pest": "^4.1",
@@ -89,4 +89,4 @@
},
"minimum-stability": "stable",
"prefer-stable": true
-}
\ No newline at end of file
+}
diff --git a/composer.lock b/composer.lock
index 5ed55ca..d934589 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "f57f42baa39a474eb39dad5682f0748c",
+ "content-hash": "ada8f90ada660db7576ae0f26a2847a7",
"packages": [
{
"name": "brick/math",
diff --git a/docker-compose.yml b/docker-compose.yml
deleted file mode 100644
index 7b7b6e4..0000000
--- a/docker-compose.yml
+++ /dev/null
@@ -1,47 +0,0 @@
-version: '3.8'
-
-services:
- laravel:
- build:
- context: .
- dockerfile: Dockerfile
- volumes:
- - .:/var/www/html
- environment:
- DB_CONNECTION: pgsql
- DB_HOST: db
- DB_PORT: 5432
- DB_DATABASE: laravel
- DB_USERNAME: laravel
- DB_PASSWORD: secret
- ports:
- - "5173:5173"
- - "8000:8000"
- networks:
- - laravel-network
- depends_on:
- db:
- condition: service_healthy
-
- db:
- image: postgres:16
- volumes:
- - postgres_data:/var/lib/postgresql/data
- environment:
- POSTGRES_USER: laravel
- POSTGRES_PASSWORD: secret
- POSTGRES_DB: laravel
- healthcheck:
- test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
- interval: 5s
- timeout: 5s
- retries: 5
- networks:
- - laravel-network
-
-volumes:
- postgres_data:
-
-networks:
- laravel-network:
- driver: bridge
\ No newline at end of file
diff --git a/phpunit.xml b/phpunit.xml
index 30886ad..bbfcf81 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -23,8 +23,7 @@
-
-
+