Skip to content

Commit 853434d

Browse files
authored
Merge pull request #784 from Kit/add-devcontainer
Add `devcontainer` Configuration
2 parents 6605003 + f7855c4 commit 853434d

8 files changed

Lines changed: 208 additions & 13 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"name": "WordPress Codespace",
3+
"image": "ghcr.io/automattic/vip-codespaces/alpine-base:latest",
4+
"overrideCommand": false,
5+
"forwardPorts": [80, 81, 8025],
6+
"portsAttributes": {
7+
"80": {
8+
"label": "Application",
9+
"onAutoForward": "notify",
10+
"elevateIfNeeded": true
11+
},
12+
"81": {
13+
"label": "phpMyAdmin",
14+
"onAutoForward": "notify",
15+
"elevateIfNeeded": true
16+
},
17+
"3306": {
18+
"label": "MySQL",
19+
"onAutoForward": "ignore"
20+
},
21+
"9000": {
22+
"label": "php-fpm",
23+
"onAutoForward": "ignore"
24+
},
25+
"9003": {
26+
"label": "Xdebug Client Port",
27+
"onAutoForward": "notify"
28+
}
29+
},
30+
"features": {
31+
"ghcr.io/automattic/vip-codespaces/base:latest": {},
32+
"ghcr.io/automattic/vip-codespaces/nginx:latest": {},
33+
"ghcr.io/automattic/vip-codespaces/php:latest": {
34+
"version": "8.2",
35+
"composer": true
36+
},
37+
"ghcr.io/automattic/vip-codespaces/mariadb:latest": {
38+
// Set to false to prevent the database content from persisting between rebuilds.
39+
"installDatabaseToWorkspaces": true
40+
},
41+
"ghcr.io/automattic/vip-codespaces/wordpress:latest": {
42+
// WordPress version: Accepts 'latest', 'nightly', or a version number.
43+
"version": "latest",
44+
// Set to false to prevent wp-content/uploads content from persisting between rebuilds.
45+
"moveUploadsToWorkspaces": false,
46+
// Set to true to create the environment as a WordPress multisite.
47+
"multisite": false,
48+
// GitHub Codespaces only supports the subdirectory network type for multisite; subdomain cannot be used.
49+
"multisiteStyle": "subdirectory"
50+
},
51+
"ghcr.io/automattic/vip-codespaces/wp-cli:latest": {
52+
// Set to true to enable nightly builds of WP-CLI.
53+
"nightly": false
54+
},
55+
"ghcr.io/automattic/vip-codespaces/dev-tools:latest": {},
56+
"ghcr.io/automattic/vip-codespaces/phpmyadmin:latest": {
57+
// Set to false to disable phpMyAdmin.
58+
"enabled": true
59+
},
60+
"ghcr.io/automattic/vip-codespaces/xdebug:latest": {
61+
// Set to true to enable Xdebug.
62+
// This setting can also be updated with CLI commands in the terminal.
63+
"enabled": true,
64+
// Set Xdebug mode. Accepted value options are listed here: https://xdebug.org/docs/all_settings#mode
65+
"mode": "debug"
66+
},
67+
"ghcr.io/automattic/vip-codespaces/ssh:latest": {
68+
// Set to true to enable an SSH server for the Codespaces environment.
69+
"enabled": true
70+
}
71+
},
72+
"postCreateCommand": "bash ./.devcontainer/post-create.sh"
73+
}

.devcontainer/post-create.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
# Install Free Third Party WordPress Plugins
4+
wp plugin install classic-editor custom-post-type-ui elementor forminator woocommerce
5+
6+
# Install Default WordPress Theme
7+
wp theme install twentytwentyfive
8+
9+
# Symlink Plugin
10+
ln -s /workspaces/convertkit-wordpress /wp/wp-content/plugins/convertkit
11+
12+
# Run Composer in Plugin Directory to build
13+
cd /wp/wp-content/plugins/convertkit
14+
composer update
15+
16+
# Activate Plugin
17+
wp plugin activate convertkit
347 KB
Loading
31.7 KB
Loading
7.04 KB
Loading

.github/docs/dev-container.png

289 KB
Loading

SETUP.md

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ This document describes how to setup your development environment, so that it is
55
Suggestions are provided for the LAMP/LEMP stack and Git client are for those who prefer the UI over a command line and/or are less familiar with
66
WordPress, PHP, MySQL and Git - but you're free to use your preferred software.
77

8-
## Setup
9-
10-
### LAMP/LEMP stack
8+
## LAMP/LEMP stack
119

1210
Any Apache/nginx, PHP 7.x+ and MySQL 5.8+ stack running WordPress. For example, but not limited to:
1311
- Local by Flywheel (recommended)
14-
- Docker
1512
- MAMP
1613
- WAMP
1714
- VVV
15+
- Docker
16+
17+
## Local, MAMP, WAMP, VVV
18+
19+
If using a non-Docker environment, follow the below steps:
1820

1921
### Composer
2022

@@ -56,9 +58,9 @@ Create a blank `test` database in MySQL, with a MySQL user who can read and writ
5658

5759
### Configure Testing Environment
5860

59-
Copy the `.env.example` file to `.env.testing` in the root of this repository, changing the `WORDPRESS_*` and `CHROMEDRIVER_*` variables as necessary to match your environment.
61+
Copy the `.env.example` file to `.env.testing` in the root of this repository, changing folder and database credentials as necessary.
6062

61-
#### Codeception
63+
### Codeception
6264

6365
Create a `codeception.yml` file in the root of the repository, with the following contents:
6466
```yaml
@@ -68,10 +70,6 @@ params:
6870
6971
This tells Codeception to read the above `.env.testing` file when testing on the local development enviornment.
7072

71-
#### PHPStan
72-
73-
Copy the `phpstan.neon.example` file to `phpstan.neon` in the root of this repository, changing the `scanDirectories` to point to your local WordPress installation.
74-
7573
### Install Packages
7674

7775
In the Plugin's directory, at the command line, run `composer install`.
@@ -178,10 +176,79 @@ vendor/bin/phpstan --memory-limit=1G
178176
Again, don't worry if you don't understand these commands; if your output looks similar to the above screenshot, with no errors, your environment
179177
is setup successfully.
180178

181-
### Add your API Key to the Plugin
179+
### Connect Plugin to Kit
180+
181+
Refer to the [Kit Help Article](https://help.kit.com/en/articles/2502591-getting-started-the-wordpress-plugin) to get started with using the WordPress Plugin.
182+
183+
## Docker
184+
185+
Using the Development Container, and either GitHub Codespaces or VS Code, it's quick and easy to get started:
186+
187+
### Clone Repository
188+
189+
Using your preferred Git client or command line, clone this repository to your local machine.
190+
191+
If you're new to this, use [GitHub Desktop](https://desktop.github.com/) or [Tower](https://www.git-tower.com/mac)
192+
193+
### Install Docker and Visual Studio Code
194+
195+
- Install [Docker Desktop](https://www.docker.com/products/docker-desktop/), or [Docker Engine](https://docs.docker.com/engine/) if you're developing on Linux
196+
- Install [Visual Studio Code]()
197+
198+
### Install and Run Dev Containers
199+
200+
- Open Visual Studio Code, and install the [Dev Containers]() extension
201+
- Open the Visual Studio Code Command Palette (`Ctrl + Shift + P`)
202+
- Type `>Dev Container: Rebuild and Reopen in Container`, pressing Enter
203+
204+
Visual Studio Code will switch to the Dev Container, loading the preconfigured Docker image for WordPress development, with the Terminal in Visual Studio Code showing the progress:
205+
206+
![Terminal](/.github/docs/dev-container.png?raw=true)
207+
208+
After a few minutes, your development environment should be ready.
209+
210+
### Accessing WordPress
211+
212+
Click on the `Ports` tab, and navigate to the "Application" URL by hovering over the `Forwarded Address` and clicking the globe icon:
213+
214+
![Ports tab](/.github/docs/dev-container-ports.png?raw=true)
215+
216+
To access the WordPress Administration interface, append `/wp-admin` to the URL, using the following credentials:
217+
- Username: `vipgo`
218+
- Password: `password`
219+
220+
Once logged in, navigating to the Plugins screen will show the repository Plugin installed and active, along with some other common third party Plugins:
221+
222+
![Ports tab](/.github/docs/dev-container-plugins.png?raw=true)
223+
224+
### Running Codesniffer
225+
226+
In Visual Studio Code's Terminal, navigate to `/workspaces/convertkit-wordpress`, and run the following command to run PHP_CodeSniffer, which will check the code meets WordPress' Coding Standards:
227+
228+
```bash
229+
vendor/bin/phpcs ./ -v -s
230+
```
231+
232+
If no Terminal instance is open, you can create a new one by clicking the `+` icon.
233+
234+
![Terminal tab](/.github/docs/dev-container-terminal-plus.png?raw=true)
235+
236+
### Running PHPStan
237+
238+
In Visual Studio Code's Terminal, navigate to `/workspaces/convertkit-wordpress`, and run the following command to run PHPStan, which will perform static analysis on the code, checking it meets required
239+
standards, that PHP DocBlocks are valid, WordPress action/filter DocBlocks are valid etc:
240+
241+
```bash
242+
vendor/bin/phpstan --configuration phpstan-dev.neon --memory-limit=1G
243+
```
244+
245+
If no Terminal instance is open, you can create a new one by clicking the `+` icon.
246+
247+
![Terminal tab](/.github/docs/dev-container-terminal-plus.png?raw=true)
248+
249+
### Testing
182250

183-
Refer to the [Kit Help Article](https://help.kit.com/en/articles/2502591-getting-started-the-wordpress-plugin) to get started with
184-
using the WordPress Plugin.
251+
Codeception testing is currently unavailable when using Dev Containers or GitHub Codespaces. This may be available in a future PR.
185252

186253
### Next Steps
187254

phpstan-dev.neon

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# PHPStan configuration for Dev Containers
2+
3+
# Include PHPStan for WordPress configuration.
4+
includes:
5+
- vendor/szepeviktor/phpstan-wordpress/extension.neon
6+
7+
# Parameters
8+
parameters:
9+
# Paths to scan
10+
# This should comprise of the base Plugin PHP file, plus directories that contain Plugin PHP files
11+
paths:
12+
- wp-convertkit.php
13+
- admin/
14+
- includes/
15+
16+
# Files that include Plugin-specific PHP constants.
17+
bootstrapFiles:
18+
- wp-convertkit.php
19+
20+
# Location of WordPress Plugins for PHPStan to scan, building symbols.
21+
scanDirectories:
22+
- /wp/wp-content/plugins
23+
24+
# Location of constants, Kit helper functions and Kit WordPress Libraries for PHPStan to scan, building symbols.
25+
scanFiles:
26+
- /wp/wp-config.php
27+
28+
# Don't report unmatched ignored errors on older PHP versions (7.2, 7.3)
29+
reportUnmatchedIgnoredErrors: false
30+
31+
# Ignore the following errors, as PHPStan and PHPStan for WordPress haven't correctly registered symbols,
32+
# so they're false positives.
33+
ignoreErrors:
34+
- '#Function __ invoked with 2 parameters, 1 required.#'
35+
36+
# Should not need to edit anything below here
37+
# Rule Level: https://phpstan.org/user-guide/rule-levels
38+
level: 5

0 commit comments

Comments
 (0)