diff --git a/Dockerfile b/Dockerfile index 17107abb756796f9e46bf0fbb244e24a2f2b653a..626555a88af105ca5d6744523bf05f2cf3147bd8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ ENV LAKEDROPS_DEV_DC_OPTIONS " " ADD config.fish /etc/fish/ ADD start.sh /usr/local/bin/.start ADD configIdea.sh /usr/local/bin/.configIdea +ADD configIdea.php /usr/local/bin/.configIdea.php ADD l3dComposer.php /usr/local/bin/.l3dComposer.php ADD ahoy.changelog.yml /etc/ahoy/changelog.yml ADD run/scripts/info /usr/local/bin/l3d diff --git a/ahoy.changelog.yml b/ahoy.changelog.yml index 05e9370a744581bd15423d0ba6f43a326f735a52..bf0424a13d663b1c4a12db867e91e901879f61fb 100644 --- a/ahoy.changelog.yml +++ b/ahoy.changelog.yml @@ -2,7 +2,7 @@ ahoyapi: v2 commands: extract: cmd: | - if [ "x$1" <> "x" ]; then + if [ "x$1" != "x" ]; then cd $1 fi git log $(git describe --tags `git rev-list --tags --max-count=1`)..HEAD --oneline | cut -d' ' -f 2-999 diff --git a/configIdea.php b/configIdea.php new file mode 100644 index 0000000000000000000000000000000000000000..a29aa032a8504f7ad70769b7ba153eea35d8f06b --- /dev/null +++ b/configIdea.php @@ -0,0 +1,123 @@ +<?php + +if ($argc !== 2) { + return; +} +$uuid = $argv[1]; + +$tasks = [ + 'inspectionProfiles/Project_Default.xml' => [ + 'component/profile' => [ + 'inspection_tool' => [ + [ + 'attribute' => 'class', + 'value' => 'MessDetectorValidationInspection', + 'content' => '<inspection_tool class="MessDetectorValidationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />', + ], + [ + 'attribute' => 'class', + 'value' => 'PhpCSValidationInspection', + 'content' => '<inspection_tool class="PhpCSValidationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true"><option name="CODING_STANDARD" value="Drupal" /><option name="EXTENSIONS" value="php,js,css,inc" /></inspection_tool>', + ], + ], + ], + ], + 'php.xml' => [ + 'project' => [ + 'component' => [ + [ + 'attribute' => 'name', + 'value' => 'MessDetector', + 'content' => '<component name="MessDetector"><phpmd_settings><MessDetectorConfiguration tool_path="$PROJECT_DIR$/vendor/bin/phpmd" /></phpmd_settings></component>', + ], + [ + 'attribute' => 'name', + 'value' => 'PhpCodeSniffer', + 'content' => '<component name="PhpCodeSniffer"><phpcs_settings><PhpCSConfiguration standards="Drupal;DrupalPractice;MySource;PEAR;PSR1;PSR12;PSR2;SlevomatCodingStandard;Squiz;VariableAnalysis;Zend" tool_path="$PROJECT_DIR$/vendor/bin/phpcs" /></phpcs_settings></component>', + ], + [ + 'attribute' => 'name', + 'value' => 'PhpInterpreters', + 'content' => '<component name="PhpInterpreters"><interpreters><interpreter id="' . $uuid . '" name="php" home="docker-compose://DATA" debugger_id="php.debugger.XDebug"><remote_data INTERPRETER_PATH="php" HELPERS_PATH="/opt/.phpstorm_helpers" INITIALIZED="false" VALID="true" RUN_AS_ROOT_VIA_SUDO="false" DOCKER_ACCOUNT_NAME="Docker" DOCKER_COMPOSE_SERVICE_NAME="php" DOCKER_REMOTE_PROJECT_PATH="/opt/project"><type_data command="EXEC" /><dockerComposeConfigurationPaths><item value="$PROJECT_DIR$/docker-compose.yml" /></dockerComposeConfigurationPaths><envs /></remote_data></interpreter></interpreters></component>', + ], + [ + 'attribute' => 'name', + 'value' => 'PhpUnit', + 'content' => '<component name="PhpUnit"><phpunit_settings><phpunit_by_interpreter interpreter_id="' . $uuid . '" configuration_file_path="/var/www/html/tests/phpunit.xml.dist" custom_loader_path="/var/www/html/vendor/autoload.php" phpunit_phar_path="" use_configuration_file="true" /></phpunit_settings></component>', + ], + ], + ], + ], + 'workspace.xml' => [ + 'project' => [ + 'component' => [ + [ + 'attribute' => 'name', + 'value' => 'DrupalConfiguration', + 'content' => '<component name="DrupalConfiguration" enabled="true" version="9"><drupalPath>$PROJECT_DIR$/web</drupalPath></component>', + 'keep existing' => TRUE, + ], + [ + 'attribute' => 'name', + 'value' => 'PhpServers', + 'content' => '<component name="PhpServers"><servers><server host="abc.def.de" id="' . $uuid . '" name="Docker" use_path_mappings="true"><path_mappings><mapping local-root="$PROJECT_DIR$" remote-root="/var/www/html" /></path_mappings></server></servers></component>', + 'keep existing' => TRUE, + ], + [ + 'attribute' => 'name', + 'value' => 'RunManager', + 'content' => '<component name="RunManager"><configuration name="Docker" type="PhpWebAppRunConfigurationType" factoryName="PHP Web Application" is_https="true" server_name="Docker"><method v="2" /></configuration></component>', + 'keep existing' => TRUE, + ], + ], + ], + ], +]; + +foreach ($tasks as $file => $task) { + $filename = '/drupal/.idea/' . $file; + if (file_exists($filename)) { + $delete = []; + $replace = []; + $i = 0; + $xml = simplexml_load_string(file_get_contents($filename)); + foreach ($task as $wrapper => $items) { + $obj = $xml->xpath('//' . $wrapper); + if (!$obj) { + // Ignore for now. + continue; + } + foreach ($items as $xpath => $settings) { + $elements = $obj[0]->xpath($xpath); + foreach ($settings as $setting) { + $exists = FALSE; + foreach ($elements as $element) { + foreach ($element->attributes() as $name => $value) { + if ($name === $setting['attribute'] && (string) $value === $setting['value']) { + $exists = TRUE; + if (empty($setting['keep existing'])) { + $delete[] = $element; + } + break 2; + } + } + } + if (!$exists || empty($setting['keep existing'])) { + $i++; + $obj[0]->addChild('XYZ-' . $i); + $replace['<XYZ-' . $i . '/>'] = $setting['content']; + } + } + } + } + foreach ($delete as $item) { + $dom = dom_import_simplexml($item); + $dom->parentNode->removeChild($dom); + } + $result = $xml->asXml(); + foreach ($replace as $from => $to) { + $result = str_replace($from, $to, $result); + } + file_put_contents($filename, $result); + } +} diff --git a/configIdea.sh b/configIdea.sh index eb1b033ace36a3da597268855bd753acd8b7f5a8..af0846207c16289711a51fdc81f79ab19c75e442 100755 --- a/configIdea.sh +++ b/configIdea.sh @@ -1,91 +1,36 @@ #!/bin/bash -UUID=b88416e8-1762-45c7-ad93-82be4fbf72a4 +UUID=7a28abff-18ef-49a4-889e-453241ccddd0 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?> -<project version=\"4\"> - <component name=\"RemoteMappingsManager\"> - <list> - <list> - <remote-mappings server-id=\"php@${UUID}\" /> - </list> - </list> - </component> -</project>" > /drupal/.idea/remote-mappings.xml + <project version=\"4\"> + <component name=\"PhpTestFrameworkVersionCache\"> + <tools_cache> + <tool tool_name=\"PHPUnit\"> + <cache> + <versions> + <info id=\"interpreter-${UUID}\" version=\"9.5.20\" /> + </versions> + </cache> + </tool> + </tools_cache> + </component> + </project>" > /drupal/.idea/php-test-framework.xml -echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?> -<project version=\"4\"> - <component name=\"PhpDockerContainerSettings\"> - <list> - <map> - <entry key=\"${UUID}\"> - <value> - <DockerContainerSettings> - <option name=\"envVars\"> - <list> - <DockerEnvVarImpl> - <option name=\"name\" - value=\"COMPOSE_PROJECT_NAME\"/> - <option name=\"value\" value=\"${COMPOSE_PROJECT_NAME}\"/> - </DockerEnvVarImpl> - <DockerEnvVarImpl> - <option name=\"name\" - value=\"PHP_VERSION\"/> - <option name=\"value\" value=\"${PHP_VERSION}\"/> - </DockerEnvVarImpl> - <DockerEnvVarImpl> - <option name=\"name\" - value=\"SSH_AUTH_SOCK\"/> - <option name=\"value\" - value=\"/ssh-agent\"/> - </DockerEnvVarImpl> - </list> - </option> - <option name=\"version\" value=\"1\"/> - <option name=\"volumeBindings\"> - <list> - <DockerVolumeBindingImpl> - <option name=\"containerPath\" - value=\"/drupal\"/> - <option name=\"hostPath\" - value=\"${WORKDIR}\"/> - </DockerVolumeBindingImpl> - <DockerVolumeBindingImpl> - <option name=\"containerPath\" - value=\"/ssh-agent\"/> - <option name=\"hostPath\" - value=\"${SSHAUTH}\"/> - </DockerVolumeBindingImpl> - <DockerVolumeBindingImpl> - <option name=\"containerPath\" - value=\"/var/run/docker.sock\"/> - <option name=\"hostPath\" - value=\"/var/run/docker.sock\"/> - </DockerVolumeBindingImpl> - <DockerVolumeBindingImpl> - <option name=\"containerPath\" - value=\"/root/.traefik\"/> - <option name=\"hostPath\" - value=\"${HOMEDIR}/.traefik\"/> - </DockerVolumeBindingImpl> - <DockerVolumeBindingImpl> - <option name=\"containerPath\" - value=\"/root/.gitconfig\"/> - <option name=\"hostPath\" - value=\"${HOMEDIR}/.gitconfig\"/> - </DockerVolumeBindingImpl> - <DockerVolumeBindingImpl> - <option name=\"containerPath\" - value=\"/root/.composer/auth.json\"/> - <option name=\"hostPath\" - value=\"${HOMEDIR}/.composer/auth.json\"/> - </DockerVolumeBindingImpl> - </list> - </option> - </DockerContainerSettings> - </value> - </entry> - </map> - </list> - </component> -</project>" > /drupal/.idea/php-docker-settings.xml +if [[ ! -d /drupal/.idea/inspectionProfiles ]]; then + mkdir /drupal/.idea/inspectionProfiles +fi +if [[ ! -f /drupal/.idea/inspectionProfiles/Project_Default.xml ]]; then + echo "<?xml version=\"1.0\"?><component name=\"InspectionProjectProfileManager\"><profile version=\"1.0\"></profile></component>" > /drupal/.idea/inspectionProfiles/Project_Default.xml +fi +if [[ ! -f /drupal/.idea/php.xml ]]; then + echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><project version=\"4\"></project>" > /drupal/.idea/php.xml +fi +if [[ ! -f /drupal/.idea/symfony2.xml ]]; then + echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><project version=\"4\"><component name=\"Symfony2PluginSettings\"><option name=\"pluginEnabled\" value=\"true\" /></component></project>" > /drupal/.idea/symfony2.xml +fi +if [[ ! -f /drupal/.idea/workspace.xml ]]; then + echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><project version=\"4\"></project>" > /drupal/.idea/workspace.xml +fi + +php /usr/local/bin/.configIdea.php $UUID diff --git a/start.sh b/start.sh index 834cbffd165ce6c10fc3b78a94cce44aaffeb015..dcb6b327f86ecf13f37f457b1e4331e29a8f93f1 100755 --- a/start.sh +++ b/start.sh @@ -27,6 +27,9 @@ function truncateCurrentDirectory { } function restoreEnvFile { + if [[ "${COMPOSE_PROJECT_NAME}" == "." ]]; then + return + fi if [[ -n ${PHP_VERSION} ]]; then echo "PHP_VERSION=${PHP_VERSION}" >>.env fi @@ -235,28 +238,34 @@ else l3dComposer fi -setupAhoy if [[ -d /drupal/.idea ]]; then /usr/local/bin/.configIdea fi restoreEnvFile -# Configure Git Hook -if [[ -d .git ]]; then - if [[ ! -f .git/hooks/post-checkout ]]; then - echo "#!/bin/sh" > .git/hooks/post-checkout - chmod +x .git/hooks/post-checkout - fi - OLDCOMMAND='docker exec '${COMPOSE_PROJECT_NAME}'_l3d /usr/local/bin/update-env' - NEWCOMMAND='RUNNING=$(docker container ls --all -q -f name='${COMPOSE_PROJECT_NAME}'_l3d);if [ "x$RUNNING" != "x" ];then docker exec '${COMPOSE_PROJECT_NAME}'_l3d /usr/local/bin/update-env;fi' - OLD_HOOK_DEFINED=$(grep "$OLDCOMMAND" .git/hooks/post-checkout) - NEW_HOOK_DEFINED=$(grep "$NEWCOMMAND" .git/hooks/post-checkout) - if [[ "x$OLD_HOOK_DEFINED" = "x" ]]; then - echo "$NEWCOMMAND" >> .git/hooks/post-checkout - elif [[ "x$NEW_HOOK_DEFINED" = "x" ]]; then - OLDCOMMAND="${OLDCOMMAND//\//\\/}" - sed -i -e "/${OLDCOMMAND}/d" .git/hooks/post-checkout - echo "$NEWCOMMAND" >> .git/hooks/post-checkout +if [[ "${COMPOSE_PROJECT_NAME}" != "." ]]; then + # Setup Ahoy + setupAhoy + # Configure Git Hook + if [[ -d .git ]]; then + if [[ ! -d .git/hooks ]]; then + mkdir -p .git/hooks + fi + if [[ ! -f .git/hooks/post-checkout ]]; then + echo "#!/bin/sh" > .git/hooks/post-checkout + chmod +x .git/hooks/post-checkout + fi + OLDCOMMAND='docker exec '${COMPOSE_PROJECT_NAME}'_l3d /usr/local/bin/update-env' + NEWCOMMAND='RUNNING=$(docker container ls --all -q -f name='${COMPOSE_PROJECT_NAME}'_l3d);if [ "x$RUNNING" != "x" ];then docker exec '${COMPOSE_PROJECT_NAME}'_l3d /usr/local/bin/update-env;fi' + OLD_HOOK_DEFINED=$(grep "$OLDCOMMAND" .git/hooks/post-checkout) + NEW_HOOK_DEFINED=$(grep "$NEWCOMMAND" .git/hooks/post-checkout) + if [[ "x$OLD_HOOK_DEFINED" = "x" ]]; then + echo "$NEWCOMMAND" >> .git/hooks/post-checkout + elif [[ "x$NEW_HOOK_DEFINED" = "x" ]]; then + OLDCOMMAND="${OLDCOMMAND//\//\\/}" + sed -i -e "/${OLDCOMMAND}/d" .git/hooks/post-checkout + echo "$NEWCOMMAND" >> .git/hooks/post-checkout + fi fi fi /usr/local/bin/update-env