Skip to content

Commit

Permalink
Feature/add more flexibility (#413)
Browse files Browse the repository at this point in the history
Co-authored-by: Taylor Lovett <tlovett88@gmail.com>
  • Loading branch information
dustinrue and tlovett1 authored Aug 21, 2024
1 parent 899d907 commit 8b74e5a
Show file tree
Hide file tree
Showing 22 changed files with 548 additions and 241 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-pumpkins-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"10up-toolkit": patch
---

Simple enhancements to toolkit project command to align with devops needs.
24 changes: 8 additions & 16 deletions packages/toolkit/PROJECTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,34 @@ In this scenario, `deploy_from` would be set to `wp` and `deploy_to_subdir` woul

`deploy_type` currently supports `rsync`, `wpe` (WP Engine), and `pantheon`. It defaults to `rsync`. If WPE or Pantheon is choosen, `deploy_to` should contain a Git URL. More deploy types will be added in the future.

The following are additional optional variables that allow you to use custom scripts different than the ones provided by 10up Toolkit. You shouldn't need to use these unless you are doing something super custom. All these paths are relative from the root of your project.

```yaml
deploy_script_path: "" # Custom deploy script
build_script_path: "" # For using a build script in a different location
create_payload_script_path: "" # Custom create payload script
```
## Commands

The project subcommand provides a variety of utlities for creating, building, and deploying 10up-specific projects.

List of commands:

```bash
10up-toolkit project init [<path>] [--template=<Git repository>] [--name=<Project Name>] [--confirm] [--skip-composer]
10up-toolkit project init [--path=<path>] [--layout=<layout>] [--template=<Git repository>] [--name=<Project Name>] [--confirm] [--skip-composer] [--skip-ci]
```

`init` creates a project. You can optionally provide it a number of parameters or answer the prompts. If no path is provided, it will initialize the project in the current directory. You will be prompted to choose a template e.g. [WP Scaffold](https://github.com/10up/wp-scaffold). Init will automatically search and replace prefixes using the project name you provide.
`init` creates a project. You can optionally provide it a number of parameters or answer the prompts. If no path is provided, it will initialize the project in the current directory. If no layout is provided, it will default to `wpcontent` which means the project is rooted in `wp-content` (The other option is `wpparent` where the root of the project is one directory above WordPress). You will be prompted to choose a template e.g. [WP Scaffold](https://github.com/10up/wp-scaffold). Init will automatically search and replace prefixes using the project name you provide.

```bash
10up-toolkit project build
10up-toolkit project build [--type=<type>]
```

`build` simply executes your `scripts/build.sh` file (or other path you specify). `build` will be executed before deploying files.
`build` will build your project e.g. `composer install`, `npm install`, and `npm run build`. It will execute all the `.sh` files in your `scripts/` directory where you can add custom build logic for your particular project. `--type` defaults to local e.g. build for your local environment. In CI, type will be set to `full`.

```bash
10up-toolkit project create-payload <branch>
10up-toolkit project generate-ci [--confirm] [--path=<path>]
```

This command creates a payload directory of the built project (including WordPress) for deployment. Engineers likely won't need to run this command themselves as GitLab does it automatically. You must provide a branch that corresponds to an environment in `.tenup.yml`.
This command generates necessary CI files. For GitLab, this would be `.gitlab-ci.yml`. Right now this only supports GitLab but we will add support for GitHub in the future.

```bash
10up-toolkit project generate-ci [--confirm] [--path=<path>]
10up-toolkit project update-composer
```

This command generates necessary CI files. For GitLab, this would be `.gitlab-ci.yml`. Right now this only supports GitLab but we will add support for GitHub in the future.
Convenience function to update all dependencies in all found composer.json files. Also generates updated lock files.

**Note that generating CI files is currently in alpha and may require manual editing to fix issues.**
3 changes: 0 additions & 3 deletions packages/toolkit/project/default-variables.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"project_name": "10up Project",
"php_version": "8.2",
"build_script_path": "",
"wordpress_version": "",
"deploy_script_path": "",
"create_payload_script_path": "",
"environments": []
}
2 changes: 1 addition & 1 deletion packages/toolkit/project/gitlab/.gitlab-ci.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build_plugins_and_themes:
stage: build
script:
- nvm install 18
- npx 10up-toolkit project create-payload $CI_COMMIT_REF_NAME
- npx 10up-toolkit project build --type=full
artifacts:
paths:
- payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ deploy_production:
MULTI_DEV_ENVIRONMENT: "{{branch}}"
WORDPRESS_VERSION: {{wordpress_version}}
GIT_URL: {{deploy_to}}
EXCLUDES: {{deploy_file_excludes}}
EXCLUDES: {{rsync_file_excludes}}
allow_failure: false
only:
refs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ deploy_{{branch}}:
MULTI_DEV_ENVIRONMENT: "{{branch}}"
WORDPRESS_VERSION: {{wordpress_version}}
GIT_URL: {{deploy_to}}
EXCLUDES: {{deploy_file_excludes}}
EXCLUDES: {{rsync_file_excludes}}
allow_failure: false
only:
refs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ deploy_production:
variables:
DESTINATION: {{deploy_to}}
SUBDIR: {{deploy_to_subdir}}
EXCLUDES: {{deploy_file_excludes}}
EXCLUDES: {{rsync_file_excludes}}
only:
refs:
- {{branch}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ deploy_{{branch}}:
variables:
DESTINATION: {{deploy_to}}
SUBDIR: {{deploy_to_subdir}}
EXCLUDES: {{deploy_file_excludes}}
EXCLUDES: {{rsync_file_excludes}}
only:
refs:
- {{branch}}
26 changes: 26 additions & 0 deletions packages/toolkit/project/local/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
payload
build/vendor
build/composer.lock
build/composer.json
/vendor
wordpress/.env
wordpress/*php
wordpress/wp-content/uploads
wordpress/wp-includes
wordpress/wp-admin
wordpress/license.txt
wordpress/readme.html
!wordpress/wp-config.php
docker-compose.override.yml
.config.json
wordpress/wp-content/advanced-cache.php
wordpress/wp-content/mu-plugins/10up-experience.php
wordpress/wp-content/mu-plugins/10up-experience/
wordpress/wp-content/mu-plugins/batcache.php
wordpress/wp-content/mu-plugins/batcache/
wordpress/wp-content/mu-plugins/redis-cache.php
wordpress/wp-content/mu-plugins/redis-cache/
wordpress/wp-content/mu-plugins/s3-uploads.php
wordpress/wp-content/mu-plugins/s3-uploads/
wordpress/wp-content/object-cache.php
.lock
21 changes: 17 additions & 4 deletions packages/toolkit/project/local/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Add builds scripts here. This script will be run from the root of your project (same directory as .tenup.yml).
#!/usr/bin/env bash -l
# NOTE: you should keep the above line, at line 1. Only modify if you know what you are doing.

nvm install
node -v
npm install
# You should use npx 10up-toolkit build to build your project. When you do, there are a number of things
# you get "for free" including nvm handling and the basics of building are handled automatically. You
# only need to provide additional build routines if the default build system doesn't quite get things
# right. Adding build scripts is easy. Create as many .sh files as you need in this scripts directory.

# Here is an example script you can use to get you started It assumes you are using a "modern" layout.

# change directories to your theme or plugin
pushd .

# run your build commands
echo "Hello World!"

# return to where we were so the next build script starts off from the same place
popd
7 changes: 7 additions & 0 deletions packages/toolkit/scripts/project/bash/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:latest

USER root
WORKDIR /var/www/html
COPY payload .
RUN mkdir wp-content/uploads && \
chown 33:33 wp-content/uploads
13 changes: 0 additions & 13 deletions packages/toolkit/scripts/project/bash/build-setup.sh

This file was deleted.

20 changes: 0 additions & 20 deletions packages/toolkit/scripts/project/bash/create-payload.sh

This file was deleted.

Loading

0 comments on commit 8b74e5a

Please sign in to comment.