Skip to content

Instantly share code, notes, and snippets.

@uberhacker
Created January 25, 2016 23:00
Show Gist options
  • Save uberhacker/295fee90b3ce4153d3ab to your computer and use it in GitHub Desktop.
Save uberhacker/295fee90b3ce4153d3ab to your computer and use it in GitHub Desktop.
Contents of pantheon.yml:
---
api_version: 1
workflows:
# Commits: Notify team of new commit to master (dev)
sync_code:
after:
- type: webphp
description: post to slack after each code pushed
script: private/quicksilver/slack/sync_notification.php
# Database Clones: Notify, sanitize, and notify on db clone
#clone_database:
# before:
# - type: webphp
# description: post to slack before cloning the database
# script: private/quicksilver/slack/before_db_clone.php
# after:
# - type: webphp
# description: sanitize the db after each database Clone
# script: private/quicksilver/sanitize_after_db_clone.php
# - type: webphp
# description: post to slack after the database clones
# script: private/quicksilver/slack/after_db_clone.php
# Code Deploys: Notify, Sanitize (if on test), post to new relic, update db, and notify completion
deploy:
#before:
# - type: webphp
# description: post to slack before cloning the database
# script: private/quicksilver/slack/deploy_notification.php
after:
# - type: webphp
# description: post to new relic always
# script: private/quicksilver/new_relic/post_after_deploy.php
# - type: webphp
# description: sanitize the db after deploy to test
# script: private/quicksilver/sanitize_after_db_clone.php
# - type: webphp
# description: pull configuration into the database
# script: private/quicksilver/config_pull_after_deploy.php
- type: webphp
description: post to slack after each deploy
script: private/quicksilver/slack/deploy_notification.php
# Cache Clears: Post to slack after clearing cache
clear_cache:
after:
- type: webphp
description: post to slack after cache clear
script: private/quicksilver/slack/clear_cache_notification.php
Contents of sync_notification.php:
<?php
// Get the committer, hash, and message for the most recent commit.
$committer = `git log -1 --pretty=%cn`;
$message = `git log -1 --pretty=%B`;
$hash = `git log -1 --pretty=%h`;
// Load our hidden credentials.
// See the README.md for instructions on storing secrets.
$secrets = json_decode(file_get_contents($_SERVER['HOME'] . '/files/private/secrets.json'), 1);
if ($secrets == FALSE) {
die('No secrets file found. Aborting!');
}
isset ($secrets['slack_channel']) ? $channel = $secrets['slack_channel'] : $channel = '#quicksilver';
// Prepare the slack payload as per:
// https://api.slack.com/incoming-webhooks
// TODO: use awesome attachment-style formatting.
// https://api.slack.com/docs/attachments
$text = 'Code sync to the ' . $_ENV['PANTHEON_ENVIRONMENT'] . ' environment of ' . $_ENV['PANTHEON_SITE_NAME'] . ' by ' . $_POST['user_email'] . "!\n";
$text .= 'Most recent commit: ' . rtrim($hash) . ' by ' . rtrim($committer) . ': ' . $message;
$post = array(
'username' => 'Pantheon-Quicksilver',
'text' => $text,
'channel' => $channel,
'icon_emoji' => ':lightning_cloud:'
);
$payload = json_encode($post);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $secrets['slack_url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
print("\n==== Posting to Slack ====\n");
$result = curl_exec($ch);
print("RESULT: $result");
print("\n===== Post Complete! =====\n");
curl_close($ch);
Contents of clear_cache_notification.php:
<?php
// Find out what tag we are on and get the annotation.
$deploy_tag = `git describe --tags`;
$annotation = `git tag -l -n99 $deploy_tag`;
// Load our hidden credentials.
// See the README.md for instructions on storing secrets.
$secrets = json_decode(file_get_contents($_SERVER['HOME'] . '/files/private/secrets.json'), 1);
if ($secrets == FALSE) {
die('No secrets file found. Aborting!');
}
isset ($secrets['slack_channel']) ? $channel = $secrets['slack_channel'] : $channel = '#quicksilver';
// Prepare the slack payload as per:
// https://api.slack.com/incoming-webhooks
// TODO: use awesome attachment-style formatting.
// https://api.slack.com/docs/attachments
$text = 'Cache clear in the '. $_ENV['PANTHEON_ENVIRONMENT'];
$text .= ' environment of '. $_ENV['PANTHEON_SITE_NAME'] .' by '. $_POST['user_email'] .' complete!';
$text .= ' <https://dashboard.pantheon.io/sites/'. PANTHEON_SITE .'#'. PANTHEON_ENVIRONMENT .'/deploys|View Dashboard>';
$text .= "\n\n*DEPLOY MESSAGE*: $annotation";
$post = array(
'username' => 'Pantheon-Quicksilver',
'text' => $text,
'channel' => $channel,
'icon_emoji' => ':lightning_cloud:'
);
$payload = json_encode($post);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $secrets['slack_url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
print("\n==== Posting to Slack ====\n");
$result = curl_exec($ch);
print("RESULT: $result");
print("\n===== Post Complete! =====\n");
curl_close($ch);
Command to cache clear including terminus workflows watch output:
vagrant@debian:~$ terminus —site=jouer-cosmetics —env=dev drush "cc all"
[2016-01-23 15:07:32] [info] Running drush cc all on jouer-cosmetics-dev
cmd: 'cc all'
site: 'jouer-cosmetics'
env: 'dev'
'all' cache was cleared in [success]
/srv/bindings/e7e8db41e54549058a0841ab139a2dbc/code#dev-jouer-cosmetics.pantheon.io
vagrant@debian:~$ [2016-01-23 15:07:56] [info] Started 0fb6d154-c1e3-11e5-8d0c-bc764e10d7c2 Clear edge cache for "dev" (dev)
[2016-01-23 15:07:56] [info] Finished Workflow 0fb6d154-c1e3-11e5-8d0c-bc764e10d7c2 Clear edge cache for "dev" (dev)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment