Skip to content

adding a cron and post_deploy example and new method to handle trailing slashes #4528

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 25 additions & 5 deletions sites/upsun/src/get-started/stacks/wordpress/bedrock.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ application can receive requests. Such tasks include:
- Running any due cron jobs

To perform these tasks, we'll utilize the [deploy hook](/learn/overview/build-deploy.md#deploy-steps). Locate the
`deploy:` section (below the `build:` section). Update the `deploy:` section as follows:
`deploy:` section (below the `build:` section). Update the `deploy:` and `post_deploy:` section as follows:

```yaml {configFile="app"}
applications:
Expand All @@ -147,8 +147,9 @@ applications:
wp cache flush
# Runs the WordPress database update procedure
wp core update-db
# Runs all due cron events
post_deploy: |
wp cron event run --due-now

```

## 5. Update App container depdencies
Expand Down Expand Up @@ -194,7 +195,26 @@ routes:
Matching the application name `myapp` with the `upstream` definition `myapp:http` is the most important setting to ensure at this stage.
If these strings aren't the same, the WordPress deployment will not succeed.

## 7. Update `.environment`
## 7. Add your crons

Under your application configuration you can now add a cron.

```yaml {configFile="app"}
applications:
myapp:
source:
root: "/"
type: 'php:8.3'
...
crons:
wp-cron:
spec: '*/10 * * * *'
commands:
start: wp cron event run --due-now
shutdown_timeout: 600
```

## 8. Update `.environment`

The CLI generated a `.environment` file during the Getting started guide. Notice it has already created some environment
variables for you to connect to your database service.
Expand All @@ -215,7 +235,7 @@ To configure the remaining environment variables that WordPress needs to run smo
2. Add the following at the end of the file:

```bash {location=".environment"}
export WP_HOME=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select(.value.primary == true) | .key')
export WP_HOME=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select(.value.primary == true) | if (.key[-1:] == "/") then (.key[0:-1]) else .key end')
export WP_SITEURL="${WP_HOME}/wp"
export WP_DEBUG_LOG=/var/log/app.log
# Uncomment this line if you would like development versions of WordPress on non-production environments.
Expand All @@ -230,7 +250,7 @@ To configure the remaining environment variables that WordPress needs to run smo
export NONCE_SALT="${PLATFORM_PROJECT_ENTROPY}NONCE_SALT"
```

## 8. Commit, Push, and Deploy!
## 9. Commit, Push, and Deploy!
You can now commit all the changes made to `.upsun/config.yaml` and `.environment` and push to {{% vendor/name %}}.

```bash {location="Terminal"}
Expand Down
24 changes: 22 additions & 2 deletions sites/upsun/src/get-started/stacks/wordpress/composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Such tasks include:

To launch these tasks during the deploy hook,
locate the `deploy:` section (below the `build:` section).</br>
Update the `deploy:` section as follows:
Update the `deploy:` and `post_deploy:` section as follows:

```yaml {configFile="app"}
applications:
Expand All @@ -202,6 +202,7 @@ applications:
wp cache flush
# Runs the WordPress database update procedure
wp core update-db
post_deploy: |
# Runs all due cron events
wp cron event run --due-now
```
Expand Down Expand Up @@ -235,7 +236,26 @@ routes:
Matching the application name `myapp` with the `upstream` definition `myapp:http` is the most important setting to ensure at this stage.
If these strings aren't the same, the WordPress deployment will not succeed.

## 7. Update your MariaDB service relationship
## 7. Add your crons

Under your application configuration you can now add a cron.

```yaml {configFile="app"}
applications:
myapp:
source:
root: "/"
type: 'php:8.3'
...
crons:
wp-cron:
spec: '*/10 * * * *'
commands:
start: wp cron event run --due-now
shutdown_timeout: 600
```

## 8. Update your MariaDB service relationship

You need to update the name used to represent the [relationship](/create-apps/app-reference/single-runtime-image.md#relationships) between your app and your MariaDB service.
To do so, locate the `relationships:` top-level property.
Expand Down
32 changes: 26 additions & 6 deletions sites/upsun/src/get-started/stacks/wordpress/vanilla.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ If you changed the name of the directory at step 1.4 you'll need to update the `
- Running any due cron jobs

To perform these tasks, we'll utilize the [deploy hook](/learn/overview/build-deploy.md#deploy-steps). Locate the
`deploy:` section (below the `build:` section). Update the `deploy:` section as follows:
`deploy:` section (below the `build:` section). Update the `deploy:` and `post_deploy:` section as follows:

```yaml {configFile="app"}
applications:
Expand All @@ -155,11 +155,31 @@ If you changed the name of the directory at step 1.4 you'll need to update the `
wp cache flush
# Runs the WordPress database update procedure
wp core update-db
post_deploy: |
# Runs all due cron events
wp cron event run --due-now
```

5. Add your crons

Under your application configuration you can now add a cron.

```yaml {configFile="app"}
applications:
myapp:
source:
root: "/"
type: 'php:8.3'
...
crons:
wp-cron:
spec: '*/10 * * * *'
commands:
start: wp cron event run --due-now
shutdown_timeout: 600
```

5. Locate the `routes:` section, and beneath it, the `"https://{default}/":` route. Update the route as follows:
6. Locate the `routes:` section, and beneath it, the `"https://{default}/":` route. Update the route as follows:

```yaml {configFile="app"}
applications:
Expand All @@ -180,7 +200,7 @@ If you changed the name of the directory at step 1.4 you'll need to update the `
- '/^wp-*/'
```

6. Optional: Add the wp-cli tool to your application build. Locate the `dependencies:` section that is commented out,
7. Optional: Add the wp-cli tool to your application build. Locate the `dependencies:` section that is commented out,
and update it as follows:

```yaml {configFile="app"}
Expand All @@ -195,7 +215,7 @@ If you changed the name of the directory at step 1.4 you'll need to update the `
wp-cli/wp-cli-bundle: "^2.4"
```

7. Add and commit your changes.
8. Add and commit your changes.

```bash {location="Terminal"}
git add .upsun/config.yaml
Expand Down Expand Up @@ -223,8 +243,8 @@ To configure the remaining environment variables WordPress needs to run smoothly
2. Add the following at the end of the file:

```bash {location=".environment"}
export WP_HOME=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select(.value.primary == true) | .key')
export WP_SITEURL="${WP_HOME}wordpress"
export WP_HOME=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select(.value.primary == true) | if (.key[-1:] == "/") then (.key[0:-1]) else .key end')
export WP_SITEURL="${WP_HOME}/wordpress"
export WP_DEBUG_LOG=/var/log/app.log
if [ "$PLATFORM_ENVIRONMENT_TYPE" != "production" ] ; then
export WP_ENV='development'
Expand Down