Coder Social home page Coder Social logo

pantheon-systems / quicksilver-examples Goto Github PK

View Code? Open in Web Editor NEW
128.0 127.0 114.0 287 KB

Example scripts for using Pantheon's Quicksilver Platform Hooks

Home Page: https://docs.pantheon.io/guides/quicksilver

License: MIT License

PHP 100.00%
automation quicksilver

quicksilver-examples's Issues

New Relic API v2

Currently the New Relic example is using New Relic's v1 API. Seems that doesn't work anymore. Has anyone had success with v2?

Documentation referring to the `private` directory is unclear.

The documentation references a private directory, but it’s unclear where it goes. At the very bottom, the Troubleshooting sections says "pantheon.yml and private go in your site root, ie. your ~/code directory", but the problem is that private actually goes in your web root. So that’s either ~/code/ or ~/code/web/ if you have that set up differently (but pantheon.yml still goes in your ~/code/ root regardless). This needs to be cleaned up.

False positive quicksilver status on passthru

Issue Description:

The passthru usages will result in a false positive if the called command returns with non-zero exit code.

Suggested Resolution:

Check &$return_var value and raise an error to propagate the error to the calling quicksilver script.

$cmd = 'wp search-replace "://test-example.pantheonsite.io" "://example.com" --all-tables ';
passthru($cmd . ' 2>&1', $exit);
if (0 !== $exit) {
  trigger_error(sprintf('Command "%s" exit status: %s', $cmd, $exit), E_USER_ERROR);
}

Multidev creation hook times out

Using the Solr index example it times out after 175 seconds. This is fine except no sign of an error is displayed to the user unless watching workflows with Terminus, which we can't reasonably expect folks to do. It would be great if we could surface an error operations in Quicksilver hooks time out. In this case the Solr index operation takes about 20 minutes.

terminus workflow:watch solr-power
 [notice] Watching workflows...
 [notice] Finished workflow c554cc42-0985-11e7-8ce6-bc764e1141f9 Create a Multidev environment () at 2017-03-15 13:51:22
 [notice] ------ Operation: Index Solr Power items after multidev creation finished in 175s (slow-query) ------
Operation exceeded maximum execution time of 120 seconds.

Add Drupal 8 sanitization example

quicksilver-examples/db_sanitization/db_sanitization_drupal.php is named "Drupal" but it won't work for Drupal 8 because the password and such is in users_field_data, not users.

Please add an example of sanitizing a D8 database and mark the other Drupal script as being for D7.

Slack notifications not passing on commit details

Using the example slack_notifications.php, the commit ID and message weren't being passed on to Slack. It looks like $fields array wasn't merged properly. To resolve, I changed the following from line 78:

    $fields += array(
      array(
        'title' => 'Commit',
        'value' => rtrim($hash),
        'short' => 'true'
      ),
      array(
        'title' => 'Commit Message',
        'value' => $message,
        'short' => 'false'
      )
    );

To this:

    $fields[] = array(
      'title' => 'Commit',
      'value' => rtrim($hash),
      'short' => 'true'
    );
    $fields[] = array(
      'title' => 'Commit Message',
      'value' => $message,
      'short' => 'false'     
    );

Possibly the numeric keys generated by PHP for the second array start at 0 so are ignored when using +=.

Add Loader.io example

I have used Loader.io in Quicksilver demos and should bring over my code to this repo. It also includes some Slack reporting.

The purpose of the script is to trigger a load test of Test or Live upon deployment.

Can sync_code detect a git tag creation?

Hello;

I don't know if it is an issue and I am unsure of here being the right place to ask for help (or pantheon support?).

Is there a way to hook, not on a git commit but on a git tag creation?

my workflow:

workflows:
sync_code:
after:
- type: webphp
description: Notification.
script: private/scripts/my_script.php

is working well when there is a commit. But nothing is happening for tag, sync_code does not seem to capture their creation.

Is there a way to do so?

Gerald

Determine directory structure

How should we organize this repository?
@newtoid @greg-1-anderson

I'm thinking:

Option 1

  • pantheon.yml files/
  • webphp files/
  • script-type 2 files/

Option 2

Where full site examples make more sense together than apart, I think that the directories here should house sets of quicksilver stuff that all works together, grouped by type. Each example folder would house a set of scripts used for a site. It would result in redundant code, however...

  • example type 1/
    • example 1-1/
    • example 1-2/
  • example type 2/
    • example 2-1/
    • example 2-2/

Reducing secrets.json credential overlap or confusion

I noticed while adding the Diffy Visual Regression Quicksilver script, that username is quite generic. Now, I know for myself, I can change that username secret key in the PHP file to something like diffy_username but I'm not sure if others get that. So, if the key username is used for all script examples, do you think any customers will take pause because they already may have that key used in their secrets file (and not realize it's trivial to update the key accessed in secrets.json)?

Example wanted: Post Solr schema after creating new multidev env with Drupal

Related to #62, we tried to implement the "autoposting" solr schema using the create_cloud_development_environment event with no luck.

On our pantheon.yml file we have this:

api_version: 1

workflows:
  create_cloud_development_environment:
    after:
      - type: webphp
        description: Enables Solr backend
        script: private/quicksilver-scripts/configure_solr.php

Then, we have the configure_solr.php file, that contains the next code:

<?php
// Prevent this script to be executed out of pantheon.
if (!defined('PANTHEON_ENVIRONMENT') || (PANTHEON_ENVIRONMENT === 'live')) {
  return;
}

// Bootstrap Drupal using the same technique as is in index.php.
define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
$default_path = 'sites/all/modules/apachesolr/solr-conf/solr-3.x/schema.xml';
$schema_path = variable_get('pantheon_apachesolr_schema', $default_path);
pantheon_apachesolr_post_schema_exec($schema_path);

But this code is not working and I can not figure out why. Also, I tried to debug it following the steps mentioned in the troubleshooting part of the quicksilver documentation, it says to use terminus workflow:list to get the logs. I just created a new multidev environment and it does not even appear on the list of workflows, so is not possible to get the logs.

Example wanted: Setting New Relic Apdex configuration upon Multidev creation

I've been doing some profiling of PHP 5.6 vs. PHP 7 and in doing so, I've been creating a lot of Multidev environments.

As I do, I'm reminded that the Apdex T value and alert policy is unique for each environment. If there isn't a way to set default values in New Relic for new Multidevs, it should be fairly trivial to do so with with the REST API called from Quicksilver.

For example:

curl -X PUT 'https://api.newrelic.com/v2/applications/123456789.json' \
     -H 'X-Api-Key:12344567890QWERQASDFASDFZXCV' -i \
     -H 'Content-Type: application/json' \
     -d \
'{
  "application": {
    "name": "string",
    "settings": {
      "app_apdex_threshold": "1",
      "end_user_apdex_threshold": "3",
      "enable_real_user_monitoring": "boolean"
    }
  }
}' 

@ari-gold, @joshkoenig, @ataylorme, Should this be done some other way? If not, I'll make a PR to add this example.

Environment url & protocol in payload

Having the environment url and protocol in the payload would be nice.

Use case: post-deployment url status checker (which could also serve as a cache warmer)

An array of URLs are defined to be checked with Guzzle for returning status 200 after deployment.

It would be nice if the base environment url was available, including protocol if the site is secured (for sites that are setup to restrict requests to https).

If this were the case, the script would only need one set of uris defined, which appended a base url, for status checking across multiple environments.

What environment variables are available?

Are any environment variables available to our scripts? Specifically I would like to know which environment the script is being run on (dev, test, live, or which multidev).

This might be the uri for the environment, e.g. test-mysite.pantheonsite.io

Bootstrapping drupal not working with Quicksilver?

In this script:

https://github.com/pantheon-systems/quicksilver-examples/blob/master/db_sanitization/db_sanitization_drupal.php

I have a simplified version which can not seem to bootstrap drupal.

<?php
echo "\n\n";
echo "\n========= START DB POST ===========\n";
if (defined('PANTHEON_ENVIRONMENT') && ($_ENV['PANTHEON_ENVIRONMENT'] !== 'live')) {
  echo "\nON PANTHEON\n";
  define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  echo "\nBEFORE BOOTSTRAPPING\n";
  drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  echo "\nBOOTSTRAPPED DRUPAL\n";
} else {
  echo "\nNOT ON PANTHEON\n";
}
echo "\n========= END DB POST ===========\n";
echo "\n\n";

And line by line I commented stuff out to see where it fails. Everything runs fine until after the line with the "BEFORE BOOSTRAPPING" message. But when the next line executes it fails with this message:

PANTHEON ERROR:

Expected status 200, got: 301 while running your Quicksilver operation.

Please check your script path is correct and try again.

Has anyone gotten the Quicksilver system to successfully boostrap drupal? If so how?

Thank you!

diffy.website integration is unnecessarily tedious

I've tested the diffy.website integration and though on paper it looks great in reality it's a big hassle and won't work as you would expect (https://github.com/pantheon-systems/quicksilver-examples/tree/main/diffy_visualregression)

A conceptual issue I found with it is that it should trigger after a deploy but also including a db clone. Otherwise the comparison doesn't make sense. test and live need to be copies of each other for this to be useful.

At the moment, the included example triggers on deploy.after - but this doesn't trigger when the deploy+database/file cloning is done. It triggers before that. This way deploys to test become a two step process: clone db and files, then deploy. It would be much more useful if this could be done just in one step and help to automate testing

Add curl timeout to New Relic API request, to prevent hung php worker / failed deploy workflow

It would be great to add a timeout to the curl request somewhere around here:
https://github.com/pantheon-systems/quicksilver-examples/blob/master/new_relic_deploy/new_relic_deploy.php#L63L69

As php does not count external processing toward php timeout, it will cause the php worker to hang in case New Relic fails to respond. This will also cause the Deploy workflow to be marked as failed on the site's Dashboard.
http://php.net/manual/en/info.configuration.php#ini.max-execution-time
http://php.net/manual/en/function.set-time-limit.php#refsect1-function.set-time-limit-notes

Internal support ticket reference:
120299

Feature request: Site level object store

It seems like a common task is going to be storing config data for the scripts. (credentials, service endpoints, etc...)

JSON configs are fine for static data, but it would be pretty nice for the scripts to have access to a site-level object store for both static and dynamic use.

Besides an easier way to store and retrieve script data, it would be nice if the data persisted at a global (site) level rather than an environment level. This way when a file system is blown out by a copy, the data would not be lost.

If a site level db service is out of the question, maybe access to write files at a site level directory would be sufficient. The author could maintain an sqlite db if they needed anything fancy. A site level service with a simple getter/setter wrapper functions available to the scripts would provide for a nice way to standardize though.

Documentation unclear on script placement

Hello,

I was trying to test out the provided slack notification quicksilver examples and was a bit confused as you speak about the repository and the private files repo at different locations.

Should I be storing the slack notification in:

{repo root}/private/scripts/slack_after_deploy.php?

Or do you mean for me to run the ftp command to deploy the php to the private files folder similar to the JSON with secret?

Quicksilver task times out with no notification

I"m adding this issue here on the advice of Zvi Epner at Pantheon support.

I have the following simple test script:

<?php
print 'QS test script';
passthru("wp search-replace https://www.marsdd.com http://db-clean-www-marsdd-com.pantheonsite.io —verbose 2>&1");
  • It does not appear to run
  • No output appears from it in the workflow log (even the first print statement)
  • No failure states are mentioned in the workflow log
  • When I remove the passthru statement the print output shows up in the workflow log

wp search-replace is quite a long running process. I suspect it is being killed by a timeout, or other resource limitation. A mention of it does happen in php slow log. Zvi was unable to confirm or deny this though, and I don't see any documentation of resource limitations for quicksilver anywhere.

It might be nothing to do with that though. It would be great if someone could look into this and give me a hint as to what might be going wrong.

Create OWNERS file

Maybe we should add an OWNERS file that specifies who is responsible for maintaining this project, with a comment documenting the process for approvals.

An owner is required to merge, and they’ll want a +1 from another owner

Deploy Message that fires "Before" is Different from "After"

When running a script before deployment starts, the correct deployment message should be displayed. Right now it is displaying the $annotation from the previous deployment.

image

Whether implementing a hook before or after a deployment, references to the $annotation should be consistent, right?

Slack Notifications don't work with multidev

Hi,

After testing the slack notifications, they don't work when actions are executed on multidev with the pantheon.yml specified in the readme.md

This includes code sync, clear cache, creating new cloud environment.

Thanks,

Dominique

Edit readme to make it clearer

In file https://github.com/pantheon-systems/quicksilver-examples/blob/master/slack_notification/README.md, change "Add, and update as needed, the example slack_notification.php script to the private directory in the root of your site's codebase, that is under version control. Note this is a different private directory than where the secrets.json is stored."
For: "Add, and update as needed, the example slack_notification.php script to the private directory in the root of your site's codebase, that is under version control. It should be located under code/private/scripts/slack_notification.php."

URL Checker value always 1

Issue
The issue is that when you run the current version of the URL checker the value is always 1.

Solution
In function url_checker_build_output() it uses count($failed) as opposed to the actual $failed value.

I've created a patch, but it won't let me add it:


diff --git a/url_checker/url_checker.php b/url_checker/url_checker.php
index c58e51d..103d49d 100644
--- a/url_checker/url_checker.php
+++ b/url_checker/url_checker.php
@@ -83,7 +83,7 @@ function url_checker_build_output($results, $failed) {
   foreach ($results as $item) {
     $output .= '  ' . $item['status'] . ' - ' . $item['url'] . "\n";
   }
-  $output .= "--------\n" . count($failed) . " failed\n\n";
+  $output .= "--------\n" . $failed . " failed\n\n";
   return $output;
 }
 

Sanitization example- correct for D7?

I may be doing it wrong, but the sanitization example does not seem to be correct for resetting the password on Drupal 7.

When I use the statement:

db_query("UPDATE users SET pass = MD5(CONCAT('MILDSECRET', name));");

And then try to log in, it won't accept the password. The sanitation script references this blog post, http://crackingdrupal.com/blog/greggles/creating-sanitized-drupal-database-dump#comment-164, which is dated to 2010, a year before Drupal 7 was released.

Can the example be updated to handle Drupal 7 as well?

EDIT:

The real goal here is to have a way to do basic DB sanitization (email addresses and passwords) in D7. It doesn't matter if it uses Drush or some other way, but I want to be able to log in as [email protected] with password "password". (in other words, more or less the default behavior of drush sql-sanitize)

[docs] Timeout 60 seconds

It appears the timeout for a script with multiple drush commands is 60 seconds. The README.md in one of the examples (config-import) says the timeout is 120 seconds. I would like to see some clarification in the docs about drush timeouts vs quicksilver timeouts.

shell_exec("drush pm-list --format=json") doesn't seem to work.

If I change it to:
shell_exec("drush pm-list --format=json 2>&1");

I get:
Unknown option: --format. See drush help pm-list for available [error]
options. To suppress this error, add the option --strict=0.

If I use terminus to execute the command it works correctly, but using quicksilver it doesn't seem to work.

Example wanted: Using terminus command from within php script

I'm trying to make sure our dev site always build from the live DB on each push. I was thinking to use terminus to get the latest live DB and import it in to the deb DB before deploying the lastest dev code but I'm not quite sure how to do that from the existing examples. Is it possible for one to be created?

Documentation for self-referential updates to scripts / pantheon.yml

While working on updating slack to use attachments, I saw behavior that is inconsistent with the following statement in the documentation:

"Likewise, if you are adding new operations or changing the script an operation will target, the deploy which contains those adjustments to pantheon.yml will not self-referentially exhibit the new behavior. Only subsequent deploys will be affected."

Just to clarify, updates made to the referenced scripts are executing for me on the first push, but the statement here refers to the registry of which scripts to run within pantheon.yml, and how they don't run self-referentially on the same commit, correct?

Or is it perhaps it's the fact that I've been working on a script that fires after deploy?

Finding log file for quicksilver

Hello,

My goal is to notify AWS SNS (the Notification Service) when something is pushed on our repo.

I deployed a php file, a file with some secrets and a pantheon.yml.

I had the :

Successfully applied pantheon.yml to the 'dev' environment.

Where to read the logs to determine why it is not working? Which file?

Thanks

Gerald

undefined variable: deploy tag in new_relic_deploy.php script

Getting the following notice after deploying code changes to Test env.

Undefined variable: deploy_tag in /srv/bindings/ed851365e8b24fbdb2c5e19bbe784cab/code/private/scripts/new_relic_deploy.php on line 51

It seems to be working in Live.

Any thoughts?

QuickSilver Examples Don't work with Private Slack Channels

Once I had this properly configured, it looks like the WebHook doesn't think that the private channel is a real channel.

e.g.

Choose workflow: 1
+----------+--------------------------------------+
| Key      | Value                                |
+----------+--------------------------------------+
| Id       | e550e8f4-bfa4-11e5-8b9c-bc764e10d7c2 |
| Env      | dev                                  |
| Workflow | Sync code on "dev"                   |
| User     | Pantheon                             |
| Status   | finished                             |
| Time     | 26s                                  |
+----------+--------------------------------------+
+-------------+--------------------------------------+-----------+----------+
| Type        | Operation Description                | Result    | Duration |
+-------------+--------------------------------------+-----------+----------+
| platform    |                                      | succeeded | 0s       |
| platform    |                                      | succeeded | 16s      |
| quicksilver | post to slack after each code pushed | succeeded | 7s       |
+-------------+--------------------------------------+-----------+----------+

------ Operation: post to slack after each code pushed finished in 7s ------

==== Posting to Slack ====
RESULT: Invalid channel specified
===== Post Complete! =====

private directory does not exist?

We do not have a private directory "in our code repo" on the dev env (at least not according to sftp). In your readme the mkdir command is mentioned in order to get the secrets file on the specific dev environment but that is in the sites/default/files directory and not the root directory.

On Acquia the private dir is above the htdocs dir so that it is outside of the repo on purpose. It seems like you are suggesting we have two private directories, namely:

  • root/sites/default/files/private (which is where secrets.json file lives)
  • root/private/scripts/ (which is where slack_notifications.php lives)

where root is the git root or (/srv/bindings/!@#!@#!@#!@#@!/)

Is that correct? If so, you should mention the necessary mkdir command in the README.md .

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.