Problem/Motivation

A pre/post assessment plugin can be a starting point for developers to experiment with affecting the build when running as the codebase building user (and not the testing user like www-data)

It should basically be just a shell exec that saves its output, and should *probably* execute inside the environment.

Proposed resolution

We add two plugins: host_command and container_command.

So for instance if you want to test whether a file was added by a patch (not a great use case but hopefully illustrative) then you'd structure your yml like this:

build:
  assessment:
    host_command:
      die-on-nonzero: TRUE
      commands:
        - test -f your/file.txt

You could run on container_command similarly.

Currently there is only the PHP container, which might be a different version of PHP than the host.

die-on-nonzero is granular to the command step. You can further granularize the behavior by adding more of them with names like this:

build:
  assessment:
    host_command.setup:
      die-on-nonzero: FALSE
      commands:
        - setup your/thing
        - setup other/thing
    container_command.critical:
      die-on-nonzero: TRUE
      commands:
        - showstopper -V

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Mixologic created an issue. See original summary.

Mixologic’s picture

In Phase II we may allow for modifications to the environment and restarting of the containers. E.G. apt-get install php7.1-gmp to add a particular extension and restart the containers. Or perhaps its a config change to mysql or php itself (disabling assertions etc).

mile23’s picture

Issue summary: View changes

Updated IS with a little more spec.

Updated Phase II with the comment above. #2949210: Drupalci Roadmap

mile23’s picture

Updating IS w findings from slack discussion

mile23’s picture

Mixologic’s picture

Sweet. Bingo.

  • Mile23 committed 487807b on 2949251-pre-post-assessment
    Issue #2949251: First steps.
    
mile23’s picture

Issue summary: View changes

Working for host, not for container. See

tests/DrupalCI/Tests/Application/Fixtures/build.CoreD8PreAssessment.yml

Updated to a sort of coding standard: Plugins have underscores, config has hyphens.

Added $taskbase->execWithArtifact() which is similar to execRequiredCommand(), except it allows us to specify an artifact file name, and it can be used many times in one plugin instance.

  • Mile23 committed 7f7449a on 2949251-pre-post-assessment
    Issue #2949251: Execution in the PHP container now. Needs tests.
    
Mixologic’s picture

Plugins have underscores, config has hyphens.

I super like this idea, and think thats how it should be, but Im somewhat concerned that if we convert the codebase to have this standard, that we'll have a pile of older builds and older build.yml files that wouldnt be compatible with the new format. - but maybe we just add a thing where right after we try to discover if its a plugin and dont find one, we string replace _ for -'s for 180 days, and then after all the old builds have expired we remove it.

Mixologic’s picture

Also, found a potential use case for pre/post build.

Found this gitlab-ci.yml in a repo:
https://cgit.drupalcode.org/file_system_switch/tree/.gitlab-ci.yml?h=7.x...

So having the ability to make commits would be interesting. I doubt we can do that because we'd need maintainers ssh keys, but its something to think about.

mile23’s picture

The 'coding standard' was that plugin *names* have underscores, but the config elements have hyphens, so that it's 'php-container' instead of 'php_container'. I did that because I kept typing it that way instead of the original suggestion which was 'php_container'.

Sorry if I wasn't clear.

Mixologic’s picture

Right, I was just saying that, thats a good idea for a standard, but we already have several config elements with underscores instead of hypens, and that if we adopt that standard, we should fix those config elements to be hyphens, but then existing drupalci.yml files wouldnt work because they'd all have underscores.

So I was just saying that at the point where we're recursing through the yaml, and matching keys to plugin names, anytime a key doesnt match a plugin name, we're assuming it means its a config element. So right there we could just convert whatever was submitted to be a hypen, so that it'll match the rest of the converted codebase.

#2953923: Convert configuration elements to be all hypens, ensure all plugin definitions use underscores Im def gonna do this.

Also, I've been testing this plugin out and running into a couple of rando issues, mostly with some oddball things we're doing elsewhere.

#2953897-7: drupalci.yml should not fail on container composer Is my latest, and its causing a bug with http://cgit.drupalcode.org/drupalci_testbot/tree/src/DrupalCI/Plugin/Bui... where pimple gets mad that we've set the db.results service and are trying to set it again. So Im working on a fix for that.

Also going to tweak some other config stuff, specifically '$is_extension_test' config should not be a config at all, and should instead come from codebase->getProjectType.

  • Mile23 committed 8acc5a1 on 2949251-pre-post-assessment
    Issue #2949251: Added unit tests. Still to go: functional tests
    
mile23’s picture

So do you want to assign yourself to it, or shall I continue working?

Mixologic’s picture

This one, keep working on.. I was getting confused between this and the other one

So when I said

Also, I've been testing this plugin out

I meant :
#2950939: Use the drupalci.yml to specify assessment if modified

Mixologic’s picture

Title: Add a pre and post Assessment plugin » Add a container_command and host_command Assessment plugin

Documenting the slack discussion:

Pre/post seem like they are the same thing, only separated by where they happen in the build.

Lets just make them command plugins, and remove the 'execution-environment: host' config and make them subclasses of each other. Seems nicer to say :

build:
  assessment:
    host_command.setup:
      die-on-nonzero: FALSE
      commands:
        - setup your/thing
        - setup other/thing
    container_command.critical:
      die-on-nonzero: TRUE
      commands:
        - showstopper -V
Mixologic’s picture

Status: Active » Needs work

  • Mile23 committed 0663705 on 2949251-pre-post-assessment
    Issue #2949251: Changed to host_command and container_command. Still...
mile23’s picture

Issue summary: View changes

Changed the plugin names. This simplifies things. :-)

Updated IS.

Still needs tests.

Mixologic’s picture

Assigned: Unassigned » Mixologic

I'll gather this and start lookin.

Mixologic’s picture

Im starting to wonder if https://www.drupal.org/project/drupalci_testbot/issues/2847205 is something we should do first. execWithArtifact sure seems like its going down that path.

mile23’s picture

I can't find the issue right now, but it might be better to work on a solution for run-all-the-things-even-if-one-of-them-fails. That's the harder use case and would give a better opportunity to put everything where it should be.

  • 0c125b3 committed on 2949251-pre-post-assessment
    Issue #2949251: Moves commands to Utility Buildstep namespace, .
    
  • aab7288 committed on 2949251-pre-post-assessment
    Issue #2949251: HostCommand exists only to provide a plugin namespace...
  • b82db0e committed on 2949251-pre-post-assessment
    Issue #2949251: minor nit
    
  • c369389 committed on 2949251-pre-post-assessment
    Issue #2949251: Updates the plugins to use the new exec architecture....
  • d23b70e committed on 2949251-pre-post-assessment
    Issue #2949251: Moves HostCommand to Command, changes ContainerCommand...
Mixologic’s picture

I saw these plugins trying to do a bunch of things they shouldnt need to be trying to do , and additional code for stuff that was already handled elsewhere, So, I went ahead and did some unifying of the underlying command infrastructure over in https://www.drupal.org/project/drupalci_testbot/issues/2847205

I even did the needful and updated CONTRIBUTING.md to reflect all these improvements:

https://cgit.drupalcode.org/drupalci_testbot/tree/CONTRIBUTING.md#n362

So, given that we've got this fancy api that does all the signal, artifact, and array handling for us, these plugins can just about be a passthrough mechanism.

*but wait, theres more*

I was thinking that in the vast majority of cases, the commands that are being executed need some variables from the underlying system, specifically, the source directory, and the project directory, in both the environment and on the host. -> perhaps we can either set some environment variables for whatever commands get executed, (proc_open?) or have some sort of rudimentary tokens that translate {SOURCE_DIR} into the sourceDir of the system under test. I dont think that changing directory to those locations is going to do what we want (especially with the docker container.. you cant just cd, because each command is like a new shell. you gotta cd somedir && do something else

Anyhow, did some other moving around, and now what remains is some command tokens, and making the tests test things.

  • 1205d3f committed on 2949251-pre-post-assessment
    Issue #2949251: Removes assumptions of cwd for executing composer
    
  • 4849301 committed on 2949251-pre-post-assessment
    Issue #2949251: Allows for injecting environment variables into command...
  • 94dcc7a committed on 2949251-pre-post-assessment
    Issue #2949251: converts exec() to a Symfony process object and makes a...

  • 387a82c committed on 2949251-pre-post-assessment
    Issue #2949251: makes some prelim test adjustments, sets a longer...
Mixologic’s picture

Okay, so what we have now are two plugins under Utility: Command ('host_command'), and ContainerCommand ('container_command').

These rely on symfony process component to handle the execution of things.

Stuff I ran into:

Im setting some environment variables in each plugin such that consumers of these plugins can execute commands and have access to the following vars:

HOST_SOURCE_DIR
HOST_PROJECT_DIR
TEST_SOURCE_DIR
TEST_PROJECT_DIR

Which, now that I think about it shouldnt be obviously just SOURCE_DIR and PROJECT_DIR, and have different values depending on whether its host_command or container_command.

Anyhow, setting env vars on the symfony process must have done something wonky to composer such that the local composer commands were failing on a real testbot (but not on the vagrant box).

I got around that by not setting a blank array to the env, but that might mean that there are other scripts that fail when we pass in the envs in these plugins. Hard to tell. Maybe its just composer.

  • f5fc456 committed on 2949251-pre-post-assessment
    Issue #2949251: cleans up environment variables
    
Mixologic’s picture

Status: Needs work » Fixed

Okay, existing tests are passing, and, due to circumstances and not-quite thinking things through, this was merged into dev for testing, and then I had to get a separate concurrency bug fixed in d7, and so this ended up in production. So yeah, its there now.

Lets close this and carry forth in a followup: #2955089: Create tests that exercise host_command and container_command

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.