Skip to content

Commit

Permalink
feat: ✨ Big update (with PHP 8.2, PostgreSQL 16, Node 20, Mailpit), n…
Browse files Browse the repository at this point in the history
…ew Makefile ...
  • Loading branch information
cbouvat committed Nov 27, 2023
1 parent 593d16a commit 8e1c649
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 250 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ supervisord.pid
_ide_helper_models.php
_ide_helper.php
.phpstorm.meta.php
/docker-compose.yml
/docker/pgsql/datas
/docker/mariadb/datas
131 changes: 63 additions & 68 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,96 +1,91 @@
build:
docker-compose -f docker-compose-production.yml build
default: help ## Display help

build-dev:
docker-compose build
artisan: ## Laravel Artisan command add arg="command" to run a specific command (ex: make artisan arg="migrate")
docker compose exec php php artisan $(arg)

composer-install:
docker-compose exec php composer install --optimize-autoloader --no-suggest --no-dev
artisan-migrate: ## Laravel Artisan migrate
docker compose exec php php artisan migrate

composer-install-dev:
docker-compose run --rm php composer install
artisan-migrate-fresh: ## Laravel Artisan migrate:fresh
docker compose exec php php artisan migrate:fresh

composer-update:
docker-compose run --rm php composer update
artisan-migrate-seed: ## Laravel Artisan migrate:fresh --seed
docker compose exec php php artisan migrate:fresh --seed

database-migrate:
docker-compose run --rm php php artisan migrate --force
artisan-key-generate: ## Laravel Artisan key:generate
docker compose exec php php artisan key:generate

database-seed:
docker-compose run --rm php php artisan migrate:fresh --seed

down:
docker-compose exec php php artisan down --refresh=15

ide-helper:
docker-compose run --rm php php artisan ide-helper:eloquent
docker-compose run --rm php php artisan ide-helper:generate
docker-compose run --rm php php artisan ide-helper:meta
docker-compose run --rm php php artisan ide-helper:models --nowrite
artisan-storage:
docker-compose run --rm php php artisan storage:link

git-pull:
git reset --hard
git pull origin main
build: ## Build containers
docker compose build

install: build composer-install laravel-storage
composer: ## Composer command add arg="command" to run a specific command (ex: make composer arg="require laravel/ui")
docker compose run --rm php composer $(arg)

install-dev: build-dev composer-install-dev laravel-storage
composer-install-dev: ## Composer install dev
docker compose run --rm php composer install

laravel-install:
docker-compose run --rm php composer create-project laravel/laravel laravel --prefer-dist
mv README.md README-docker.md
-mv -f ./laravel/* ./laravel/.* ./
-rm -rf ./laravel
composer-install-prod: ## Composer install prod
docker compose run --rm php composer install --optimize-autoloader --no-suggest --no-dev

laravel-cache:
docker-compose exec php php artisan cache:clear
docker-compose exec php php artisan config:cache
docker-compose exec php php artisan event:cache
docker-compose exec php php artisan route:cache
docker-compose exec php php artisan view:cache
composer-update: ## Composer update
docker compose run --rm php composer update

laravel-storage:
docker-compose run --rm php php artisan storage:link
copy-env: ## Copy .env.example to .env
cp .env.example .env

pull:
docker-compose -f docker-compose-production.yml pull
copy-docker-compose-dev: ## Copy docker-compose.dev.yml to docker-compose.yml
cp docker-compose.dev.yml docker-compose.yml

pull-dev:
docker-compose pull
down: ## Stop and remove all containers
docker compose down --remove-orphans
@echo "🛑 Project are stopped and removed"

restart: stop start
eslint: ## Run eslint
docker compose run --rm node npm run eslint

restart-dev: stop-dev start-dev
install: copy-docker-compose-dev upgrade laravel-install copy-env up npm-install artisan-key-generate artisan-storage ## Install Project
@echo "✅ Project is installed and running, edit .env"

start:
docker-compose -f docker-compose-production.yml up -d
git-pull:
git reset --hard
git pull origin --no-rebase

start-dev:
docker-compose up -d
help: ## Display this help
@echo "📖 Project help"
@echo "✍️ Usage: make [command]"
@echo "👉 Available commands open Makefile to see all commands"

stop:
docker-compose -f docker-compose-production.yml down --remove-orphans
laravel-install: ## Install Laravel
docker-compose run --rm php composer create-project laravel/laravel laravel --prefer-dist
mv README.md README-docker.md
-mv -f ./laravel/* ./laravel/.* ./
-rm -rf ./laravel

stop-dev:
docker-compose down --remove-orphans
npm: ## Npm command add arg="command" to run a specific command (ex: make npm arg="install")
docker compose run --rm node npm $(arg)

tinker:
docker-compose exec php php artisan tinker
npm-install: ## Npm install
docker compose run --rm node npm install

test:
docker-compose exec php php artisan config:clear
docker-compose exec php php artisan test
npm-update: ## Npm update
docker compose run --rm node npm update

test-create:
docker-compose run --rm php php artisan make:test $(name)
up: ## Create and start all containers
docker compose up -d
@echo "✅ Project is up and running"

up:
docker-compose exec php php artisan up
upgrade: pull build ## Upgrade containers (pull and build)

update: down git-pull composer-install laravel-cache database-migrate up
upgrade-dev: down copy-docker-compose-dev upgrade up composer-install-dev npm-install ## Upgrade Project with docker-compose.dev.yml

update-dev: down git-pull-dev composer-install-dev database-migrate up
pint: ## Run Laravel Pint
docker compose run --rm php ./vendor/bin/pint

upgrade: stop git-pull pull build composer-install laravel-cache database-migrate start
pull: ## Pull all containers
docker compose pull

upgrade-dev: stop-dev git-pull pull-dev build-dev composer-install-dev database-migrate start-dev
setup-dev: copy-docker-compose-dev copy-env upgrade composer-install-dev npm-install artisan-key-generate artisan-migrate
@echo "✅ Project is installed, edit .env and you can now run 'make up' to start containers"
80 changes: 27 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Docker Laravel

## 🚫 Requirement
## Requirement

- Docker engine 19.03.0+
- Docker Compose 1.27+
- Docker engine
- Docker Compose
- Make

## 🛠 Build with
## Build with

- HTTP server Nginx 1.20
- PHP 8.1
- Node 16
- Database PostgreSQL 14
- HTTP server Nginx 1.25
- PHP 8.2
- Node 20
- PostgreSQL 16 or MariaDB 11

## 📖 Install Laravel
## Install Laravel

Many commands are in `Makefile` file. Example `start`, `stop`, `build` and [many more 👇](#-list-of-commands).
Many commands are in `Makefile` file. Example `up`, `down`, `upgrade` and [many more 👇](#list-of-commands).

- It is not recommended to clone or fork the repository, download a copy of this Git repository
- Run this command `make laravel-install` for install Laravel with Composer
- It is not recommended to clone or fork the repository, download a copy of this Git repository and extract it.
- Run this command `make install` for install Laravel with Composer
- **⚠️ Modify** environnement file `.env` create by Laravel installer with this :

```bash
Expand All @@ -42,15 +42,15 @@ MAIL_FROM_NAME="${APP_NAME}"
- Launch the environment with `make start-dev`
- And enjoy 😊 !

## 🧰 Development environment
## Development environment

This command build container, install composer dependencies.

`make install-dev`
`make install`

Start environment.

`make start-dev`
`make up`

### Development tools

Expand All @@ -75,55 +75,29 @@ For Visual Studio Code, use this configuration in `.vscode/launch.json` file.
}
```

#### Database management tool
#### Database

Adminer equivalent to PHPmyAdmin. All credentials are in `.env` file.
The database is accessible on port `5432` with this parameters :

`http://localhost:8080`
- Host : `localhost`
- Port : `5432`

Use for example [DBeaver](https://dbeaver.io/) for connect to the database.

#### Mail capture

MailHog capture all mails form the application.

`http://localhost:8025`

## 💼 Production environment
## Production environment

### First launch

- **Modify** ⚠️ environnement file `.env` with production parameters
- `make install`
- `make start`

## 📚 List of commands

- `build` : Build docker container
- `build-dev` : Build docker development container
- `composer-install` : Install PHP dependencies with Composer for production
- `composer-install-dev` : Install PHP dependencies with Composer for devellopement
- `composer-update` : Update PHP dependencies
- `database-migrate` : Laravel database migration command
- `database-seed` : Laravel database seeding command
- `down` : Set in maintenance Laravel application
- `ide-helper` : Generate helpers file for IDE (PHPStorm, VS Code ...)
- `git-pull` : Reset stage and git pull
- `install` : Run `build`, `composer-install` `laravel-storage`
- `install-dev` : Run `build-dev`, `composer-install-dev` `laravel-storage`
- `laravel-install` : Install Laravel with Composer
- `laravel-cache` : Generate all cache for Laravel
- `laravel-storage` : Create store link for Laravel
- `pull` : Pull the lastest Docker containers
- `restart` : Restart Docker containers
- `restart-dev` : Restart Docker development containers
- `start` : Start Docker containers
- `start-dev` : Start Docker development containers
- `stop` : Stop Docker containers
- `stop-dev` : Stop Docker development containers
- `tinker` : Run Laravel Tinker
- `test` : Run Laravel unit test
- `test-create name=TestName` : Create run Laravel unit test
- `up` : Set online Laravel application
- `update` : Run `down` `git-pull` `composer-install` `laravel-cache` `database-migrate` `up`
- `update-dev` : Run `down` `git-pull` `composer-install-dev` `database-migrate` `up`
- `upgrade` : Run `stop` `git-pull` `pull` `build` `composer-install` `laravel-cache` `database-migrate` `start`
- `upgrade-dev` : Run `stop` `git-pull` `pull-dev` `build-dev` `composer-install-dev` `database-migrate` `start`
- `make up`

## List of commands

All commands are in `Makefile` file with description. Open this file for more informations.
50 changes: 50 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
services:
php:
build:
context: ./docker/php/
dockerfile: dev.Dockerfile
ports:
- 80:80
volumes:
- ./:/app/
extra_hosts:
- 'host.docker.internal:host-gateway'
depends_on:
- pgsql
node:
image: node:20
ports:
- 5173:5173
volumes:
- ./:/app/
working_dir: /app/
command: "npm run dev"
# mariadb:
# image: mariadb:11
# ports:
# - 3306:3306
# environment:
# MARIADB_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
# MARIADB_DATABASE: "${DB_DATABASE}"
# MARIADB_USER: "${DB_USERNAME}"
# MARIADB_PASSWORD: "${DB_PASSWORD}"
# volumes:
# - ./docker/mariadb/datas:/var/lib/mysql
pgsql:
image: postgres:16
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: '${DB_PASSWORD:-secret}'
POSTGRES_DB: '${DB_DATABASE:-laravel}'
POSTGRES_USER: '${DB_USERNAME:-laravel}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
volumes:
- './docker/pgsql/datas:/var/lib/postgresql/data'
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "${DB_DATABASE:-laravel}", "-U", "${DB_USERNAME:-laravel}" ]
mailpit:
image: axllent/mailpit:latest
ports:
- 1025:1025
- 8025:8025
Loading

0 comments on commit 8e1c649

Please sign in to comment.