profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/jfarrell/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

heronproject/apache-proposal 22

Apache Incubator Proposal for Heron

acquia/fluent-plugin-sumologic-cloud-syslog 2

Fluentd plugin to send logs to the Sumologic cloud syslog collectors

jfarrell/bazel-sandbox 2

Playground used while creating custom rules for Google Bazel

jfarrell/elasticsearch 2

Open Source, Distributed, RESTful Search Engine

acquia/cloud-data-base 1

Acquia Cloud Data team base docker build image

jfarrell/docker-cassandra 1

Docker container for Apache Cassandra

acquia/Baragon 0

Load balancer API

acquia/collectd-fluentd 0

Collectd plugin to monitor Fluentd

acquia/Diamond 0

Diamond is a python daemon that collects system metrics and publishes them to Graphite (and others). It is capable of collecting cpu, memory, network, i/o, load and disk metrics. Additionally, it features an API for implementing custom collectors for gathering metrics from almost any source.

acquia/garethr-docker 0

Puppet module for managing docker

issue commentacquia/cloud-hooks

updated examples for Drupal 8

Drupal 9 / Drush 10 too please.

shelane

comment created time in a month

issue commentacquia/cloud-hooks

Varnish Purge Cloud Api example

@jameswilson Nice and thanks for circling back! I'm glad we both arrived at a similar solution!

I didn't particularly like how much I was having to hardcode the application uuid and environment ids and such, so I added a few more APIs calls so that all it needs to know is what Acquia $target_env it's running under and then it queries the API and parses out the application uuid, environment id, and the domains associated with that specific environment. So when I'm doing a post-code-deploy hook in dev it's only going to clear the domains that I've added under the dev environment in Acquia. And yes it does pull back the default Acquia domains (exampledev.prod.acquia-sites.com) as well as any real, customer-facing domains you've added (dev.example.com).

#!/bin/sh
#
# Cloud Hook: post-code-deploy

site="$1"
target_env="$2"
source_branch="$3"
deployed_tag="$4"
repo_url="$5"
repo_type="$6"

# Fallback to the dev target environment if target_env isn't set to an expected environment
if [[ "$target_env" != 'dev' && "$target_env" != 'test' && "$target_env" != 'prod' ]]; then
  target_env="dev"
fi

# Load the Acquia Cloud API settings file, which is stored on the root of the user directory on the Acquia server
. $HOME/$target_env/files/acquia_varnish_keys

client_key="$ACQUIA_CLIENT_KEY"
client_secret="$ACQUIA_CLIENT_SECRET"

# Generate an access token
access_token=$(curl https://accounts.acquia.com/api/auth/oauth/token --data-urlencode "client_id=$client_key" --data-urlencode "client_secret=$client_secret" --data-urlencode "grant_type=client_credentials" | grep -Po '"'"access_token"'"\s*:\s*"\K([^"]*)')

# Get the application uuid filtering where the name field is "Example"
application_uuid=$(curl -X GET --header "Authorization: Bearer $access_token" --header "Content-Type: application/json" "https://cloud.acquia.com/api/applications?filter=name%3DExample" | grep -Po '"'"uuid"'"\s*:\s*"\K([^"]*)' | head -1)

# Get the environment id for the target environment
environment_id=$(curl -X GET --header "Authorization: Bearer $access_token" --header "Content-Type: application/json" "https://cloud.acquia.com/api/applications/$application_uuid/environments?filter=name%3D$target_env" | grep -Po '"'"id"'"\s*:\s*"\K([^"]*)')

# Parses the hostname from domains json response, loops through the number of domains, and wraps them in valid json leaving the comma off the last item
domains_json="{\"domains\": ["
domains_json+=$(curl -X GET --header "Authorization: Bearer $access_token" --header "Content-Type: application/json" "https://cloud.acquia.com/api/environments/$environment_id/domains" | grep -Po '"'"hostname"'"\s*:\s*"\K([^"]*)' | sed 's/^/\"/;s/$/\"/;$!s/$/\,/')
domains_json+="]}"

# Clear Varnish cache for the specified domains attached to this environment
curl -X POST --header "Authorization: Bearer $access_token" --header "Content-Type: application/json" --data "$domains_json" "https://cloud.acquia.com/api/environments/$environment_id/domains/actions/clear-varnish"

jameswilson

comment created time in 3 months

issue commentacquia/cloud-hooks

Varnish Purge Cloud Api example

Hi @wesleymusgrove .

Your idea to fetch the domain lists from the API is smart. I wonder does that handle both the Acquia domains and the project real domains for all environments?

Also, I'd totally forgotten about this issue, and have long since written a very similar looking script. It looks like we're using SED instead of GREP. I place the following in hooks/common/post-code-deploy/cache.sh and hooks/common/post-code-update/cache.sh for all of our drupal 8/9 sites in Acquia, and modify the ENV

#!/bin/sh

# Store Acquia API credentials in the home folder on Acquia servers:
#  CLIENT_ID=SOMEIDVALUEHERE
#  CLIENT_SECRET=ANOTHERVALUE
. $HOME/.acquia-secret

site="$1"
target_env="$2"

docroot="/var/www/html/$site.$target_env/docroot"

if [ $target_env = 'test' ]
then
ENV="11111-11111111-1111-1111-1111-111111111111"
BODY='{"domains": ["examplestg.prod.acquia-sites.com","test.example.com"]}'
fi

if [ $target_env = 'dev' ]
then
ENV="22222-22222222-2222-2222-2222-222222222222"
BODY='{"domains": ["exampledev.prod.acquia-sites.com","dev.example.come"]}'
fi

if [ $target_env = 'prod' ]
then
ENV="33333-33333333-3333-3333-3333-333333333333"
BODY='{"domains": ["example.prod.acquia-sites.com","example.com"]}'
fi

TOKEN=$(curl -X POST -d "client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&grant_type=client_credentials" https://accounts.acquia.com/api/auth/oauth/token | sed -E 's/.*access_token\"\:\"([^\"]+)\".*/\1/');

curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -d "$BODY" https://cloud.acquia.com/api/environments/$ENV/domains/actions/clear-varnish

# Complete DevOps commands (these are optional and unrelated to this issue)
# DRUSH_CMD="/var/www/html/$site.$target_env/vendor/bin/drush --root=$docroot"
# 
# $DRUSH_CMD @$site.$target_env cache:rebuild
# $DRUSH_CMD @$site.$target_env updatedb
# $DRUSH_CMD @$site.$target_env config:import --yes
# $DRUSH_CMD @$site.$target_env cohesion:rebuild
jameswilson

comment created time in 3 months

issue commentacquia/cloud-hooks

Varnish Purge Cloud Api example

Also if you don't want to hardcode your domain lists, you can fetch those from the API as well, spin through the results grepping for hostname, and use sed to format those into the valid JSON request that the varnish request is expecting you to pass in.

# Parses the hostname from domains json response, loops through the number of domains, and wraps them in valid json leaving the comma off the last item
# https://stackoverflow.com/questions/35021524/how-can-i-add-a-comma-at-the-end-of-every-line-except-the-last-line
domains_json="{\"domains\": ["
domains_json+=$(curl -X GET --header "Authorization: Bearer $access_token" --header "Content-Type: application/json" "https://cloud.acquia.com/api/environments/$environment_id/domains" | grep -Po '"'"hostname"'"\s*:\s*"\K([^"]*)' | sed 's/^/\"/;s/$/\"/;$!s/$/\,/')
domains_json+="]}"
jameswilson

comment created time in 3 months

issue commentacquia/cloud-hooks

Varnish Purge Cloud Api example

Hi @paqu83 @KCarlile @jameswilson,

It took a little finagling, but I finally got a working bash script that:

  • Generates an Acquia Cloud v2 API token using OAuth based on a client key and secret created in your Acquia account
  • Parses the access_token json from curl output and stores it in a variable
  • Clears the Varnish cache for the specified domains attached to a specified Acquia environment

It was interesting to piece together the Acquia https://cloudapi-docs.acquia.com/#/Environments/postEnvironmentsDomainsClearVarnish POST request without a working example readily available. The only way I could figure out what the environmentId was supposed to be was going to my application in Acquia's dashboard and grabbing it from the URL. I didn't see this officially documented anywhere.

#!/bin/sh
#
# Cloud Hook: post-code-deploy
#
# The post-code-deploy hook is run whenever you use the Workflow page to
# deploy new code to an environment, either via drag-drop or by selecting
# an existing branch or tag from the Code drop-down list. See
# ../README.md for details.
#
# Usage: post-code-deploy site target-env source-branch deployed-tag repo-url
#

site="$1"
target_env="$2"
source_branch="$3"
deployed_tag="$4"
repo_url="$5"
repo_type="$6"

# Generates an Acquia Cloud v2 API token using OAuth based on a client key and secret created in your Acquia account
# https://cloud.acquia.com/a/profile/tokens
# https://docs.acquia.com/cloud-platform/develop/api/auth/
# https://docs.acquia.com/cloud-platform/develop/api/migrate/

# Load the Acquia CLIENT_KEY and CLIENT_SECRET values from outside this repo
. $HOME/acquia_varnish_settings

client_key="$CLIENT_KEY"
client_secret="$CLIENT_SECRET"

if [ "$target_env" = 'dev' ]; then
  environment_id="11111-abc12345-1abc-2345-ab67-8a90bc1abcde"
  domains_json="{\"domains\": [\"exampledev.prod.acquia-sites.com\",\"dev.example.com\"]}"
elif [ "$target_env" = 'test' ]; then
  environment_id="22222-abc12345-1abc-2345-ab67-8a90bc1abcde"
  domains_json="{\"domains\": [\"examplestg.prod.acquia-sites.com\",\"stg.example.com\"]}"
elif [ "$target_env" = 'prod' ]; then
  environment_id="11111-abc12345-1abc-2345-ab67-8a90bc1abcde"
  domains_json="{\"domains\": [\"example.prod.acquia-sites.com\",\"www.example.com\"]}"
else
  environment_id="12345-abc12345-1abc-2345-ab67-8a90bc1abcde"
  domains_json="{\"domains\": [\"exampledev.prod.acquia-sites.com\",\"dev.example.com\"]}"
fi

# Parses the access_token json from curl output and stores it in a variable
# https://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools#comment42500081_1955505
# https://askubuntu.com/questions/714458/bash-script-store-curl-output-in-variable-then-format-against-string-in-va
access_token=$(curl https://accounts.acquia.com/api/auth/oauth/token --data-urlencode "client_id=$client_key" --data-urlencode "client_secret=$client_secret" --data-urlencode "grant_type=client_credentials" | grep -Po '"'"access_token"'"\s*:\s*"\K([^"]*)')

# Clears the Varnish cache for the specified domains attached to a specified Acquia environment
# https://cloudapi-docs.acquia.com/#/Environments/postEnvironmentsDomainClearVarnish
curl -X POST --header "Authorization: Bearer $access_token" --header "Content-Type: application/json" --data "$domains_json" "https://cloud.acquia.com/api/environments/$environment_id/domains/actions/clear-varnish"

jameswilson

comment created time in 3 months