carlalexander/bedrock-pantheon-circleci 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

carlalexander/bedrock-pantheon-circleci

Composer 安装命令:

composer create-project carlalexander/bedrock-pantheon-circleci

包简介

WordPress project template for using Bedrock with Pantheon and CircleCI

README 文档

README

This is a project template for using bedrock with Pantheon. This project shows you how to use bedrock on Pantheon with CircleCI handling continuous deployment.

Creating a project

To create a new project, just use the following command:

$ composer create-project carlalexander/bedrock-pantheon-circleci

You'll then need to update the environment variables in your project's .env file. You can read about all the Bedrock environment variables in the Bedrock documentation.

Configuration

By itself, the project template only has the code and configuration files required to work on the Pantheon and CircleCI platforms. Both platforms require some additional configuration for the continuous deployment workflow to work.

Configuring SSH

The first thing that you'll need to do is to grant CircleCI SSH access to your account. To do that, you should create a special SSH key just for CircleCI. Start by running this command in your project directory:

$ ssh-keygen -m pem -C "circleci"

This command will create two files, id_rsa and id_rsa.pub, in your project directory. You'll use these two files to configure CircleCI and Pantheon.

Important: Do not commit the id_rsa and id_rsa.pub files into your project.

CircleCI

First, we're going to configure CircleCI. In the CircleCI application, go to your bedrock project’s settings by clicking the gear icon next to your project.

Project settings

There, you want to go to the SSH Permissions screen. You then want to click on the Add SSH Key button. This will open a modal window where you can enter the SSH key that you want to add to your CircleCI project. The modal has two fields: Hostname and Private Key.

SSH key modal window

For the Hostname, you want enter drush.in. This will limit the SSH key use to only Pantheon servers. If you leave it empty, the SSH key will be used for all SSH connections which we don't want.

The Private Key is the content of the id_rsa file that we created with the ssh-keygen command. The content of the id_rsa file will always start with: -----BEGIN RSA PRIVATE KEY-----. Once you've filled the two form fields, you want to click on Add SSH Key button to add the SSH key.

SSH keys screen

You should then see it appear in the list of SSH keys.

Pantheon

Next, you need to add the SSH key to your Pantheon account. From the dashboard, you want to go to the account page by clicking the Account tab.

Account tab

There you want to go to the SSH Keys section and fill the Add an SSH Key form. For this form, you want to copy the public key instead of the private key. You can find it in the id_rsa.pub file.

Add an SSH key form

The beginning of the file will always start with ssh-rsa. If you use the -C "circleci" option with the ssh-keygen command, the file will end with circleci. Once you've copied the content of the id_rsa.pub file, you want to click on Add Key.

SSH keys screen

You should then see it appear in the list of SSH keys.

Creating the initial .env file

Unlike a standard WordPress site, a Bedrock site uses environment variables to manage sensitive credentials. These environment variables can come from different sources. The most important one being .env file which Bedrock uses instead of the standard WordPress wp-config.php file.

Pantheon won't create the initial .env file that your Bedrock site needs. You're going to have to create it yourself and upload it to the Pantheon server. To easiest way to do that is by connecting to your Pantheon server using FTP and creating the .env file.

Connection Info

To connect to your Pantheon site using FTP, go to your site admin panel in the Pantheon dashboard. There, you'll see a Connection Info button to the right as shown above. This will open a menu with all the credentials used to connect to your Pantheon site.

SFTP credentials

You'll find the SFTP credentials at the bottom. Use these SFTP credentials to connect to your Pantheon site. Once connected, you want to go to the files directory and create the private directory. You want to create your .env file in the private directory that you just created with the following:

WP_ENV=development
WP_SITEURL=${WP_HOME}/wp

# Generate your keys here: https://roots.io/salts.html
AUTH_KEY='generateme'
SECURE_AUTH_KEY='generateme'
LOGGED_IN_KEY='generateme'
NONCE_KEY='generateme'
AUTH_SALT='generateme'
SECURE_AUTH_SALT='generateme'
LOGGED_IN_SALT='generateme'
NONCE_SALT='generateme'

It's important that you replace all the keys with new ones that were generated here. You'll also notice that this is a more trimmed down .env file than what you're used to see with Bedrock. That's because Pantheon supplies a lot of the environment variables that we'd store in the .env file normally.

CircleCI environment variables

For the CircleCI Pantheon deployment script to work, we need to configure some project specific environment variables. To do that, you're going to have to go back to your project's setting in CircleCI. You can access them by clicking on the gear icon.

Environment Variables screen

There, you want to navigate to the Environment Variables screen. Next, you'll need to add specific environment variables. The following sections will explain how to get the value for each environment variable.

TERMINUS_SITE

The TERMINUS_SITE environment variable is the name of the site that we're deploying on the Pantheon platform. The easiest way to get that value is by going to your site on the Pantheon. In the admin panel, you want to click to visit the development version of the site.

Development site button

The URL for the development version of the site should look something like http://dev-xxxxxxx.pantheonsite.io/. The xxxxxxx is the name of site on the Pantheon platform. You need to use that as the value of your TERMINUS_SITE environment variable.

Adding TERMINUS_SITE

TERMINUS_TOKEN

The TERMINUS_TOKEN environment variable is the token used by terminus to authenticate with the Pantheon platform. You create it by going to the Machine Tokens section in the Account tab of the Pantheon dashboard. You then want to click on Create token to create your machine token.

Create new token page

You'll need to give a name to identify your machine token. Once that's done, you want to click on Generate token. This will generate the token and bring a modal.

Generate token modal

Pantheon will only show you the machine token once. You can save it somewhere if you need to. Otherwise, just head over to your project's settings in CircleCI and add the machine token as the value of your TERMINUS_TOKEN environment variable.

Adding TERMINUS_TOKEN

GITHUB_TOKEN (optional)

The deployment script will create multidev environments whenever CircleCI is running for a pull request. These multidev environments won't get cleaned up once the pull request gets merged. For that, you need to allow terminus to connect to your GitHub account.

To do that, you need to add the GITHUB_TOKEN environment variable. The value of the GITHUB_TOKEN environment variable comes from creating a personal access token on GitHub. You can find a guide explaining how to create one here.

GitHub personal token

Once created, GitHub will only show your personal token once. You can save it somewhere if you want. Otherwise, just head over to your project's settings in CircleCI and add the machine token as the value of your GITHUB_TOKEN environment variable.

Adding GITHUB_TOKEN

Acknowledgements

Thanks to the Roots team for creating and maintaining the Bedrock project. Also thanks to Andrew Taylor for his repo showing how to have advanced deployment workflow with WordPress and Pantheon.

carlalexander/bedrock-pantheon-circleci 适用场景与选型建议

carlalexander/bedrock-pantheon-circleci 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 8, 最近一次更新时间为 2020 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「composer」 「wordpress」 「wp」 「roots」 「bedrock」 「wp-config」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 carlalexander/bedrock-pantheon-circleci 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 carlalexander/bedrock-pantheon-circleci 我们能提供哪些服务?
定制开发 / 二次开发

基于 carlalexander/bedrock-pantheon-circleci 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-30