Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o one commit to start fresh in pantheon-systems
  • Loading branch information
stevector committed Jul 14, 2017
0 parents commit 2a496ce
Show file tree
Hide file tree
Showing 18 changed files with 3,321 additions and 0 deletions.
103 changes: 103 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
###
### GitHub repository .gitignore section
###

# Ignore directories generated by Composer
/vendor/

# Webroot #
###########
!web/
web/*
!web/index.php
!web/wp-cli.yml
!web/wp-config.php
!web/wp-content/
web/wp-content/*
!web/wp-content/mu-plugins/
web/wp-content/mu-plugins/*
!web/wp-content/mu-plugins/alter_wpcfm_config_path.php
!web/wp-content/plugins/
web/wp-content/plugins/*
!web/wp-content/themes
web/wp-content/themes/*
!web/wp-content/themes/twentyseventeen-child/
!web/wp-content/config/
!web/private/
web/private/*
!web/private/config/
!web/private/scripts/

# Add directories containing build assets below.
# Keep all additions above the "cut" line.

# This distinction is only important when using this
# repository as a custom upstream. The .gitignore file
# is not modified in the GitHub PR workflow.


# :::::::::::::::::::::: cut ::::::::::::::::::::::

###
### Pantheon site .gitignore section
###
### Items below the "cut" line are still ignored on
### the Pantheon site. Items above the "cut" line
### are ignored in the GitHub repository, but committed
### to the Pantheon repository.
###

# Ignore Drupal's file directory
/web/sites/*/files/

# Ignore Drupal's file directory
web/sites/default/files

# Pantheon commits a settings.php for environment-specific settings.
# Place local settings in settings.local.php
web/sites/*/settings.local.php
web/sites/*/services*.yml

# Ignore SimpleTest multi-site environment.
web/sites/simpletest

# Ignore files generated by PhpStorm
.idea

# Packages #
############
*.7z
*.dmg
*.gz
*.bz2
*.iso
*.jar
*.rar
*.tar
*.zip
*.tgz

# Logs and databases #
######################
*.log
*.sql

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon

Thumbs.db
._*

# Vim generated files #
######################
*.un~

# SASS #
##########
.sass-cache

# Things in the core directory that Drupal 8 commits in the repository.
!web/core/**/*.gz
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Reload!

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Example WordPress Composer


This repository is a start state for a Composer-based WordPress workflow with Pantheon. It is meant to be copied by the the [Terminus Build Tools Plugin](https://github.com/pantheon-systems/terminus-build-tools-plugin) which will set up for you a brand new

* GitHub repo
* Free Pantheon sandbox site
* A CircleCI configuration to run tests and push from the source repo (GitHub) to Pantheon.

For more background information on this style of workflow, see the [Pantheon documentation](https://pantheon.io/docs/guides/github-pull-requests/).


## Installation

#### Prerequisites

Before running the `terminus build:project:create` command, make sure you have all of the prerequisites:

* [A Pantheon account](https://dashboard.pantheon.io/register)
* [Terminus, the Pantheon command line tool](https://pantheon.io/docs/terminus/install/)
* [The Terminus Build Tools Plugin](https://github.com/pantheon-systems/terminus-build-tools-plugin)
* An account with GitHub and an authentication token capable of creating new repos.
* An account with CircleCI and an authentication token.

You may find it easier to export the GitHub and CircleCI tokens as variables on your command line where the Build Tools Plugin can detect them automatically:

```
export GITHUB_TOKEN=[REDACTED]
export CIRCLE_TOKEN=[REDACTED]
```

#### One command setup:

Once you have all of the prerequisites in place, you can create your copy of this repo with one command:

```
terminus build:project:create pantheon-systems/example-wordpress-composer my-new-site --team="Agency Org Name"
```

The parameters shown here are:

* The name of the source repo, `pantheon-systems/example-wordpress-composer`. If you are interest in other source repos like Drupal 8, see the [Terminus Build Tools Plugin](https://github.com/pantheon-systems/terminus-build-tools-plugin).
* The machine name to be used by both the soon-to-be-created Pantheon site and GitHub repo. Change `my-new-site` to something meaningful for you.
* The `--team` flag is optional and refers to a Pantheon organization. Pantheon organizations are often web development agencies or Universities. Setting this parameter causes the newly created site to go within the given organization. Run the Terminus command `terminus org:list` to see the organizations you are a member of. There might not be any.


## Important files and directories

#### `/web`

Pantheon will serve the site from the `/web` subdirectory due to the configuration in `pantheon.yml`, facilitating a Composer based workflow. Having your website in this subdirectory also allows for tests, scripts, and other files related to your project to be stored in your repo without polluting your web document root.

#### `/web/wp`

Even within the `/web` directory you may notice that other directories and files are in different places [compared to a default WordPress installation](https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory). See `/web/wp-config.php` for key settings like `WP_SITEURL` which allows WordPress core to be relocated to `/web/wp`. The overall layout of directories in the repo is inspired by [Bedrock](https://github.com/roots/bedrock).

#### `composer.json`

If you are just browsing this repository on GitHub, you may not see some of the directories mentioned above like `wp-admin`. That is because WordPress core and its plugins are installed via Composer and ignored in the `.gitignore` file. Specific plugins are added to the project via `composer.json` and `composer.lock` keeps track of the exact version of each plugin (or other dependency). Generic Composer dependencies (not WordPress plugins or themes) are downloaded to the `/vendor` folder.

## Behat tests

So that CircleCI will have some test to run, this repository includes a configuration of [WordHat](https://wordhat.info/), A WordPress Behat extension. You can add your own `.feature` files within `/tests/behat/features`. [A fuller guide on WordPress testing with Behat is forthcoming.](https://github.com/pantheon-systems/documentation/issues/2469)
83 changes: 83 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# https://circleci.com/docs/configuration#machine
machine:
timezone:
America/Chicago
php:
# https://circleci.com/docs/build-image-trusty/#php
version: 7.1.0
environment:
# In addition to the environment variables defined in this file, also
# add the following variables in the Circle CI UI.
#
# See: https://circleci.com/docs/1.0/environment-variables/
#
# TERMINUS_SITE: Name of the Pantheon site to run tests on, e.g. my_site
# TERMINUS_TOKEN: The Pantheon machine token
# GITHUB_TOKEN: The GitHub personal access token
# GIT_EMAIL: The email address to use when making commits
#
# TEST_SITE_NAME: The name of the test site to provide when installing.
# ADMIN_PASSWORD: The admin password to use when installing.
# ADMIN_EMAIL: The email address to give the admin when installing.
#
# The variables below usually do not need to be modified.
BRANCH: $(echo $CIRCLE_BRANCH | grep -v '^\(master\|[0-9]\+.x\)$')
PR_ENV: ${BRANCH:+pr-$BRANCH}
CIRCLE_ENV: ci-$CIRCLE_BUILD_NUM
DEFAULT_ENV: $(echo ${PR_ENV:-$CIRCLE_ENV} | tr '[:upper:]' '[:lower:]' | sed 's/[^0-9a-z-]//g' | cut -c -11 | sed 's/-$//')
TERMINUS_ENV: ${TERMINUS_ENV:-$DEFAULT_ENV}
NOTIFY: 'scripts/github/add-commit-comment {project} {sha} "Created multidev environment [{site}#{env}]({dashboard-url})." {site-url}'
PATH: $PATH:~/bin:tests/scripts
WORDPRESS_ADMIN_USERNAME: admin
# There is a mismatch in variable names used by
# the terminus build plugin and the Behat tests.
# So the variable ADMIN_PASSWORD needs to be
# reassigned to WORDPRESS_ADMIN_PASSWORD.
# And because CircleCI does not allow for simple
# setting of a private variable to a public
# variable, this workaround of writing to a file is
# used.
WORDPRESS_ADMIN_PASSWORD: $(cat ~/WORDPRESS_ADMIN_PASSWORD)

dependencies:
cache_directories:
- ~/.composer/cache
pre:
- echo "Begin build for $CIRCLE_ENV${PR_ENV:+ for }$PR_ENV. Pantheon test environment is $TERMINUS_SITE.$TERMINUS_ENV"
- |
if [ -n "$GITHUB_TOKEN" ] ; then
composer config --global github-oauth.github.com $GITHUB_TOKEN
fi
- git config --global user.email "$GIT_EMAIL"
- git config --global user.name "Circle CI"
override:
- echo $ADMIN_PASSWORD > ~/WORDPRESS_ADMIN_PASSWORD
- composer global require -n "hirak/prestissimo:^0.3"
- composer global require -n "consolidation/cgr"
- cgr "pantheon-systems/terminus:^1"
- terminus --version
- mkdir -p ~/.terminus/plugins
- composer create-project -n -d ~/.terminus/plugins pantheon-systems/terminus-build-tools-plugin:^1
- composer create-project -n -d ~/.terminus/plugins pantheon-systems/terminus-secrets-plugin:^1
post:
- terminus auth:login -n --machine-token="$TERMINUS_TOKEN"
- terminus build:env:delete:ci -n "$TERMINUS_SITE" --keep=2 --yes
- composer -n build-assets
- terminus env:wake -n "$TERMINUS_SITE.dev"
- terminus build:env:create -n "$TERMINUS_SITE.dev" "$TERMINUS_ENV" --yes --notify="$NOTIFY"
# This line will re-copy the database to the multidev environment to account
# for multiple CI builds running on the same multidev.
- terminus env:clone-content "$TERMINUS_SITE.dev" "$TERMINUS_ENV" --yes

test:
override:
- run-behat
post:
- terminus secrets:set -n "$TERMINUS_SITE.$TERMINUS_ENV" token "$GITHUB_TOKEN" --file='github-secrets.json' --clear --skip-if-empty

deployment:
build-assets:
branch: master
commands:
- terminus build-env:merge -n "$TERMINUS_SITE.$TERMINUS_ENV" --yes
- terminus build-env:delete:pr -n "$TERMINUS_SITE" --yes
96 changes: 96 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"name": "stevector/example-wordpress-composer",
"description": "",
"version": "0.1.0",
"type": "project",
"keywords": [],
"minimum-stability": "dev",
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org"
},
{
"type": "package",
"package": {
"name": "pantheon-systems/wordpress",
"version": "4.8",
"dist": {
"url": "https://github.com/pantheon-systems/WordPress/archive/4.8.zip",
"type": "zip"
},
"source": {
"url": "[email protected]:pantheon-systems/WordPress.git",
"type": "git",
"reference": "4.8"
},
"type": "wordpress-core",
"require": {
"johnpbloch/wordpress-core-installer": "~0.1"
},
"extra": {
"wordpress-install-dir": "web/wp"
}
}
},
{
"type": "vcs",
"url": "https://github.com/ataylorme/behat-wordpress-extension"
}
],
"require": {
"composer/installers": "~1.0",
"vlucas/phpdotenv": "^2.4.0",
"wpackagist-plugin/wp-native-php-sessions": "^0.6.0",
"wpackagist-plugin/pantheon-advanced-page-cache": "^0.1.4",
"wpackagist-plugin/wp-cfm": "^1.4.5",
"wpackagist-theme/twentyseventeen": "^1.1",
"pantheon-systems/wordpress": "^4.8",
"roots/wp-password-bcrypt": "^1.0.0"
},
"require-dev": {
"ataylorme/behat-wordpress-extension": "dev-pantheon-fixes",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "^1.3",
"roave/security-advisories": "dev-master"
},
"config": {
"vendor-dir": "vendor",
"preferred-install": "dist",
"secure-http": false
},
"extra": {
"build-env": {
"install-cms": [
"wp core install --title={site-name} --url={site-url} --admin_user={account-name} --admin_email={account-mail} --admin_password={account-pass}",
"wp option update permalink_structure '/%postname%/'"
]
},
"installer-paths": {
"web/wp-content/plugins/{$name}/": [
"type:wordpress-plugin"
],
"web/wp-content/themes/{$name}/": [
"type:wordpress-theme"
]
}
},
"scripts": {
"build-assets": [
"composer install --optimize-autoloader"
],
"cleanup": [
"./scripts/composer/cleanup-composer"
],
"post-install-cmd": [
"@cleanup"
],
"post-update-cmd": [
"@cleanup"
],
"post-create-project-cmd": [
"@cleanup"
]
},
"prefer-stable": true
}
Loading

1 comment on commit 2a496ce

@pantheon-ci-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created multidev environment example-wordpress-composer#ci-12.

Visit Site

Please sign in to comment.