Compare commits

..

1 Commits

Author SHA1 Message Date
d28f793ad9 mailpit as utility v1 2025-06-17 13:13:01 +08:00
15 changed files with 107 additions and 79 deletions

View File

@ -1,5 +1,5 @@
# ------------------------------------------------------------------
# Lenverge: Central Configuration for Your Development Environment
# Lenvi: Central Configuration for Your Development Environment
# ------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
@ -8,13 +8,15 @@
# utilities:
# phpmyadmin:
# enabled: false
# domain: "pma.lenverge.local" # Local domain (can be customized)
# domain: "pma.lenvi.local" # Local domain (can be customized)
# php_version: "8.3" # Must match one of your project's PHP versions
# redis:
# enabled: false
# mailpit:
# enabled: false # Fake SMTP server to catch and view emails sent during local dev
# db_engine:
# Choose between mariadb, mysql, or postgresql. Lenverge will install and manage the correct service.
# Choose between mariadb, mysql, or postgresql. Lenvi will install and manage the correct service.
# db_credentials:
# Used for all auto-provisioned databases.
@ -34,17 +36,19 @@
utilities:
phpmyadmin:
enabled: false
domain: "pma.lenverge.local"
domain: "pma.lenvi.local"
php_version: "8.3"
redis:
enabled: false
mailpit:
enabled: false
# 🛢️ Database Engine
db_engine: "mariadb"
# 🔐 Database Credentials
db_credentials:
user: "Lenverge"
user: "Lenvi"
password: "secret"
# 🌐 Project Sites
@ -55,18 +59,18 @@ db_credentials:
sites:
- domain: mylaravelapp.local
project_root: /home/lenverge/projects/laravel
document_root: /home/lenverge/projects/laravel/public
project_root: /home/lenvi/projects/laravel
document_root: /home/lenvi/projects/laravel/public
php_version: "8.2"
database: "laravel_db"
- domain: mylegacyapp.local
project_root: /home/lenverge/projects/legacy-site
document_root: /home/lenverge/projects/legacy-site
project_root: /home/lenvi/projects/legacy-site
document_root: /home/lenvi/projects/legacy-site
php_version: "8.0"
database: "legacy_db"
- domain: simple.local
project_root: /home/lenverge/projects/simple
document_root: /home/lenverge/projects/simple
project_root: /home/lenvi/projects/simple
document_root: /home/lenvi/projects/simple
php_version: "8.3"

View File

@ -1,11 +1,9 @@
# Lenverge
Lenverge is a lightweight, Ansible-powered environment tool built for Laravel and legacy PHP projects. It delivers fast, VM-free provisioning directly on Ubuntu or WSL2 — ideal for modern apps and legacy codebases alike.
> Lenverge comes from Laravel, Legacy, and Lightweight Environment — built for projects that sit on the verge of legacy and modern, and need a clean bridge.
# Lenvi
The name **Lenvi** stands for **L**aravel, **L**egacy, and **L**ightweight **Envi**ronment.
It's a fast, simple alternative to tools like Homestead that uses Ansible to provision your local Ubuntu machine (or WSL2) directly, without the overhead of a virtual machine. True to its name, Lenvi is tailored to handle modern **L**aravel applications and complex **L**egacy PHP sites with ease, all while remaining incredibly **L**ightweight.
### Core Features
* **No Virtual Machine:** Runs directly on Ubuntu 22.04+ (or WSL2 Ubuntu).
* **Centralized Configuration:** Define your entire stack in one simple `Lenverge.yaml` file.
* **Centralized Configuration:** Define your entire stack in one simple `Lenvi.yaml` file.
* **Multi-PHP Ready:** Run different sites on different PHP versions simultaneously.
* **Smart CLI Wrappers:** Automatically uses the correct PHP version for `php`, `composer`, and `artisan` commands based on your current project directory.
* **Developer Utilities:** Easily enable tools like phpMyAdmin and Redis.
@ -27,19 +25,19 @@ Lenverge is a lightweight, Ansible-powered environment tool built for Laravel an
### 1. Get the Code
Clone the repository to a convenient location, like your home directory.
```bash
git clone https://git.marmattheo.com/marito/Lenverge.git ~/Lenverge && cd ~/Lenverge
git clone https://git.marmattheo.com/marito/Lenvi.git ~/Lenvi && cd ~/Lenvi
```
### 2. Configure Your Environment (`Lenverge.yaml`)
This is the most important step. Open `Lenverge.yaml` and define your entire environment.
### 2. Configure Your Environment (`Lenvi.yaml`)
This is the most important step. Open `Lenvi.yaml` and define your entire environment.
```yaml
# ------------------------------------------------------------------
# Lenverge: Central Configuration for Your Development Environment
# Lenvi: Central Configuration for Your Development Environment
# ------------------------------------------------------------------
# Optional developer utilities
utilities:
phpmyadmin:
enabled: false
domain: "pma.lenverge.local"
domain: "pma.lenvi.local"
php_version: "8.2"
redis:
enabled: false
@ -47,19 +45,19 @@ utilities:
db_engine: "mariadb"
# 2. Global Database Credentials
db_credentials:
user: "Lenverge"
user: "Lenvi"
password: "secret"
# 3. Your Web Projects
sites:
- domain: mylaravelapp.local
project_root: /home/lenverge/projects/laravel
document_root: /home/lenverge/projects/laravel/public
project_root: /home/lenvi/projects/laravel
document_root: /home/lenvi/projects/laravel/public
php_version: "8.2"
database: "laravel_db"
```
**Key Configuration Options:**
* **`utilities`**: Set `enabled: true` to install optional tools like `phpmyadmin` and `redis`.
* **`db_engine`**: Choose between `mariadb`, `mysql`, or `postgresql`. Lenverge will install and manage the correct service.
* **`db_engine`**: Choose between `mariadb`, `mysql`, or `postgresql`. Lenvi will install and manage the correct service.
* **`sites`**: A list of all your projects.
* `domain`: The local domain name you'll use in the browser.
* `project_root`: The base directory of your project (where `.git` or `composer.json` lives).
@ -68,16 +66,16 @@ sites:
* `database`: (Optional) The name of the database to create for this site.
> **WSL Performance Tip:** For the best performance, keep your project files inside the WSL filesystem (e.g., `/home/user/projects`) rather than on the mounted Windows filesystem (e.g., `/mnt/c/Users/...`).
### 3. Run the Provisioning Script
To set up or update your environment, use the simple `lenverge.sh` script.
To set up or update your environment, use the simple `lenvi.sh` script.
First, make the script executable (you only need to do this once):
```bash
chmod +x lenverge.sh
chmod +x lenvi.sh
```
Now, run the script. It will handle everything for you and will prompt for your `sudo` password to perform the necessary system changes.
```bash
./lenverge.sh
./lenvi.sh
```
> **WSL Users:** The very first time you run this, the script may stop and ask you to restart WSL. This is a one-time setup step to fix file permissions. Follow the on-screen instructions, and then re-run `./lenverge.sh`.
> **WSL Users:** The very first time you run this, the script may stop and ask you to restart WSL. This is a one-time setup step to fix file permissions. Follow the on-screen instructions, and then re-run `./lenvi.sh`.
## Post-Installation
### 1. Update Your `hosts` File
For your browser to access local domains, you must map them to your local machine.
@ -86,24 +84,24 @@ For your browser to access local domains, you must map them to your local machin
sudo nano /etc/hosts
```
* **On Windows (for WSL):** Open **Notepad as an Administrator** and edit `C:\Windows\System32\drivers\etc\hosts`.
Add an entry for each domain defined in `Lenverge.yaml`:
Add an entry for each domain defined in `Lenvi.yaml`:
```
127.0.0.1 mylaravelapp.local
# Add other project domains here
# Add utility domains if enabled, e.g.:
# 127.0.0.1 pma.lenverge.local
# 127.0.0.1 pma.lenvi.local
```
### 2. Configure Your Application (`.env`)
Update your application's `.env` file to use the database credentials from `Lenverge.yaml`.
Update your application's `.env` file to use the database credentials from `Lenvi.yaml`.
**Example `.env` for `mylaravelapp.local` (MariaDB/MySQL):**
```env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=Lenverge
DB_USERNAME=Lenvi
DB_PASSWORD=secret
# If you enabled Redis in Lenverge.yaml
# If you enabled Redis in Lenvi.yaml
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
@ -114,20 +112,20 @@ DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel_db_pg
DB_USERNAME=Lenverge
DB_USERNAME=Lenvi
DB_PASSWORD=secret
```
### 3. Verify Your Setup
* **Web Access:** Open your browser and navigate to `http://mylaravelapp.local`.
* **Smart PHP Version:** The `php`, `composer`, and `artisan` commands are context-aware.
```bash
cd /home/lenverge/projects/laravel
cd /home/lenvi/projects/laravel
php --version # Will show the PHP version defined for this site
composer install
```
## Daily Workflow
Lenverge is designed to be declarative. To make any changes, simply edit `Lenverge.yaml` and re-run the provisioning script with `./lenverge.sh`.
* **To Add a New Site:** Add a new entry to the `sites` list, update your `hosts` file, and run `./lenverge.sh`.
* **To Remove a Site:** Delete the site's block from `Lenverge.yaml`. When you re-run `./lenverge.sh`, Lenverge will automatically remove its Nginx configuration.
* **To Change a PHP Version:** Update the `php_version` for a site and run `./lenverge.sh`.
* **To Enable a Utility:** Set `enabled: true` for `phpmyadmin` or `redis`, update your `hosts` file if needed, and run `./lenverge.sh`.
Lenvi is designed to be declarative. To make any changes, simply edit `Lenvi.yaml` and re-run the provisioning script with `./lenvi.sh`.
* **To Add a New Site:** Add a new entry to the `sites` list, update your `hosts` file, and run `./lenvi.sh`.
* **To Remove a Site:** Delete the site's block from `Lenvi.yaml`. When you re-run `./lenvi.sh`, Lenvi will automatically remove its Nginx configuration.
* **To Change a PHP Version:** Update the `php_version` for a site and run `./lenvi.sh`.
* **To Enable a Utility:** Set `enabled: true` for `phpmyadmin` or `redis`, update your `hosts` file if needed, and run `./lenvi.sh`.

View File

@ -1,2 +1,2 @@
[lenverge_dev]
[lenvi_dev]
localhost ansible_connection=local

View File

@ -1,6 +1,6 @@
#!/bin/bash
# --- Lenverge Provisioning Script ---
# --- Lenvi Provisioning Script ---
# This script simplifies running the Ansible playbook, making it accessible
# for users who are not familiar with Ansible.
@ -10,8 +10,8 @@ chmod +x /home/$(whoami)
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR"
echo "▶️ Starting Lenverge Provisioning..."
echo " This will install/update services based on your Lenverge.yaml configuration."
echo "▶️ Starting Lenvi Provisioning..."
echo " This will install/update services based on your Lenvi.yaml configuration."
echo " You will be prompted for your sudo password to make system changes."
echo ""
@ -19,12 +19,12 @@ echo ""
# The `if` statement checks the command's exit code to provide a clear success/failure message.
if ansible-playbook playbook.yml -i inventory --ask-become-pass; then
echo ""
echo "✅ Success! Your Lenverge environment has been provisioned."
echo "✅ Success! Your Lenvi environment has been provisioned."
echo " Don't forget to update your hosts file if you added or changed site domains."
echo ""
else
echo ""
echo "❌ Error: Lenverge provisioning failed." >&2
echo "❌ Error: Lenvi provisioning failed." >&2
echo " Please review the Ansible output above to diagnose the issue." >&2
exit 1
fi

View File

@ -1,10 +1,10 @@
---
- name: "Provision Lenverge Development Environment"
hosts: lenverge_dev
- name: "Provision Lenvi Development Environment"
hosts: lenvi_dev
become: yes
vars_files:
- Lenverge.yaml
- Lenvi.yaml
pre_tasks:
- name: "Gather a unique list of required PHP versions from sites"
@ -21,4 +21,6 @@
when: utilities.phpmyadmin.enabled is defined and utilities.phpmyadmin.enabled
- role: redis
when: utilities.redis.enabled is defined and utilities.redis.enabled
- role: mailpit
when: utilities.mailpit.enabled is defined and utilities.mailpit.enabled
- role: projects

View File

@ -47,5 +47,5 @@
- name: "FOR WSL USER: This error is safe and intentional. Follow instructions below."
ansible.builtin.fail:
msg: |
✅ ACTION REQUIRED: WSL Configuration was Updated! Lenverge has configured /etc/wsl.conf to fix file permissions. You MUST restart WSL for this change to take effect. Please perform the following steps: 1. Type 'logout' or 'exit' to exit WSL. 2. Run the command: wsl --shutdown 3. Wait a few seconds, then re-open your WSL terminal. 4. cd ~/Lenverge and Re-run ./lenverge.sh
✅ ACTION REQUIRED: WSL Configuration was Updated! Lenvi has configured /etc/wsl.conf to fix file permissions. You MUST restart WSL for this change to take effect. Please perform the following steps: 1. Type 'logout' or 'exit' to exit WSL. 2. Run the command: wsl --shutdown 3. Wait a few seconds, then re-open your WSL terminal. 4. cd ~/Lenvi and Re-run ./lenvi.sh
when: wsl_conf_result.changed

View File

@ -80,7 +80,7 @@
- db_engine != 'postgres'
- "'postgresql' in ansible_facts.services"
- name: "Create the global Lenverge PostgreSQL user"
- name: "Create the global Lenvi PostgreSQL user"
community.postgresql.postgresql_user:
name: "{{ db_credentials.user }}"
password: "{{ db_credentials.password }}"
@ -98,7 +98,7 @@
state: present
when: db_engine == 'mariadb' or db_engine == 'mysql'
- name: "Create the global Lenverge database user"
- name: "Create the global Lenvi database user"
community.mysql.mysql_user:
name: "{{ db_credentials.user }}"
password: "{{ db_credentials.password }}"

View File

@ -0,0 +1,6 @@
---
- name: "Restart Mailpit service"
ansible.builtin.systemd:
name: mailpit
daemon_reload: yes
state: restarted

View File

@ -0,0 +1,24 @@
---
- name: "Install Mailpit using the official installation script"
ansible.builtin.shell: "bash <(curl -sL https://raw.githubusercontent.com/axllent/mailpit/develop/install.sh)"
args:
creates: /usr/local/bin/mailpit
register: mailpit_install
changed_when: "mailpit_install.rc == 0 and 'Installed Mailpit to' in mailpit_install.stdout"
become: yes
- name: "Create Mailpit systemd service file"
ansible.builtin.template:
src: mailpit.service.j2
dest: /etc/systemd/system/mailpit.service
owner: root
group: root
mode: '0644'
notify: Restart Mailpit service
- name: "Ensure Mailpit service is enabled and started"
ansible.builtin.systemd:
name: mailpit
enabled: yes
state: started
daemon_reload: yes

View File

@ -0,0 +1,14 @@
[Unit]
Description=Mailpit
After=network.target
[Service]
User={{ ansible_user_id }}
Group={{ ansible_user_gid }}
Type=simple
ExecStart=/usr/local/bin/mailpit
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

View File

@ -1,11 +0,0 @@
# This is the default catch-all server.
# It handles any request for a domain that is not explicitly configured.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
# Return a 404 Not Found error.
return 404;
}

View File

@ -14,13 +14,4 @@
ansible.builtin.file:
path: /etc/nginx/sites-enabled/default
state: absent
notify: Reload Nginx
- name: "Create a default catch-all server block"
ansible.builtin.copy:
src: 00-default-catch-all.conf
dest: /etc/nginx/conf.d/00-default-catch-all.conf
owner: root
group: root
mode: '0644'
notify: Reload Nginx

View File

@ -1,5 +1,5 @@
#!/bin/bash
# Lenverge Smart Artisan Wrapper
# Lenvi Smart Artisan Wrapper
# This script executes 'artisan' with the project-specific PHP version.
# Find the php wrapper script which contains all the logic.

View File

@ -1,10 +1,10 @@
#!/bin/bash
# Lenverge Smart PHP Wrapper
# Lenvi Smart PHP Wrapper
# This script executes any 'php' command with the project-specific PHP version.
DEFAULT_PHP_BINARY="/usr/bin/php"
PHP_BINARY=""
LENVI_CONFIG_FILE="{{ playbook_dir }}/Lenverge.yaml"
LENVI_CONFIG_FILE="{{ playbook_dir }}/Lenvi.yaml"
if [[ -f "$LENVI_CONFIG_FILE" ]]; then
CURRENT_PROJECT_ROOT=$(pwd)

View File

@ -11,7 +11,7 @@
msg: |
VALIDATION FAILED for site '{{ project.domain }}':
The project_root directory '{{ project.project_root }}' does not exist.
This path is required for Composer. Please create it or correct the path in Lenverge.yaml.
This path is required for Composer. Please create it or correct the path in Lenvi.yaml.
when: not project_root_stat.stat.exists or not project_root_stat.stat.isdir
- name: "Validate that document root '{{ project.document_root }}' exists"
@ -24,7 +24,7 @@
msg: |
VALIDATION FAILED for site '{{ project.domain }}':
The document_root directory '{{ project.document_root }}' does not exist.
This path is required for Nginx. Please create it or correct the path in Lenverge.yaml.
This path is required for Nginx. Please create it or correct the path in Lenvi.yaml.
when: not document_root_stat.stat.exists or not document_root_stat.stat.isdir
- name: "Check for an index file (index.php or index.html) in the document root"