Explore the posibility of a different setup for the project, composer expansion and symlinking process

Created on 6 March 2024, 10 months ago
Updated 1 August 2024, 5 months ago

Problem/Motivation

Maybe we don't need to do anything, or maybe we do.
[#15470452-13] and #3418831-40: Test-only job both led to the conclusion that our current building process is not ideal, as it modifies files from the project, so it's hard when we need to do git diff in MR-based workflows, or we have some issues with the symlinks (like when creating the cspell job).

So, quoting from one of those comments:

We could change the approach to building the project so that the original repo folder is pristine. For example: we could create a brand new folder, bring Drupal via composer there and do the expand_composer in that other folder. We'd just need to adjust the apache webroot paths after that. It's not a quick and easy one, but it's not a super complex one either.

Obviously, things are NOT broken, so they might not need fixing, but doing a refactoring that makes everything tidier and avoids the mentioned side effects might be a nice to have, and if we do it in a way that is fully BC then it might be worth exploring.

Steps to reproduce

Do a git diff after the composer step and you'll see that the "composer.json" file appears as changed, even tho we are preserving the pristine copy in the symlinked folder (git diff runs in the root folder).

Proposed resolution

Explore a different setup process.

Remaining tasks

MR and tests.

Feature request
Status

Active

Component

gitlab-ci

Created by

🇪🇸Spain fjgarlin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @fjgarlin
  • 🇦🇺Australia dpi Perth, Australia

    Core systems, for example LibraryDiscoveryParser, require libraries to be placed in the Drupal root or module-relative.

    I have a project which dynamically determines the location of library files, for this example it is a test module in a subdirectory of the project.

    The gitlab templates as they are right now keep the module files outside the Drupal install. Then symlink the module files to a typical location inside modules/custom via symlink_project

    When PHP attempts to gets the location of the file, via reflection, it is outputting the true location of the file. That is, outside of the Drupal installation.

    When I try to use code in CI, it will not work since the files lie outside of the Drupal install.

    My guess is that there could be other Drupal projects failing, however unless assertions are very thorough, they won't notice assets are not loading.

    --

    My only suggestion at this time, is to actually copy, not symlink, files to the appropriate directory.

    This could be done by further modifications to the project composer.json file, by adding a path repository, and modifying symlink_project.php to instead copy files.

    Or we could just set up CI so it checks out the module code where it belongs in the first place, and build a running Drupal project around it (a few directories above). Im sure there are more ways to do this...

    The code I used to workaround the problem can be found at https://git.drupalcode.org/project/pinto/-/commit/ac26e665ce5f703faffbda.... Note the changes to `.gitlab-ci.yml` and a creation of a modified symlink_project, at `.gitlab/custom_symlink_project.php` (which actually copies, not symlinks)

  • 🇪🇸Spain fjgarlin

    Thanks for the links and examples, they do help a lot.

    My thinking about the project set up is similar. GitLab CI puts the project in /builds/project/THE-MODULE/ and then we build everything on that folder.

    We could explore building the project in /builds/project/full_project and then copy (not symlink) the module code. If using the above folder is not an option (haven't tried yet), we can still have a full_project folder in a location that we're allowed and build everything there. Then for module related jobs, we use the original pristine module folder (ie: linting jobs), and for the project related jobs (ie: running testing) we use the projects folder.

    So I fully agree with you on this one.

  • 🇦🇺Australia dpi Perth, Australia

    Just hit on this again in another project 🤦

    https://git.drupalcode.org/project/role_enum/-/merge_requests/2/pipelines

    Lucky I had a bunch of code in .gitlab-ci.yml / .gitlab/custom_symlink_project.php I could copy 😇

  • 🇪🇸Spain fjgarlin

    Given that the differences in the script you use are so small

        $source = sprintf('%s/%s', $projectRoot, $item);
        $target = sprintf('%s/%s', $moduleRoot, $item);
        \is_file($source)
          ? $fs->copy($source, $target)
          : $fs->mirror($source, $target);
    

    vs

    $fs->symlink($rel . $item, $moduleRoot . "/$item");
    

    we could definitely implement a variable to switch between symlink and copy. That could go in the current templates, without needing a big refactoring as it would also need to be selected.

    It could be something like this (untested):

    // In the hidden-variables.yml file
    _COPY_STRATEGY: "symlink"
    
    // In the symlink_project.php script (which could be renamed or just leave as is)
    $copy_strategy = isset($argv[3]) ? $argv[3] : getenv('_COPY_STRATEGY');
    $source = sprintf('%s/%s', $projectRoot, $item);
    $target = sprintf('%s/%s', $moduleRoot, $item);
    if ($copy_strategy === 'symlink') {
       $fs->symlink($source, $target);
    }
    elseif ($copy_strategy === 'copy') {
        \is_file($source)
          ? $fs->copy($source, $target)
          : $fs->mirror($source, $target);
    }
    else {
      // Fail or do the "symlink" as fallback I guess.
    }
    

    Feel free to create a different issue for this part if that's something worth exploring.

Production build 0.71.5 2024