diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..d2bd182 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,57 @@ +{ + "name": "IPAG SDK PHP Development", + "dockerComposeFile": [ + "../docker-compose.yml", + "docker-compose.yml" + ], + "service": "lcslucas-ipag-sdk", + "workspaceFolder": "/var/www/html", + "shutdownAction": "stopCompose", + + // Forward ports for debugging + "forwardPorts": [9000, 9003], + "portsAttributes": { + "9003": { + "label": "Xdebug", + "onAutoForward": "silent" + }, + "9000": { + "label": "PHP-FPM", + "onAutoForward": "silent" + } + }, + + "postCreateCommand": "composer install", + + "customizations": { + "vscode": { + "extensions": [ + "xdebug.php-debug", + "bmewburn.vscode-intelephense-client", + "DEVSENSE.phptools-vscode", + "neilbrayfield.php-docblocker", + "streetsidesoftware.code-spell-checker", + "streetsidesoftware.code-spell-checker-portuguese-brazilian", + "formulahendry.code-runner", + "shardulm94.trailing-spaces", + "MehediDracula.php-namespace-resolver", + "yzhang.markdown-all-in-one", + "junstyle.php-cs-fixer", + "GitHub.copilot-chat", + "GitHub.copilot", + "ms-azuretools.vscode-docker" + ], + "settings": { + "php.validate.executablePath": "/usr/local/bin/php", + "php.debug.executablePath": "/usr/local/bin/php", + "intelephense.files.maxSize": 5000000, + "files.watcherExclude": { + "**/vendor/**": true, + "**/node_modules/**": true + } + } + } + }, + + "remoteUser": "root" +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..4d414e8 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3' +services: + lcslucas-ipag-sdk: + volumes: + - ..:/var/www/html:cached + + # Configurações para Xdebug no Dev Container + environment: + - PHP_IDE_CONFIG=serverName=devcontainer + - XDEBUG_CONFIG=client_host=localhost + + # Overrides default command so things don't shut down after the process ends. + command: /bin/sh -c "while sleep 1000; do :; done" diff --git a/.docker/php.ini b/.docker/php.ini new file mode 100644 index 0000000..c9a03df --- /dev/null +++ b/.docker/php.ini @@ -0,0 +1,33 @@ +[PHP] +; Configurações para desenvolvimento +display_errors = On +display_startup_errors = On +error_reporting = E_ALL +log_errors = On +error_log = /var/log/php_errors.log + +; Memory limit +memory_limit = 256M + +; Execution time +max_execution_time = 120 + +; Upload +upload_max_filesize = 20M +post_max_size = 20M + +; Timezone +date.timezone = "America/Sao_Paulo" + +[Xdebug] +; Xdebug 3 configuration for Dev Container +xdebug.mode = debug,develop +xdebug.start_with_request = yes +xdebug.client_host = localhost +xdebug.client_port = 9003 +xdebug.idekey = VSCODE +xdebug.log = /var/log/xdebug.log +xdebug.log_level = 0 + +; Coverage (opcional, para testes) +; xdebug.mode = coverage \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5af0663..aa594f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,7 @@ composer.phar /vendor/ *.Identifier -.devcontainer .vscode -Dockerfile annotations.md .phpunit.cache clover.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9ad945d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +############################################################################### +# Imagem PHP + Apache +# Referência: https://gist.github.com/avandrevitor/bc9b28cba063468eda7bbeee9b485114 +# +FROM php:7.4-fpm-alpine as builder + +ENV COMPOSER_ALLOW_SUPERUSER=1 + +WORKDIR /var/www/html/ + +# Atualizar repositórios Alpine +RUN apk update + +# Install Dependencies - Usando apk para Alpine +RUN apk add --no-cache \ + bash \ + curl \ + bzip2 \ + libzip-dev \ + bzip2-dev \ + libxml2-dev \ + git \ + tar \ + unzip \ + zip \ + icu-dev \ + autoconf \ + gcc \ + g++ \ + make \ + linux-headers \ + $PHPIZE_DEPS + +# Extensões +RUN docker-php-ext-install bcmath +RUN docker-php-ext-install calendar +RUN docker-php-ext-install zip +RUN docker-php-ext-install intl + +# Configurar e instalar OPcache +RUN docker-php-ext-configure opcache && \ + docker-php-ext-install opcache + +# Instalar Xdebug (versão compatível com PHP 7.4) +RUN pecl channel-update pecl.php.net && \ + pecl install xdebug-3.1.6 && \ + docker-php-ext-enable xdebug + +# Configurar Xdebug (configuração básica, será sobrescrita pelo php.ini) +RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \ + echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \ + echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \ + echo "xdebug.log=/var/log/xdebug.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \ + echo "xdebug.idekey=VSCODE" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini + +# Composer#Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Copiar configurações personalizadas do PHP +COPY .docker/php.ini /usr/local/etc/php/conf.d/99-custom.ini + +# RUN bash -c "composer install" + +FROM builder + +WORKDIR /var/www/html/ + +RUN find . -type f | xargs -I{} chmod -v 644 {} && \ + find . -type d | xargs -I{} chmod -v 755 {}; \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5413019 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +services: + lcslucas-ipag-sdk: + container_name: lcslucas-ipag-sdk + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + working_dir: /var/www/html + volumes: + - ./:/var/www/html + ports: + - "9000:9000" # PHP-FPM + - "9003:9003" # Xdebug + environment: + - PHP_IDE_CONFIG=serverName=docker + - XDEBUG_CONFIG=remote_host=host.docker.internal \ No newline at end of file