Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# =============================================================================
# Docker Build Context Optimization
# Excluye archivos innecesarios para mejorar el rendimiento del build
# =============================================================================

# Control de versiones
.git/
.gitignore
.gitattributes
.gitmodules

# Archivos de desarrollo y configuración
.env*
.vscode/
.idea/
.claude/
*.log

# Dependencias y builds
node_modules/
bower_components/
vendor/
composer.lock
package-lock.json

# Archivos temporales y cache
storage/cache/
storage/logs/
tmp/
*.tmp
*.swp
*.swo
*~

# Archivos de backup y tests
*.backup
test/
wp-test/
db_data/
wordpress/

# Archivos comprimidos y releases
*.zip
*.tar.gz
*.rar
antonella-framework-for-wp.zip

# Archivos del sistema
.DS_Store
Thumbs.db

# Documentación de desarrollo (mantener solo esenciales)
PROBLEMAS_DE_INSTALACION.md

# CLI tools
wp-cli.phar
antonella
antonella2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.sh text eol=lf
89 changes: 81 additions & 8 deletions antonella
Original file line number Diff line number Diff line change
Expand Up @@ -754,30 +754,103 @@ class $className extends \\WP_Widget
}
}

/**
* Checks if a TCP port is in use on the host.
* @param int $port The port to check.
* @return bool True if in use, False if free.
*/
private function isPortInUse(int $port): bool
{
// Try to open a connection to the port. If it fails, it's free.
$connection = @fsockopen('127.0.0.1', $port, $errno, $errstr, 0.1);
if (is_resource($connection)) {
fclose($connection);
return true; // The port is in use
}
return false; // The port is free
}

/**
* Development server
*/
public function serveDevelopment($data)
{
$this->showInfo("Checking Docker installation...");
$this->showInfo("Starting Antonella development environment...");

// Docker checks from original method
$this->showInfo("Checking Docker installation...");
$dockerCheck = shell_exec('docker --version 2>&1');
if (empty($dockerCheck) || strpos($dockerCheck, 'not recognized') !== false) {
$this->showError("Docker is not installed. Please install from https://www.docker.com/products/docker-desktop");
}

$dockerPs = shell_exec('docker ps 2>&1');
if (
strpos($dockerPs, 'error during connect') !== false ||
strpos($dockerPs, 'Cannot connect to the Docker daemon') !== false
) {
if (strpos($dockerPs, 'error during connect') !== false || strpos($dockerPs, 'Cannot connect to the Docker daemon') !== false) {
$this->showError("Docker is not running. Please start Docker Desktop and try again.");
}

$this->showSuccess("Docker is ready!");

$base_wordpress_port = 8080;
$base_mysql_port = 3306;
$base_phpmyadmin_port = 9002;
$max_attempts = 20;

$wpPort = $base_wordpress_port;
$mysqlPort = $base_mysql_port;
$pmaPort = $base_phpmyadmin_port;
$foundFreePortSet = false;

for ($i = 0; $i < $max_attempts; $i++) {
$wpPort = $base_wordpress_port + $i;
$mysqlPort = $base_mysql_port + $i;
$pmaPort = $base_phpmyadmin_port + $i;

$this->showInfo("---");
$this->showInfo("Attempt " . ($i + 1) . ": Checking ports... (WP: $wpPort, MySQL: $mysqlPort, PMA: $pmaPort)");

$wpBusy = $this->isPortInUse($wpPort);
$mysqlBusy = $this->isPortInUse($mysqlPort);
$pmaBusy = $this->isPortInUse($pmaPort);

if (!$wpBusy && !$mysqlBusy && !$pmaBusy) {
$foundFreePortSet = true;
break;
}

if ($wpBusy) $this->showInfo(" -> Port $wpPort (WordPress) is in use.");
if ($mysqlBusy) $this->showInfo(" -> Port $mysqlPort (MySQL) is in use.");
if ($pmaBusy) $this->showInfo(" -> Port $pmaPort (phpMyAdmin) is in use.");
}

if (!$foundFreePortSet) {
$this->showError("Could not find a free set of ports after " . $max_attempts . " attempts.");
$this->showError("Please free up the ports or check your configuration.");
return;
}

$this->showInfo("---");
$this->showSuccess("Free ports found! Starting Docker with the following configuration:");
$this->showInfo(" - WordPress: http://localhost:$wpPort");
$this->showInfo(" - MySQL (Host): $mysqlPort");
$this->showInfo(" - phpMyAdmin: http://localhost:$pmaPort");

$this->showInfo("Starting development environment...");

$command = 'docker-compose up' . (isset($data[2]) && $data[2] === '-d' ? ' -d' : '');
// Cross-platform environment variable handling
$isWindows = PHP_OS_FAMILY === 'Windows';
$dockerCommand = 'docker-compose up' . (isset($data[2]) && $data[2] === '-d' ? ' -d' : '');

if ($isWindows) {
// Windows: Set environment variables before running command
putenv("WORDPRESS_PORT=$wpPort");
putenv("MYSQL_PORT=$mysqlPort");
putenv("PHPMYADMIN_PORT=$pmaPort");
$command = $dockerCommand;
} else {
// Unix/Linux: Use inline environment variables
$envVars = "WORDPRESS_PORT=$wpPort MYSQL_PORT=$mysqlPort PHPMYADMIN_PORT=$pmaPort";
$command = "$envVars $dockerCommand";
}

system($command);

$this->showSuccess("Development environment is ready!");
Expand Down
71 changes: 54 additions & 17 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
# =============================================================================
# Antonella Framework for WordPress - Docker Compose Configuration
#
# Entorno de desarrollo completo con:
# - MySQL 8.0 con healthchecks
# - WordPress con framework preconfigurado
# - phpMyAdmin para gestión de BD
# - WP-CLI para automatización
#
# Requisitos:
# - Docker Desktop 4.53.0+ (compatibilidad ARM64/Windows)
# - Docker Compose v2+
#
# Uso: docker compose up -d
# =============================================================================

services:
# Base de datos MySQL
# =============================================================================
# Base de datos MySQL 8.0
# Configurada con healthchecks para dependencias seguras
# =============================================================================
mysql:
container_name: mysql-antonella
image: mysql:8.0
restart: unless-stopped
ports:
- "3306:3306"
- "${MYSQL_PORT:-3306}:3306"
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
Expand All @@ -15,14 +33,18 @@ services:
- mysql_data:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 20s
retries: 10
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "wordpress", "-pwordpress"]
interval: 5s
timeout: 10s
retries: 20
start_period: 30s

# phpMyAdmin para gestión de base de datos
# =============================================================================
# phpMyAdmin - Gestión visual de base de datos
# Acceso: http://localhost:9000 (cambiar puerto si está ocupado)
# =============================================================================
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: phpmyadmin-antonella
restart: unless-stopped
environment:
PMA_HOST: mysql
Expand All @@ -33,18 +55,22 @@ services:
mysql:
condition: service_healthy
ports:
- "9000:80"
- "${PHPMYADMIN_PORT:-9000}:80"

# WordPress con configuración automática
# =============================================================================
# WordPress con Antonella Framework
# Configuración automática de desarrollo con inicialización completa
# Acceso: http://localhost:8080
# Admin: http://localhost:8080/wp-admin (test/test)
# =============================================================================
wordpress:
build:
context: .
dockerfile: docker/Dockerfile.wordpress
container_name: wp-antonella
hostname: antonella.test
restart: unless-stopped
ports:
- "8080:80"
- "${WORDPRESS_PORT:-8080}:80"
depends_on:
mysql:
condition: service_healthy
Expand All @@ -66,8 +92,8 @@ services:
# Configuración adicional de WordPress
WORDPRESS_CONFIG_EXTRA: |
// Configuración del sitio
define('WP_HOME', 'http://localhost:8080');
define('WP_SITEURL', 'http://localhost:8080');
define('WP_HOME', 'http://localhost:${WORDPRESS_PORT:-8080}');
define('WP_SITEURL', 'http://localhost:${WORDPRESS_PORT:-8080}');
define('DOMAIN_CURRENT_SITE', 'antonella.test');

// Configuración de desarrollo
Expand Down Expand Up @@ -96,12 +122,14 @@ services:
// Configuración de papelera
define('EMPTY_TRASH_DAYS', 7);

# Servicio para ejecutar WP-CLI commands
# =============================================================================
# WP-CLI Container - Automatización y comandos WordPress
# Uso: docker compose exec wpcli wp <comando>
# =============================================================================
wpcli:
build:
context: .
dockerfile: docker/Dockerfile.wordpress
container_name: wpcli-antonella
volumes:
- ./:/var/www/html/wp-content/plugins/antonella-framework
- wordpress_data:/var/www/html
Expand All @@ -113,16 +141,25 @@ services:
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
command: tail -f /dev/null # Mantener el contenedor activo
WORDPRESS_PORT: ${WORDPRESS_PORT:-8080}
command: tail -f /dev/null

# =============================================================================
# Volúmenes persistentes
# Mantienen datos entre reinicios de contenedores
# =============================================================================
volumes:
mysql_data:
driver: local
# Datos de MySQL (base de datos, configuraciones)
wordpress_data:
driver: local
# Instalación completa de WordPress (core, themes, uploads)

# =============================================================================
# Red personalizada
# Permite comunicación entre servicios con nombres de host
# =============================================================================
networks:
default:
name: antonella-network
27 changes: 24 additions & 3 deletions docker/Dockerfile.wordpress
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
# =============================================================================
# Antonella Framework - WordPress Development Container
#
# Builds a WordPress environment with:
# - WP-CLI for automation
# - Custom initialization scripts
# - Development tools and dependencies
#
# Compatible with: linux/amd64, linux/arm64, windows
# =============================================================================

FROM wordpress:latest

# Instalar dependencias necesarias
# =============================================================================
# Install system dependencies and development tools
# =============================================================================
RUN apt-get update && apt-get install -y \
curl \
less \
default-mysql-client \
&& rm -rf /var/lib/apt/lists/*

# Instalar WP-CLI
# =============================================================================
# Install WP-CLI for WordPress automation
# =============================================================================
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp

# Crear directorio para scripts
# =============================================================================
# Setup custom scripts directory and initialization
# =============================================================================
RUN mkdir -p /docker-scripts

# Copiar script de inicialización
Expand All @@ -23,5 +40,9 @@ RUN chmod +x /docker-scripts/init-wordpress.sh
COPY docker/entrypoint.sh /docker-scripts/
RUN chmod +x /docker-scripts/entrypoint.sh

# =============================================================================
# Configure container startup
# =============================================================================

ENTRYPOINT ["/docker-scripts/entrypoint.sh"]
CMD ["apache2-foreground"]
12 changes: 8 additions & 4 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/bin/bash
set -e

echo "🚀 Iniciando contenedor de WordPress..."

# Ejecutar el entrypoint original de WordPress
docker-entrypoint.sh "$@" &

# Obtener el PID del proceso de WordPress
WORDPRESS_PID=$!

# Esperar un poco para que WordPress se inicie
sleep 10
echo "⏳ Esperando a que WordPress se inicie..."
# Esperar más tiempo para que WordPress se inicie completamente
sleep 30

# Ejecutar la inicialización en segundo plano
/docker-scripts/init-wordpress.sh &
echo "🔧 Ejecutando script de inicialización de WordPress..."
# Ejecutar la inicialización en segundo plano con logging
/docker-scripts/init-wordpress.sh 2>&1 | tee /tmp/init-wordpress.log &

# Esperar a que WordPress termine
wait $WORDPRESS_PID
Loading