Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cfc31e3
Create Dockerfile for PHP 7.1 Apache setup
jcabo65 Oct 26, 2025
fa90ea5
Add Dockerfile for MariaDB setup
jcabo65 Oct 26, 2025
cc02216
Create docker-compose.yml
jcabo65 Oct 26, 2025
35c6754
Añadir Dockerfile.db, Dockerfile.web y composer.lock para containeriz…
jcabo65 Oct 26, 2025
620f21f
Ajustar Dockerfile.web para eliminar dependencia de vhost.conf
jcabo65 Oct 26, 2025
d3fe8fd
Actualizar Dockerfile.web a php:7.1-apache-stretch para resolver erro…
jcabo65 Oct 26, 2025
bcb3144
Actualizar Dockerfile.web a php:7.2-apache para resolver errores de i…
jcabo65 Oct 26, 2025
cadf464
Optimizar Dockerfile.web con mirror alternativo y comandos separados
jcabo65 Oct 26, 2025
a00232d
Ajustar Dockerfile.web con mirror alternativo y reintento para apt-ge…
jcabo65 Oct 26, 2025
1e62345
Ajustar Dockerfile.web con mirror oficial y retraso para apt-get update
jcabo65 Oct 26, 2025
28d9461
Actualizar a php:7.4-apache y ajustar apt-get update para Codespaces
jcabo65 Oct 26, 2025
f2d7bbb
Ajustar permisos y configuración de Apache en Dockerfile.web para res…
jcabo65 Oct 26, 2025
325218c
Ajustar Dockerfile.web con permisos y manejo de enlaces simbólicos pa…
jcabo65 Oct 26, 2025
bc26bb3
Añadir autoload PSR-4 para src/ sin modificar código
jcabo65 Oct 26, 2025
f3592e2
Asegurar ejecución de composer install para autoloading
jcabo65 Oct 26, 2025
bcc6e90
Mover autoloader.php, bootstrap.php y error_handler.php a web/ sin mo…
jcabo65 Oct 26, 2025
d19edb0
Ajustar ruta en autoloader.php a ../src/ sin modificar código
jcabo65 Oct 26, 2025
d926336
Create publish-dockerhub.yml
jcabo65 Oct 27, 2025
fa62f88
Add README for Docker application containerization
jcabo65 Oct 27, 2025
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
33 changes: 33 additions & 0 deletions .github/workflows/publish-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish to Docker Hub
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'docker/**'
- '.github/workflows/**'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & Push WEB
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile.web
push: true
tags: jcabo65/php-sample-web:latest
- name: Build & Push DB
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile.db
push: true
tags: jcabo65/php-sample-db:latest
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"require": {
"willdurand/negotiation": "^2.2",
"twbs/bootstrap": "^3.3"
},
"autoload": {
"psr-4": {
"": "src/"
}
}
}
130 changes: 130 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions docker/Dockerfile.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM mariadb:10.3

COPY sql/db.sql /docker-entrypoint-initdb.d/

ENV MYSQL_ROOT_PASSWORD=rootpass \
MYSQL_DATABASE=sample \
MYSQL_USER=sampleuser \
MYSQL_PASSWORD=samplepass
35 changes: 35 additions & 0 deletions docker/Dockerfile.web
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM php:7.4-apache

# Forzar actualización de fuentes APT
RUN apt-get update -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false || { sleep 10; apt-get update -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false; }

# Instalar dependencias y Composer
RUN apt-get install -y wget unzip libzip-dev vim-tiny
RUN docker-php-ext-install pdo pdo_mysql zip
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /var/www/html
COPY . .

# Instalar dependencias de Composer
RUN composer install --no-scripts --no-interaction

# Ajustar permisos y enlaces
RUN chown -R www-data:www-data /var/www/html/web /var/www/html/vendor || { echo "Error ajustando permisos"; exit 1; } \
&& chmod -R 755 /var/www/html/web /var/www/html/vendor \
&& ln -sf /var/www/html/vendor/twbs/bootstrap/dist/fonts/ /var/www/html/web/fonts

RUN a2enmod rewrite \
&& echo '<VirtualHost *:80>\n ServerName localhost\n DocumentRoot /var/www/html/web\n <Directory /var/www/html/web>\n Options Indexes FollowSymLinks\n AllowOverride All\n Require all granted\n </Directory>\n ErrorLog ${APACHE_LOG_DIR}/error.log\n CustomLog ${APACHE_LOG_DIR}/access.log combined\n</VirtualHost>' > /etc/apache2/sites-available/000-default.conf \
&& a2ensite 000-default.conf \
&& sed -i 's/LogLevel warn/LogLevel debug/g' /etc/apache2/apache2.conf \
&& apache2ctl configtest \
&& apache2ctl restart

EXPOSE 80

ENV DB_HOST=mariadb \
DB_NAME=sample \
DB_USER=sampleuser \
DB_PASS=samplepass
33 changes: 33 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.8'

services:
web:
build:
context: ..
dockerfile: docker/Dockerfile.web
image: tuusuario/php-sample-web:latest
ports:
- "8080:80"
depends_on:
- db
environment:
- DB_HOST=db
- DB_NAME=sample
- DB_USER=sampleuser
- DB_PASS=samplepass

db:
build:
context: ..
dockerfile: docker/Dockerfile.db
image: tuusuario/php-sample-db:latest
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: sample
MYSQL_USER: sampleuser
MYSQL_PASSWORD: samplepass
volumes:
- db_data:/var/lib/mysql

volumes:
db_data:
22 changes: 22 additions & 0 deletions web/README-ITEM2-DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Item 2 – Application Containerization (Docker)

Este documento complementa el README original **sin modificar el código fuente**.
Se publican dos imágenes en Docker Hub y se provee `docker-compose` para ejecutar la app.

## Imágenes públicas
- Web: https://hub.docker.com/r/jcabo65/php-sample-web
- DB: https://hub.docker.com/r/jcabo65/php-sample-db

## Archivos relevantes en este repo
- `docker/Dockerfile.web` – imagen PHP/Apache de la aplicación.
- `docker/Dockerfile.db` – imagen de base (MariaDB).
- `docker/docker-compose.yml` – orquesta `web` y `db` usando **las imágenes públicas**.
- `docker/docker-compose.override.yml` – comparte `/var/run/mysqld` para que la app (que usa `host=localhost`) conecte por **socket** sin cambiar código.

## Requisitos
- Docker + Docker Compose.

## Cómo ejecutar (2 líneas)
```bash
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml up -d
# abrir http://localhost:8080
1 change: 1 addition & 0 deletions web/autoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spl_autoload_register(function ($className) { if (stream_resolve_include_path($file = ("../src/" . str_replace("\\", "/", $className) . ".php"))) { include $file; } });
4 changes: 4 additions & 0 deletions web/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

require "autoloader.php";
require "error_handler.php";
19 changes: 19 additions & 0 deletions web/error_handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

set_error_handler(
function ($errno, $errstr, $errfile = null, $errline = null, $errcontext = [])
{
header($_SERVER["SERVER_PROTOCOL"] . " 500 Internal Server Error", true, 500);
$dateTime = new DateTime();
file_put_contents(__DIR__ . "/logs/error.log", "[{$dateTime->format("c")}] [$errno] $errstr in $errfile on line $errline\n", FILE_APPEND | LOCK_EX);
}
);

set_exception_handler(
function ($exception)
{
header($_SERVER["SERVER_PROTOCOL"] . " 500 Internal Server Error", true, 500);
$dateTime = new DateTime();
file_put_contents(__DIR__ . "/logs/error.log", "[{$dateTime->format("c")}] " . $exception->getMessage() . "\n", FILE_APPEND | LOCK_EX);
}
);