From aa68311a84ff13935e2b706028896c249827f19f Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sun, 3 Nov 2024 21:51:40 +0100 Subject: [PATCH] General: Add container to use in development --- .devcontainer/Containerfile | 63 +++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 23 ++++++++++++ .devcontainer/setup.sh | 6 ++++ composer.json | 5 ++- 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Containerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/setup.sh diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile new file mode 100644 index 00000000..ec0925fb --- /dev/null +++ b/.devcontainer/Containerfile @@ -0,0 +1,63 @@ +FROM php:8.3 as base +ENV AUTOLOAD_VERSION 0.2.0 + +RUN docker-php-ext-install mysqli + +RUN pecl install raphf \ + && docker-php-ext-enable raphf + +RUN apt-get update + +RUN apt-get install -y libzip-dev unzip \ + && docker-php-ext-install zip + +RUN apt-get install -y zlib1g-dev libcurl4-openssl-dev libssl-dev libicu-dev \ + && pecl install pecl_http \ + && docker-php-ext-enable http + +RUN apt-get install uuid-dev \ + && pecl install uuid \ + && docker-php-ext-enable uuid + +RUN curl -fsSL "https://github.com/pprkut/autoload-psr/releases/download/$AUTOLOAD_VERSION/autoload_psr-$AUTOLOAD_VERSION.tar.gz" -o autoload_psr.tar.gz \ + && mkdir -p autoload_psr \ + && tar -xf autoload_psr.tar.gz -C autoload_psr --strip-components=1 \ + && rm autoload_psr.tar.gz \ + && ( \ + cd autoload_psr \ + && phpize \ + && ./configure \ + && make -j "$(nproc)" \ + && make install \ + ) \ + && rm -r autoload_psr \ + && docker-php-ext-enable autoload_psr + +VOLUME /var/www/html +VOLUME /var/www/libs + +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + +ENV WEBROOT /var/www/html +ENV TARGET_DIR /var/www/libs + +WORKDIR /var/www/html + +FROM base AS dev + +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" + +RUN pecl install xdebug \ + && docker-php-ext-enable xdebug + +RUN pecl install uopz \ + && docker-php-ext-enable uopz + +# dev tools separate install so we quickly change without rebuilding all php extensions +RUN apt update && apt-get install -y --no-install-recommends \ + sudo gnupg2 git ant jq mariadb-client \ + && rm -rf /var/lib/apt/lists/* + +# Install composer +RUN curl -o /usr/local/bin/composer https://getcomposer.org/download/latest-stable/composer.phar \ + && chmod +x /usr/local/bin/composer diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..eb621b7e --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +{ + "build": { + "dockerfile": "Containerfile" + }, + "containerEnv": { + "XDEBUG_MODE": "debug" + }, + "customizations": { + "vscode": { + "extensions": [ + "felixfbecker.php-intellisense", + "octref.vetur" + ], + "settings": { + "php.suggest.basic": false + } + } + }, + "workspaceMount": "source=${localWorkspaceFolder},target=/var/www/html/dev.lunr,type=bind", + "workspaceFolder": "/var/www/html/dev.lunr", + "overrideCommand": true, + "postAttachCommand": "bash ./.devcontainer/setup.sh" +} diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100644 index 00000000..1f683661 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +composer install +for command in $(ls vendor/bin); do + ln -s "$(pwd)/vendor/bin/$command" "/usr/local/bin/$command" +done \ No newline at end of file diff --git a/composer.json b/composer.json index 22fb7541..b36bded6 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,11 @@ }, "require-dev": { "lunr/halo": "dev-master", + "phpstan/phpstan": "~1.0", "phpunit/phpunit": ">=9.0 <9.6", - "ext-xdebug": "~3.1" + "ext-xdebug": "~3.1", + "squizlabs/php_codesniffer": "^3.10", + "phploc/phploc": "^7.0" }, "config": { "optimize-autoloader": true