Skip to content

Commit 538a7ab

Browse files
authored
Merge pull request #32 from rtCamp/version/3.0
Version 3.0 - Hooks and node build support
2 parents ddb56bc + ac7ef58 commit 538a7ab

File tree

10 files changed

+981
-5419
lines changed

10 files changed

+981
-5419
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor/
2-
.vscode/
2+
.vscode/
3+
.idea/

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ RUN mkdir -p /composer && \
4242
COPY composer.* /composer/
4343
RUN cd /composer && composer install
4444

45+
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash && \
46+
apt install -y nodejs && \
47+
rm -rf /var/lib/apt/lists/*
48+
4549
COPY deploy.php hosts.yml /
4650
COPY *.sh /
4751
RUN chmod +x /*.sh

README.md

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
This action is a part of [GitHub Actions Library](https://github.com/rtCamp/github-actions-library/) created by [rtCamp](https://github.com/rtCamp/).
1+
This action is a part of [GitHub Actions Library](https://github.com/rtCamp/github-actions-library/) created
2+
by [rtCamp](https://github.com/rtCamp/).
23

34
# Deploy WordPress - GitHub Action
45

56
[![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)
67

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

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

11-
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`.
15+
During deployment, by default this action will download [WordPress](https://wordpress.org/latest.zip), put the content
16+
of the repo in `wp-content` directory and then deploy the entire WordPress setup on the deploy path specified
17+
in `hosts.yml`.
1218

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

@@ -25,29 +31,41 @@ jobs:
2531
name: Deploy
2632
runs-on: ubuntu-latest
2733
steps:
28-
- uses: actions/checkout@v2
29-
- name: Deploy
30-
uses: rtCamp/action-deploy-wordpress@v2
31-
env:
32-
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
34+
- uses: actions/checkout@v2
35+
- name: Deploy
36+
uses: rtCamp/action-deploy-wordpress@v2
37+
env:
38+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
3339
```
3440
35-
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`.
36-
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).
37-
41+
3. Create `SSH_PRIVATE_KEY` secret
42+
using [GitHub Action's Secret](https://developer.github.com/actions/creating-workflows/storing-secrets) and store the
43+
private key that you use use to ssh to server(s) defined in `hosts.yml`.
44+
4. Create `.github/hosts.yml` inventory file, based
45+
on [Deployer inventory file](https://deployer.org/docs/hosts.html#inventory-file) format. Make sure you explictly
46+
define GitHub branch mapping. Only the GitHub branches mapped in `hosts.yml` will be deployed, rest will be filtered
47+
out. Here is a sample [hosts.yml](https://github.com/rtCamp/wordpress-skeleton/blob/main/.github/hosts.yml).
3848

3949
## Environment Variables
4050

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

43-
Variable | Default | Possible Values | Purpose
44-
------------------|---------|-----------------------------|----------------------------------------------------
45-
`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.
46-
`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.
47-
`WP_MINOR_UPDATE` | null | `true` / `false` | If set to `true`, latest minor version of `WP_VERSION` will be taken.
48-
`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.)
49-
`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)
50-
53+
Variable | Default | Possible Values | Purpose
54+
------------------|---------|---------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
55+
`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.
56+
`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.
57+
`WP_MINOR_UPDATE` | null | `true` / `false` | If set to `true`, latest minor version of `WP_VERSION` will be taken.
58+
`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.)
59+
`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)
60+
`SKIP_WP_TASKS` | null | `true`/`false` | If set to `true`, WordPress specific deplyment tasks will skipped.
61+
`PHP_VERSION` | 7.4 | Valid PHP version | Determines the cachetool version compatible to use for purging opcache.
62+
`NPM_VERSION` | null | Valid NPM Version | NPM Version. If not specified, latest version will be used.
63+
`NODE_VERSION` | null | Valid Node Version | If not specified, default version built into action will be used.
64+
`NODE_BUILD_DIRECTORY` | null | path to valid directory on repository. | Build directory. Generally root directory or directory like frontend.
65+
`NODE_BUILD_COMMAND` | null | `npm run build` or similar command. | Command used to to build the dependencies needed on deployment.
66+
`NODE_BUILD_SCRIPT` | null | path to valid shell script | Custom or predefined script to run after compilation.
67+
68+
All node related variables are completely optional. You can use them if your site needs to have node dependencies built.
5169

5270
## Server Setup
5371

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

6583
#### Existing Site
84+
6685
1. Open file `/opt/easyengine/sites/example.com/config/nginx/conf.d/main.conf`.
6786
2. Replace `/var/www/htdocs` with `/var/www/htdocs/current`.
6887
3. Run `ee site reload example.com`.
@@ -74,14 +93,15 @@ mv /opt/easyengine/sites/example.com/app/wp-config.php /opt/easyengine/sites/exa
7493

7594
### Not using EasyEngine
7695

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

81-
82101
## Hashicorp Vault (Optional)
83102

84-
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.
103+
This GitHub action supports [Hashicorp Vault](https://www.vaultproject.io/). This comes in handy if you manage multiple
104+
servers and providing `SSH_PRIVATE_KEY` as GitHub secret per project becomes cumbersome.
85105

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

@@ -100,17 +120,20 @@ jobs:
100120
name: Deploy
101121
runs-on: ubuntu-latest
102122
steps:
103-
- uses: actions/checkout@v2
104-
- name: Deploy
105-
uses: rtCamp/action-deploy-wordpress@v2
106-
env:
107-
VAULT_ADDR: ${{ secrets.VAULT_ADDR }}
108-
VAULT_TOKEN: ${{ secrets.VAULT_TOKEN }}
123+
- uses: actions/checkout@v2
124+
- name: Deploy
125+
uses: rtCamp/action-deploy-wordpress@v2
126+
env:
127+
VAULT_ADDR: ${{ secrets.VAULT_ADDR }}
128+
VAULT_TOKEN: ${{ secrets.VAULT_TOKEN }}
109129
```
110130

111-
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.
131+
GitHub action uses `VAULT_TOKEN` to connect to `VAULT_ADDR` to
132+
retrieve [Signed SSH Certificates](https://www.vaultproject.io/docs/secrets/ssh/signed-ssh-certificates.html#signing-key-amp-role-configuration)
133+
and uses it for deployment.
112134

113-
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:
135+
Please remember that you must configure each of your target deployment server to accept ssh connection via signed
136+
certificate using Vault beforehand. Ususally, you need to run following commands once per server:
114137

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

129152
## Overriding default deployement behavior
130153

131-
Create a file at location `.github/deploy/deploy.php` in your git repo to provide your own [Deployer.org](https://deployer.org/) script.
132-
133-
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`.
154+
1. If you would like to completely override this actions deployer recipe. Create a file at
155+
location `.github/deploy/deploy.php` in your git repository to provide your own [Deployer.org](https://deployer.org/)
156+
script.
157+
* Please note that it will completely override this
158+
action's [original deploy.php](https://github.com/rtCamp/action-deploy-wordpress/blob/master/deploy.php). So if
159+
you need some portion
160+
of [original deploy.php](https://github.com/rtCamp/action-deploy-wordpress/blob/master/deploy.php), you need to
161+
copy that to your own `.github/deploy/deploy.php`.
162+
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
163+
location `.github/deploy/addon.php` in your git repository. Checkout the [example addon.php](./example/addon.php) to
164+
see how to customize it.
165+
3. If you need to modify the `main.sh` shell script of this action, you can create a file at
166+
location `.github/deploy/addon.sh` in your git repository. Checkout the [example addon.sh](./example/addon.sh) to see
167+
how to customize.
134168

135169
## License
136170

composer.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"require": {
3-
"deployer/deployer": "^6.3.0",
4-
"deployer/recipes": "^6.1.0",
5-
"squizlabs/php_codesniffer": "~3.3.2",
6-
"wp-cli/wp-cli-bundle": "~2.0",
7-
"phpunit/phpunit": "^5.6"
3+
"deployer/deployer": "^6.8",
4+
"deployer/recipes": "^6.2"
85
}
96
}

0 commit comments

Comments
 (0)