Skip to content

Commit

Permalink
Change hostpath so that we can serve the site from its final urls
Browse files Browse the repository at this point in the history
  • Loading branch information
koyan authored and CircleCI Bot committed Mar 12, 2019
1 parent 9a9cb27 commit 22173f6
Show file tree
Hide file tree
Showing 44 changed files with 7,296 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .circleci/artifacts.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
job_environments:
common_environment: &common_environment
CONTAINER_PREFIX: planet4-storytelling
APP_HOSTPATH: storytelling
APP_HOSTPATH:
WP_DB_NAME_PREFIX: planet4-storytel_wordpress
develop_environment: &develop_environment
APP_ENVIRONMENT: development
APP_HOSTNAME: k8s.p4.greenpeace.org
APP_HOSTNAME: develop.storytelling.greenpeace.org
CLOUDSQL_INSTANCE: p4-develop-k8s
GOOGLE_PROJECT_ID: planet-4-151612
GCLOUD_CLUSTER: p4-development
Expand All @@ -16,7 +16,7 @@ job_environments:
WP_STATELESS_BUCKET: planet4-storytelling-stateless-develop
release_environment: &release_environment
APP_ENVIRONMENT: staging
APP_HOSTNAME: release.k8s.p4.greenpeace.org
APP_HOSTNAME: release.storytelling.greenpeace.org
CLOUDSQL_INSTANCE: planet4-prod
GCLOUD_CLUSTER: planet4-production
GOOGLE_PROJECT_ID: planet4-production
Expand All @@ -26,7 +26,7 @@ job_environments:
WP_DB_NAME: planet4-storytel_wordpress_release
WP_STATELESS_BUCKET: planet4-storytelling-stateless-release
production_environment: &production_environment
APP_HOSTNAME: master.k8s.p4.greenpeace.org
APP_HOSTNAME: storytelling.greenpeace.org
CLOUDSQL_INSTANCE: planet4-prod
GCLOUD_CLUSTER: planet4-production
GOOGLE_PROJECT_ID: planet4-production
Expand Down
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ defaults: &defaults
job_environments:
common_environment: &common_environment
CONTAINER_PREFIX: planet4-storytelling
APP_HOSTPATH: storytelling
APP_HOSTPATH:
WP_DB_NAME_PREFIX: planet4-storytel_wordpress
develop_environment: &develop_environment
APP_ENVIRONMENT: development
APP_HOSTNAME: k8s.p4.greenpeace.org
APP_HOSTNAME: develop.storytelling.greenpeace.org
CLOUDSQL_INSTANCE: p4-develop-k8s
GOOGLE_PROJECT_ID: planet-4-151612
GCLOUD_CLUSTER: p4-development
Expand All @@ -22,7 +22,7 @@ job_environments:
WP_STATELESS_BUCKET: planet4-storytelling-stateless-develop
release_environment: &release_environment
APP_ENVIRONMENT: staging
APP_HOSTNAME: release.k8s.p4.greenpeace.org
APP_HOSTNAME: release.storytelling.greenpeace.org
CLOUDSQL_INSTANCE: planet4-prod
GCLOUD_CLUSTER: planet4-production
GOOGLE_PROJECT_ID: planet4-production
Expand All @@ -32,7 +32,7 @@ job_environments:
WP_DB_NAME: planet4-storytel_wordpress_release
WP_STATELESS_BUCKET: planet4-storytelling-stateless-release
production_environment: &production_environment
APP_HOSTNAME: master.k8s.p4.greenpeace.org
APP_HOSTNAME: storytelling.greenpeace.org
CLOUDSQL_INSTANCE: planet4-prod
GCLOUD_CLUSTER: planet4-production
GOOGLE_PROJECT_ID: planet4-production
Expand Down
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

# ============================================================================

# Check necessary commands exist

CIRCLECI := $(shell command -v circleci 2> /dev/null)
COMPOSER := $(shell command -v composer 2> /dev/null)
JQ := $(shell command -v jq 2> /dev/null)
SHELLCHECK := $(shell command -v shellcheck 2> /dev/null)
YAMLLINT := $(shell command -v yamllint 2> /dev/null)

# ============================================================================

lint: init
@$(MAKE) -kj lint-ci lint-sh lint-yaml lint-json lint-composer

init:
@chmod 755 .githooks/*
@find .git/hooks -type l -exec rm {} \;
@find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;

# ============================================================================

lint-sh:
ifndef SHELLCHECK
$(error "shellcheck is not installed: https://github.com/koalaman/shellcheck")
endif
@find . -type f -name '*.sh' ! -path './tests/vendor/*' | xargs shellcheck

lint-yaml:
ifndef YAMLLINT
$(error "yamllint is not installed: https://github.com/adrienverge/yamllint")
endif
@find . -type f -name '*.yml' ! -path './tests/vendor/*' | xargs yamllint

lint-json:
ifndef JQ
$(error "jq is not installed: https://stedolan.github.io/jq/download/")
endif
@find . -type f -name '*.json' ! -path './tests/vendor/*' | xargs jq type | grep -q '"object"'

lint-composer:
ifndef COMPOSER
$(error "composer is not installed: https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos")
endif
@find . -type f -name 'composer*.json' ! -path './tests/vendor/*' -exec composer validate {} \;

lint-ci:
ifndef CIRCLECI
$(error "circleci is not installed: https://circleci.com/docs/2.0/local-cli/#installation")
endif
@circleci config validate >/dev/null
186 changes: 186 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Greenpeace Planet 4

[![CircleCI](https://circleci.com/gh/greenpeace/planet4-base-fork/tree/develop.svg?style=shield)](https://circleci.com/gh/greenpeace/planet4-base-fork/tree/develop)

Testing.

This project provides the base for all Planet 4 sites.

To create a new project, that is powered by Planet 4, fork this repository.

## Prerequisite

- You will need to have PHP 7 (or higher) and composer available on your system.
- You will also need git installed
using svn).
- You will also need mysql or mariadb installed as well.

## Installation
All dependencies should be managed by [Composer](http://getcomposer.org).

The same repository handles all the different Planet4 sites. This happens by having
- everything common in the /composer.json file
- everything site specific in a subdirectory app/project/site/composer.json file
(where project is the name of the Google Cloud Project and "site" is one of "master", "staging")

The composer plugin [composer merge](https://packagist.org/packages/wikimedia/composer-merge-plugin) handles the combining of the two composer.json files

To tell composer which file to use, the first command you need to run is the following:
```
composer config extra.merge-plugin.require "app/planet4-gp-greece/production/composer.json"
```
(replacing `planet4-gp-greece/production` with whatever is applicable for the site you are building)

Then, install all required dependencies with one simple command:
```
composer install
```

If you want to add more dependencies to this project, you should also always
add them to the composer file. No manual copying of plugins or themes should be
necessary and any time.

## Configuration
You need to create a [Wordpress command line](http://wp-cli.org/) configuration file.
You can do that by copying the default one:
```
cp wp-cli.yml.default wp-cli.local.yml
```

The base configuration file `wp-cli.yml` is part of the repository and contains minimal
configuration, all your local changes should go in `wp-cli.local.yml`.

This file is not tracked by default since it contains the complete configuration of
your Wordpress instance such as your database user password. When you need to change
the database configuration, the title or the URL of this
installation, please edit `wp-cli.local.yml`.
```
path: public
core config:
dbuser: root
dbpass: root
dbname: wordpress
core install:
title: Sample Planet 4 website
url: http://test.planet4.dev
admin_user: admin
admin_email: [email protected]
theme activate:
- planet4-master-theme
```

NOTE: your website will be installed on the subdirectory "public" of the current
directory. Make sure that the "url" in the above configuration points to the
directory "public" so that wordpress sets up its live_site configurations correctly.

## Database setup
Before we can initialize the installation, make sure you did create the database
that is configured inside the configuration file. This can be easily done with this
command:
```
echo "CREATE DATABASE wordpress;" | mysql
```
It might be necessary to pass a username (`-u`) and a password (`-p`) to the
mysql command.
More information about this is available in the man page of `mysql` or
[online](https://dev.mysql.com/doc/refman/5.7/en/mysql-command-options.html).


## Install and active plugins and themes
After the database is created, the new Wordpress installation is installed with
one simple composer command:
```
composer run-script site-install
```

This will perform multiple steps:
- Create a public directy and copy the Wordpress core in it
- Create a `wp-config.php` file with default values from the `wp-cli.yml`.
- Create the initial database structure and insert the default data
- Copy themes and plugins listed as dependencies in `composer.json`.
- Activate all the plugins listed as dependencies.
- Activate the theme that is configured inside the `wp-cli.yml`

## Updating
In case a new version of the Wordpress core (a theme or plugin) is published and
you can update your base site by changing the version in `composer.json` and/or
running the update:
```
composer update
composer run-script site-update
```

This will perform multiple steps:
- Fetch the new versions and dependencies
- Merge the new wordpress core in the public directory without deleting your added files
- Copy all the themes and plugins
- Run Wordpress core database udpates if any
- Deactivate and reactivate all the plugins

## Installing an alternate theme
Themes should never be changed inside the web front-end.

_Please note that only the themes that in greenpeace composer repository will be
available by default. You will need to add another repository if it is not a
supported theme_

This would make it impossible to have an automated installation that can be
re-applied whenever needed. To change the theme add the dependency to the
`composer.json` file.
```
"require": {
...
"greenpeace/planet4-another-theme": "4.7.2",
...
}
```

Then you need to change the related line inside the `wp-cli.yml`.
```
theme activate:
- planet4-another-theme
```

After that you can run this composer command to fetch and activate the theme:
```
composer update
composer run-script theme:install
```
The theme will be copied to the public folder and activated to use by the current
Wordpress installation.

---

# Creating a new development deployment on Kubernetes

- Fork the merge repo template (todo), adjust variables to suit
- Create CloudSQL database and user (see [https://github.com/greenpeace/planet4-cloudsql-docker-compose](https://github.com/greenpeace/planet4-cloudsql-docker-compose)). By default, the deployment process uses `<CONTAINER_PREFIX>` as the username and `<CONTAINER_PREFIX>_wordpress` as the database. See: [https://github.com/greenpeace/planet4-docker/blob/master/src/planet-4-151612/p4-builder/Makefile](https://github.com/greenpeace/planet4-docker/blob/master/src/planet-4-151612/p4-builder/Makefile)
- Create the necessary CircleCI project and contexts, and update `./circleci/config.yml` workflow contxt names to match
- Push your commit and watch [https://circleci.com/gh/greenpeace](https://circleci.com/gh/greenpeace)


## CircleCI context secrets:
- GCLOUD_SERVICE_KEY - the key the CircleCI uses to manipulate GCP resources
- NEWRELIC_LICENSE - displayed in the NewRelic Account settings page
- SQLPROXY_KEY - the service account key that CloudSQL proxy uses to connect to the database
- WP_AUTH_KEY
- WP_AUTH_SALT
- WP_DB_PASSWORD - the MySQL password
- WP_LOGGED_IN_KEY
- WP_LOGGED_IN_SALT
- WP_NONCE_KEY
- WP_NONCE_SALT
- WP_SECURE_AUTH_KEY
- WP_SECURE_AUTH_SALT
- WP_STATELESS_KEY - the service account key that WP-Stateless will use to connect to the GCS bucket

Service account keys should be generated from command line via:
```
cat service-account-key.json | base64 -w 0 | xargs
```

Wordpress keys and salts can be generated here: [https://api.wordpress.org/secret-key/1.1/salt](https://api.wordpress.org/secret-key/1.1/salt)
21 changes: 21 additions & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
commands:
- Codeception\Command\GenerateWPUnit
- Codeception\Command\GenerateWPRestApi
- Codeception\Command\GenerateWPRestController
- Codeception\Command\GenerateWPRestPostTypeController
- Codeception\Command\GenerateWPAjax
- Codeception\Command\GenerateWPCanonical
- Codeception\Command\GenerateWPXMLRPC
params:
- .env.codeception
2 changes: 1 addition & 1 deletion composer-local.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Greenpeace P4 Storytelling",
"license": "MIT",
"require": {
"greenpeace/planet4-child-theme-storytelling" : "dev-develop"
"greenpeace/planet4-child-theme-storytelling" : "0.6"
},
"scripts": {
"install:plugin-gravity-forms": "wp plugin install --activate https://raw.githubusercontent.com/greenpeace/planet4-3rdparty-plugins/master/https://raw.githubusercontent.com/greenpeace/planet4-3rdparty-plugins/master/gravityforms_2.4.4.zip",
Expand Down
Loading

0 comments on commit 22173f6

Please sign in to comment.