Skip to content

Version 3.0.0 - Hooks and node build support #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
.vscode/
.vscode/
.idea/
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ RUN mkdir -p /composer && \
COPY composer.* /composer/
RUN cd /composer && composer install

RUN curl -sL https://deb.nodesource.com/setup_16.x | bash && \
apt install -y nodejs && \
rm -rf /var/lib/apt/lists/*

COPY deploy.php hosts.yml /
COPY *.sh /
RUN chmod +x /*.sh
Expand Down
102 changes: 68 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
This action is a part of [GitHub Actions Library](https://github.com/rtCamp/github-actions-library/) created by [rtCamp](https://github.com/rtCamp/).
This action is a part of [GitHub Actions Library](https://github.com/rtCamp/github-actions-library/) created
by [rtCamp](https://github.com/rtCamp/).

# Deploy WordPress - GitHub Action

[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)

A [GitHub Action](https://github.com/features/actions) to deploy WordPress on a server using [PHP's Deployer.org project](https://deployer.org/).
A [GitHub Action](https://github.com/features/actions) to deploy WordPress on a server
using [PHP's Deployer.org project](https://deployer.org/).

Please note that, this action expects git repo structure in a certain way. Your webroot should include content inside `wp-content` except `uploads`. You may use our [WordPress Skeleton](https://github.com/rtCamp/wordpress-skeleton) as a base, or restructre existing project to fit in.
Please note that, this action expects git repo structure in a certain way. Your webroot should include content
inside `wp-content` except `uploads`. You may use our [WordPress Skeleton](https://github.com/rtCamp/wordpress-skeleton)
as a base, or restructre existing project to fit in.

During deployment, by default this action will download [WordPress](https://wordpress.org/latest.zip), put the content of the repo in `wp-content` directory and then deploy the entire WordPress setup on the deploy path specified in `hosts.yml`.
During deployment, by default this action will download [WordPress](https://wordpress.org/latest.zip), put the content
of the repo in `wp-content` directory and then deploy the entire WordPress setup on the deploy path specified
in `hosts.yml`.

`hosts.yml` is [Deployer's inventory file](https://deployer.org/docs/hosts.html#inventory-file).

Expand All @@ -25,29 +31,41 @@ jobs:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy
uses: rtCamp/action-deploy-wordpress@v2
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- uses: actions/checkout@v2
- name: Deploy
uses: rtCamp/action-deploy-wordpress@v2
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
```

3. Create `SSH_PRIVATE_KEY` secret using [GitHub Action's Secret](https://developer.github.com/actions/creating-workflows/storing-secrets) and store the private key that you use use to ssh to server(s) defined in `hosts.yml`.
4. Create `.github/hosts.yml` inventory file, based on [Deployer inventory file](https://deployer.org/docs/hosts.html#inventory-file) format. Make sure you explictly define GitHub branch mapping. Only the GitHub branches mapped in `hosts.yml` will be deployed, rest will be filtered out. Here is a sample [hosts.yml](https://github.com/rtCamp/wordpress-skeleton/blob/main/.github/hosts.yml).

3. Create `SSH_PRIVATE_KEY` secret
using [GitHub Action's Secret](https://developer.github.com/actions/creating-workflows/storing-secrets) and store the
private key that you use use to ssh to server(s) defined in `hosts.yml`.
4. Create `.github/hosts.yml` inventory file, based
on [Deployer inventory file](https://deployer.org/docs/hosts.html#inventory-file) format. Make sure you explictly
define GitHub branch mapping. Only the GitHub branches mapped in `hosts.yml` will be deployed, rest will be filtered
out. Here is a sample [hosts.yml](https://github.com/rtCamp/wordpress-skeleton/blob/main/.github/hosts.yml).

## Environment Variables

This GitHub action's behavior can be customized using following environment variables:

Variable | Default | Possible Values | Purpose
------------------|---------|-----------------------------|----------------------------------------------------
`MU_PLUGINS_URL` | null | vip, any git repo url | If value is `vip`, then action will clone [VIP's MU plugins](https://github.com/Automattic/vip-mu-plugins-public) as `mu-plugins` folder. If you want to specifiy a non-VIP mu-plugins repo, you can provide a publicly accessible mu-plugins repo URL as the value.
`WP_VERSION` | latest | Any valid WordPress version | If you specify a WordPress version, then that speicifc WordPress version will be downloaded, instead of latest WordPress version. WP_VERSION defined in hosts.yml will have higher priority than one defined in workflow file.
`WP_MINOR_UPDATE` | null | `true` / `false` | If set to `true`, latest minor version of `WP_VERSION` will be taken.
`JUMPHOST_SERVER` | null | Hostname/IP address of the jumphost server | If the deployment server is not directly accessible, and needs a jumphost, then this method should be used. (Note: The `SSH_PRIVATE_KEY` env variable should have access to the jumphost as well as deployment server for this to work. Also, this method does not work with vault.)
`SUBMODULE_DEPLOY_KEY` | null | Read access deploy key created in the submodule repo's deploy keys. | Only required for privated submodule repo. For now only one private submodule deploy key is allowed. All public submodules in repo will be fetched by default without the need of this env variable. (To create a deploy key go to: Settings > Deploy Keys > Add deploy key)

Variable | Default | Possible Values | Purpose
------------------|---------|---------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
`MU_PLUGINS_URL` | null | vip, any git repo url | If value is `vip`, then action will clone [VIP's MU plugins](https://github.com/Automattic/vip-mu-plugins-public) as `mu-plugins` folder. If you want to specifiy a non-VIP mu-plugins repo, you can provide a publicly accessible mu-plugins repo URL as the value.
`WP_VERSION` | latest | Any valid WordPress version | If you specify a WordPress version, then that speicifc WordPress version will be downloaded, instead of latest WordPress version. WP_VERSION defined in hosts.yml will have higher priority than one defined in workflow file.
`WP_MINOR_UPDATE` | null | `true` / `false` | If set to `true`, latest minor version of `WP_VERSION` will be taken.
`JUMPHOST_SERVER` | null | Hostname/IP address of the jumphost server | If the deployment server is not directly accessible, and needs a jumphost, then this method should be used. (Note: The `SSH_PRIVATE_KEY` env variable should have access to the jumphost as well as deployment server for this to work. Also, this method does not work with vault.)
`SUBMODULE_DEPLOY_KEY` | null | Read access deploy key created in the submodule repo's deploy keys. | Only required for privated submodule repo. For now only one private submodule deploy key is allowed. All public submodules in repo will be fetched by default without the need of this env variable. (To create a deploy key go to: Settings > Deploy Keys > Add deploy key)
`SKIP_WP_TASKS` | null | `true`/`false` | If set to `true`, WordPress specific deplyment tasks will skipped.
`PHP_VERSION` | 7.4 | Valid PHP version | Determines the cachetool version compatible to use for purging opcache.
`NPM_VERSION` | null | Valid NPM Version | NPM Version. If not specified, latest version will be used.
`NODE_VERSION` | null | Valid Node Version | If not specified, default version built into action will be used.
`NODE_BUILD_DIRECTORY` | null | path to valid directory on repository. | Build directory. Generally root directory or directory like frontend.
`NODE_BUILD_COMMAND` | null | `npm run build` or similar command. | Command used to to build the dependencies needed on deployment.
`NODE_BUILD_SCRIPT` | null | path to valid shell script | Custom or predefined script to run after compilation.

All node related variables are completely optional. You can use them if your site needs to have node dependencies built.

## Server Setup

Expand All @@ -63,6 +81,7 @@ The Deployer.org expects server setup in a particular way.
The `current` folder will be automatically created by Deployer during execution.

#### Existing Site

1. Open file `/opt/easyengine/sites/example.com/config/nginx/conf.d/main.conf`.
2. Replace `/var/www/htdocs` with `/var/www/htdocs/current`.
3. Run `ee site reload example.com`.
Expand All @@ -74,14 +93,15 @@ mv /opt/easyengine/sites/example.com/app/wp-config.php /opt/easyengine/sites/exa

### Not using EasyEngine

1. Make sure your web server points to `current` subdirectory inside original webroot. Make sure `current` subdirectory do NOT exist actually.
1. Make sure your web server points to `current` subdirectory inside original webroot. Make sure `current` subdirectory
do NOT exist actually.
2. You may need to reload your webserver.
3. You may need to change location of `wp-config.php` as we need in above section.


## Hashicorp Vault (Optional)

This GitHub action supports [Hashicorp Vault](https://www.vaultproject.io/). This comes in handy if you manage multiple servers and providing `SSH_PRIVATE_KEY` as GitHub secret per project becomes cumbersome.
This GitHub action supports [Hashicorp Vault](https://www.vaultproject.io/). This comes in handy if you manage multiple
servers and providing `SSH_PRIVATE_KEY` as GitHub secret per project becomes cumbersome.

To enable Hashicorp Vault support, please define following GitHub secrets:

Expand All @@ -100,17 +120,20 @@ jobs:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy
uses: rtCamp/action-deploy-wordpress@v2
env:
VAULT_ADDR: ${{ secrets.VAULT_ADDR }}
VAULT_TOKEN: ${{ secrets.VAULT_TOKEN }}
- uses: actions/checkout@v2
- name: Deploy
uses: rtCamp/action-deploy-wordpress@v2
env:
VAULT_ADDR: ${{ secrets.VAULT_ADDR }}
VAULT_TOKEN: ${{ secrets.VAULT_TOKEN }}
```

GitHub action uses `VAULT_TOKEN` to connect to `VAULT_ADDR` to retrieve [Signed SSH Certificates](https://www.vaultproject.io/docs/secrets/ssh/signed-ssh-certificates.html#signing-key-amp-role-configuration) and uses it for deployment.
GitHub action uses `VAULT_TOKEN` to connect to `VAULT_ADDR` to
retrieve [Signed SSH Certificates](https://www.vaultproject.io/docs/secrets/ssh/signed-ssh-certificates.html#signing-key-amp-role-configuration)
and uses it for deployment.

Please remember that you must configure each of your target deployment server to accept ssh connection via signed certificate using Vault beforehand. Ususally, you need to run following commands once per server:
Please remember that you must configure each of your target deployment server to accept ssh connection via signed
certificate using Vault beforehand. Ususally, you need to run following commands once per server:

```bash
export VAULT_ADDR='https://example.com:8200'
Expand All @@ -128,9 +151,20 @@ systemctl restart ssh

## Overriding default deployement behavior

Create a file at location `.github/deploy/deploy.php` in your git repo to provide your own [Deployer.org](https://deployer.org/) script.

Please note that it will completely override this action's [original deploy.php](https://github.com/rtCamp/action-deploy-wordpress/blob/master/deploy.php). So if you need some portion of [original deploy.php](https://github.com/rtCamp/action-deploy-wordpress/blob/master/deploy.php), you need to copy that to your own `.github/deploy/deploy.php`.
1. If you would like to completely override this actions deployer recipe. Create a file at
location `.github/deploy/deploy.php` in your git repository to provide your own [Deployer.org](https://deployer.org/)
script.
* Please note that it will completely override this
action's [original deploy.php](https://github.com/rtCamp/action-deploy-wordpress/blob/master/deploy.php). So if
you need some portion
of [original deploy.php](https://github.com/rtCamp/action-deploy-wordpress/blob/master/deploy.php), you need to
copy that to your own `.github/deploy/deploy.php`.
2. If you need to add one or a few custom tasks on top of this actions `deploy.php`, you can create a file at
location `.github/deploy/addon.php` in your git repository. Checkout the [example addon.php](./example/addon.php) to
see how to customize it.
3. If you need to modify the `main.sh` shell script of this action, you can create a file at
location `.github/deploy/addon.sh` in your git repository. Checkout the [example addon.sh](./example/addon.sh) to see
how to customize.

## License

Expand Down
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"require": {
"deployer/deployer": "^6.3.0",
"deployer/recipes": "^6.1.0",
"squizlabs/php_codesniffer": "~3.3.2",
"wp-cli/wp-cli-bundle": "~2.0",
"phpunit/phpunit": "^5.6"
"deployer/deployer": "^6.8",
"deployer/recipes": "^6.2"
}
}
Loading