pantheon-systems / terminus-build-tools-plugin

Manage multidev environments for a Pantheon site using a GitHub PR workflow.
83 stars 68 forks source link

Initial commit fails on Windows due to single quotes around commit message #139

Closed ghost closed 5 years ago

ghost commented 6 years ago

The terminus build:project:create d8 my-test-site command fails when performing the initial commit.

I think this line might be the source of the issue. It looks like single quotes don't work properly in Windows when creating a multi-word commit message. https://github.com/pantheon-systems/terminus-build-tools-plugin/blob/1f96df24977467467c6456d091b71ba6983d54fb/src/Commands/BuildToolsCommand.php#L801

The following is the error I get after running the command.

[notice] Running git -C C:\Users\username\AppData\Local\Temp\loc3251.tmp/my-test-site commit -m 'Initial commit'
error: pathspec 'commit'' did not match any file(s) known to git.
 [error]  Command `git -C C:\Users\username\AppData\Local\Temp\loc3251.tmp/my-test-site commit -m 'Initial commit'` failed with exit code 1
 [notice] A new Terminus version v1.8.0 is available.
You are currently using version v1.6.1.
You can update Terminus by running `composer update` or using the Terminus installer:
curl -O https://raw.githubusercontent.com/pantheon-systems/terminus-installer/master/builds/installer.phar && php installer.phar update
PHP Fatal error:  Uncaught Symfony\Component\Filesystem\Exception\IOException: Failed to remove file "C:\Users\username\AppData\Local\Temp\loc3251.tmp\my-test-site\.git\objects\fa\e394892bb7243a66bd7378bb159188314b7781": unlink(C:\Users\username\AppData\Local\Temp\loc3251.tmp\my-test-site\.git\objects\fa\e394892bb7243a66bd7378bb159188314b7781): Permission denied. in C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php:186
Stack trace:
#0 C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#1 C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#2 C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#3 C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\F in C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php on line 186

I'm running Windows 10, but I think any version of Windows will encounter this issue.

ghost commented 6 years ago

Looks like the following line has the same issue:

https://github.com/pantheon-systems/terminus-build-tools-plugin/blob/1f96df24977467467c6456d091b71ba6983d54fb/src/Commands/BuildToolsCommand.php#L1164

ghost commented 6 years ago

Here, too: https://github.com/pantheon-systems/terminus-build-tools-plugin/blob/1f96df24977467467c6456d091b71ba6983d54fb/src/Commands/BuildToolsCommand.php#L1334

dchaffin commented 6 years ago

@steigenTI - I was getting the same thing. I tried escaping the single quotes as well as swapping around the single and double quotes, but eventually just went with something like:

$this->passthru("git -C $repositoryDir commit -m initialCommit");

But now I'm getting:

[notice] Running git -C C:\Users\dchaf\AppData\Local\Temp\locF882.tmp/natural-alternative commit -q -m Build_assets_for_env_label
 [notice] Enabled git push mode for "dev"
 [notice] Running git -C C:\Users\dchaf\AppData\Local\Temp\locF882.tmp/natural-alternative push --force -q pantheon master
The authenticity of host '[codeserver.dev.1750d4a5-1d3d-4638-86bd-554a71a5d874.drush.in]:2222 ([104.197.139.155]:2222)' can't be established.
RSA key fingerprint is SHA256:yPEkh1Amd9WFBSP5syXD5rhUByTjaKBxQnlb5CahZZE.
Are you sure you want to continue connecting (yes/no)? Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
 [error]  Command `git -C C:\Users\dchaf\AppData\Local\Temp\locF882.tmp/natural-alternative push --force -q pantheon master` failed with exit code 128
PHP Fatal error:  Uncaught Symfony\Component\Filesystem\Exception\IOException: Failed to remove file "C:\Users\dchaf\AppData\Local\Temp\locF882.tmp\natural-alternative\.git\objects\ff\ff85b2bfcb87b79f702a07c55a5cbc5de4b580": unlink(C:\Users\dchaf\AppData\Local\Temp\locF882.tmp\natural-alternative\.git\objects\ff\ff85b2bfcb87b79f702a07c55a5cbc5de4b580): Permission denied. in C:\terminus\vendor\symfony\filesystem\Filesystem.php:186
Stack trace:
#0 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#1 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#2 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#3 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#4 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#5 C:\User in C:\terminus\vendor\symfony\filesystem\Filesystem.php on line 186

Fatal error: Uncaught Symfony\Component\Filesystem\Exception\IOException: Failed to remove file "C:\Users\dchaf\AppData\Local\Temp\locF882.tmp\natural-alternative\.git\objects\ff\ff85b2bfcb87b79f702a07c55a5cbc5de4b580": unlink(C:\Users\dchaf\AppData\Local\Temp\locF882.tmp\natural-alternative\.git\objects\ff\ff85b2bfcb87b79f702a07c55a5cbc5de4b580): Permission denied. in C:\terminus\vendor\symfony\filesystem\Filesystem.php:186
Stack trace:
#0 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#1 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#2 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#3 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#4 C:\terminus\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#5 C:\User in C:\terminus\vendor\symfony\filesystem\Filesystem.php on line 186
ghost commented 6 years ago

@dchaffin I was able to escape the characters like this:

 $this->passthru("git -C $repositoryDir commit -m \"Initial commit\""); 
$this->passthru("git -C $repositoryDir commit -m \"Export configuration\""); 
$this->passthru("git -C $repositoryDir commit -q -m \"Build assets for $env_label.\"");

Now I'm getting an error that the process doesn't have adequate permissions to unlink a file in my user's temp directory. Trying to figure that one out now...

...
 [notice]  - drush site-install standard --account-mail="myemail@gmail.com" --account-name=admin --account-pass="[REDACTED]" --site-mail="myemail@gmail.com" --site-name=my-test-site --yes
 [error]  Install site failed with exit code 255
PHP Fatal error:  Uncaught Symfony\Component\Filesystem\Exception\IOException: Failed to remove file "C:\Users\username\AppData\Local\Temp\locFE3C.tmp\my-test-site\.git\objects\ff\ff85b2bfcb87b79f702a07c55a5cbc5de4b580": unlink(C:\Users\username\AppData\Local\Temp\locFE3C.tmp\my-test-site\.git\objects\ff\ff85b2bfcb87b79f702a07c55a5cbc5de4b580): Permission denied. in C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php:186
Stack trace:
#0 C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#1 C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#2 C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\Filesystem->remove(Array)
#3 C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php(178): Symfony\Component\Filesystem\F in C:\Users\username\AppData\Roaming\Composer\vendor\symfony\filesystem\Filesystem.php on line 186
dchaffin commented 6 years ago

@steigenTI - Are you also getting the message as well?

Host key verification failed. fatal: Could not read from remote repository.

... as in my post above? Also, is your unlink issue similar to mine?

I've tried before line 1345 to insert:

$repositoryDir = str_replace("\\", "\\\\", $repositoryDir);

... thinking the single backslashes from Windows is messing it up (I tried something similar in Symfony's Filesystem.php as well to no avail). That did not work.

ghost commented 6 years ago

@dchaffin No, I am not getting that error. That sounds like you need to set up your ssh key in Pantheon. You can do this through your user settings.

After thinking about it for a while, I realized that the permissions error isn't the reason the command is failing. When the command fails, it cleans up after itself, deleting the project from Pantheon, CircleCI, GitHub, and then finally deleting the project directory on your machine. I'm pretty sure that permissions error happens during this step, so it's not the reason the install fails.

Instead, I think we need to focus on this portion of the output:

...
 [notice] Install the site on the dev environment
 [notice] Install site on my-test-site.dev
 [notice] Enabled on-server development via SFTP for "dev"
 [notice]  - drush site-install standard --account-mail="myemail@gmail.com" --account-name=admin --account-pass="[REDACTED]" --site-mail="myemail@gmail.com" --site-name=my-test-site --yes
 [error]  Install site failed with exit code 255

In particular, the line line with exit code 255. I think something is going wrong with the site install command. I'm not sure what's though, because I can't get to the logs once the Pantheon environment is destroyed.

dchaffin commented 6 years ago

@steigenTI It's taken me a while to work through all this, but I don't think I'm getting as far as you yet. I get to line 1345:

$this->passthru("git -C $repositoryDir push --force -q pantheon $branch");

... and that's where I'm getting the host key verification failed because it prompts to accept the RSA key fingerprint, but doesn't actually give me a chance to do so. It just continues as though I pressed no and gives me that message. I've force quit the process there and I can manually call:

git push --force -q pantheon master

... and it prompts me to accept that fingerprint and I do so and it asks for a password and then it will push to Pantheon. But the build tools are just bypassing those prompts and failing for me.

dchaffin commented 6 years ago

OK ... I figured out the RSA issue by re-generating an SSH key with an empty passphrase. Pantheon's instructions around that say, "Unless you're an advanced user, just press enter for every question." which would create the empty passphrase, but I missed that and/or just thought it didn't apply to that part - seemed like it should have one. Maybe the docs could call that out. Also, I added:

StrictHostKeyChecking no

... to my ssh_config.

Now, @steigenTI - I'm caught up with where you are.

dchaffin commented 6 years ago

@steigenTI - I found another issue around where we are stuck ... #131

dchaffin commented 6 years ago

@steigenTI - I temporarily commented out the deletion of the GitHub repo and the Pantheon site in the catch block of the createProject function:

// $ch = $this->createGitHubDeleteChannel("repos/$target_project", $github_token); // $data = $this->execCurlRequest($ch, 'GitHub'); if (isset($site)) { // $site->delete(); } throw $e;

So now I can see in Pantheon's php-error.log:

[01-May-2018 18:22:30 UTC] PHP Recoverable fatal error: PHP Startup: Cannot set 'user' save handler by ini_set() or session_module_name() in Unknown on line 0 [01-May-2018 18:22:32 UTC] PHP Notice: Undefined index: token in /srv/bindings/0a22f8996206496e9ad812e181195a2e/code/web/private/scripts/quicksilver/quicksilver-pushback/push-back-to-github.php on line 38 [01-May-2018 18:23:11 UTC] PHP Recoverable fatal error: PHP Startup: Cannot set 'user' save handler by ini_set() or session_module_name() in Unknown on line 0

If I try running drush site-install manually at that point, it generates more of the same error.

ghost commented 6 years ago

Looks like it might have something to do with the version of PHP? https://github.com/lando/lando/issues/747

@dchaffin Can you check the version of PHP being used in the environment?

ghost commented 6 years ago

Looks like the terminus build:project command pulls down https://github.com/pantheon-systems/example-drops-8-composer as the base for your project.

If it's pulling a version that is 1.3.3 or newer, the project will build with PHP 7.2, as defined in the pantheon.yml config file.

https://github.com/pantheon-systems/example-drops-8-composer/blob/69a8d2f0aa60164feceb74f44d901fff8bbdf75a/pantheon.yml#L3

I think this is where the base project is configured in the build tool plugin:

https://github.com/pantheon-systems/terminus-build-tools-plugin/blob/1f96df24977467467c6456d091b71ba6983d54fb/circle.yml#L24

~Since no version is specified, it's probably pulling master or the latest stable release.~ Looks like it's set up to use the dev-test release, but I can't find that.

If we can specify that it should use the 1.3.2 tag, it should use PHP 7.0. Maybe that will help resolve this issue?

dchaffin commented 6 years ago

@steigenTI - Perhaps. But I manually changed the pantheom.yml file to PHP 7.1 and then tried to manually run drush site-install and got the same error. I didn't try 7.0 yet.

dchaffin commented 6 years ago

I manually changed the pantheon.yml to PHP 7.0 and it made no difference.

ghost commented 6 years ago

Is the change reflected in the environment? Under settings > php version?

dchaffin commented 6 years ago

@steigenTI - Yes, it was.

ghost commented 6 years ago

After some poking around, I noticed that the d8 in terminus build:project:create d8 my-test-site is just shorthand for pantheon-systems/example-drops-8-composer and can be replaced with any base project you want.

So now I'm trying terminus build:project:create pantheon-systems/example-drops-8-composer:1.3.2 my-test-site.

I commented out lines 403-408 like you said, so my Pantheon environment won't get deleted upon failure. https://github.com/pantheon-systems/terminus-build-tools-plugin/blob/1f96df24977467467c6456d091b71ba6983d54fb/src/Commands/BuildToolsCommand.php#L402-L409

Now, after running command, only the following error is showing up in the logs:

Undefined index: token in /srv/bindings/29a329e1ba4c4a2b90c0a5f8d787984a/code/web/private/scripts/quicksilver/quicksilver-pushback/push-back-to-github.php on line 38

Starting to dig into this now.

ghost commented 6 years ago

Looks like it's coming from pantheon-systems/quicksilver-pushback v1.0.0

https://github.com/pantheon-systems/quicksilver-pushback/blob/7d77e3ec46d8504a00dcf96c12a87d09050c5fed/push-back-to-github.php#L38

ataylorme commented 5 years ago

Closing this as Terminus itself does not support Windows therefore this plugin will not support Windows either