Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed May 20, 2024
1 parent af8b165 commit ebf2bb3
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 29 deletions.
12 changes: 10 additions & 2 deletions packages/toolkit/PROJECTS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# 10up Projects
# 10up Projects (BETA)

**This subcommand is currently in BETA**

10up Toolkit provides a number of utlities for creating, managing, and deploying 10up specific projects.

Expand Down Expand Up @@ -32,13 +34,15 @@ environments:
deploy_to: "gitlab@1.1.1.1:/var/www/my-project"
deploy_to_subdir: "wp-content/"
deploy_from: "./"
deploy_type: "rsync"
url: "https://environmenturl.com"
staging:
branch: "staging"
wordpress_version: "6.4"
deploy_to: "gitlab@1.1.1.1:/var/www/my-project"
deploy_to_subdir: "wp-content/"
deploy_from: "./"
deploy_type: "rsync"
url: "https://environmenturl.com"
```

Expand All @@ -52,6 +56,8 @@ environments:

In this scenario, `deploy_from` would be set to `wp` and `deploy_to_subdir` would be `./`.

`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
Expand Down Expand Up @@ -89,4 +95,6 @@ This command creates a payload directory of the built project (including WordPre
10up-toolkit project generate-ci [--confirm]
```

This command generates necessary CI files. For GitLab, this would be `.gitlab-ci.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.

**Note that generating CI files is currently in alpha and may require manual editing to fix issues.**
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
deploy_production:
extends: .wordpress-deploy-pantheon-v2
environment:
name: Production
url: {{url}}
variables:
MULTI_DEV_ENVIRONMENT: "{{branch}}"
WORDPRESS_VERSION: {{wordpress_version}}
GIT_URL: {{deploy_to}}
EXCLUDES: {{deploy_file_excludes}}
allow_failure: false
only:
refs:
- {{branch}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
deploy_{{branch}}:
extends: .wordpress-deploy-pantheon-v2
environment:
name: {{branch}}
url: {{url}}
variables:
MULTI_DEV_ENVIRONMENT: "{{branch}}"
WORDPRESS_VERSION: {{wordpress_version}}
GIT_URL: {{deploy_to}}
EXCLUDES: {{deploy_file_excludes}}
allow_failure: false
only:
refs:
- {{branch}}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
deploy_production:
stage: deploy
extends: .wordpress-deploy-rsync
environment:
name: Production
url: {{url}}
script:
- rsync -vrxc --delete --exclude-from={{deploy_file_excludes}} ./payload/ {{deploy_to}}/{{deploy_to_subdir}}/
only:
- {{branch}}
variables:
WORDPRESS_VERSION: {{wordpress_version}}
DESTINATION: {{deploy_to}}
SUBDIR: {{deploy_to_subdir}}
EXCLUDES: {{deploy_file_excludes}}
only:
refs:
- {{branch}}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
deploy_stage:
deploy_{{branch}}:
stage: deploy
extends: .wordpress-deploy-rsync
environment:
name: Staging
name: {{branch}}
url: {{url}}
script:
- rsync -vrxc --delete --exclude-from={{deploy_file_excludes}} ./payload/ {{deploy_to}}/{{deploy_to_subdir}}/
only:
- {{branch}}
variables:
WORDPRESS_VERSION: {{wordpress_version}}
DESTINATION: {{deploy_to}}
SUBDIR: {{deploy_to_subdir}}
EXCLUDES: {{deploy_file_excludes}}
only:
refs:
- {{branch}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ deploy_production:
stage: deploy
extends: .wordpress-deploy-wpe
environment:
name: WPE Production
name: Production
url: {{url}}
variables:
GIT_URL: {{deploy_to}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
deploy_stage:
deploy_{{branch}}:
stage: deploy
extends: .wordpress-deploy-wpe
environment:
name: WPE Staging
name: {{branch}}
url: {{url}}
variables:
GIT_URL: {{deploy_to}}
Expand Down
35 changes: 23 additions & 12 deletions packages/toolkit/scripts/project/generate-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ const run = async (cnf = false) => {
value: 'gitlab',
},
{
name: 'None',
value: 'none',
},
/* {
name: 'GitHub',
value: 'github',
},
}, */
],
message: 'Choose a CI type:',
});
Expand All @@ -66,6 +70,10 @@ const run = async (cnf = false) => {

type = results.type || type;

if (type === 'none') {
return;
}

if (type === 'gitlab') {
// Load template file into a string
const template = fs.readFileSync(
Expand All @@ -80,19 +88,22 @@ const run = async (cnf = false) => {

const fileEnv = env === 'production' ? 'production' : 'staging';

if (!environment.deploy_type || environment.deploy_type === 'rsync') {
const deployTemplate = fs.readFileSync(
resolve(__dirname, `../../project/gitlab/deploy-configs/rsync-${fileEnv}.tmpl`),
'utf8',
);
let filePath = `../../project/gitlab/deploy-configs/rsync-${fileEnv}.tmpl`;

const preparedDeployTemplate = replaceVariables(deployTemplate, {
...variables,
...environment,
});

preparedTemplate += `\n${preparedDeployTemplate}`;
if (environment.deploy_type === 'wpe' || environment.deploy_type === 'wpengine') {
filePath = `../../project/gitlab/deploy-configs/wpe-${fileEnv}.tmpl`;
} else if (environment.deploy_type === 'pantheon') {
filePath = `../../project/gitlab/deploy-configs/pantheon-${fileEnv}.tmpl`;
}

const deployTemplate = fs.readFileSync(resolve(__dirname, filePath), 'utf8');

const preparedDeployTemplate = replaceVariables(deployTemplate, {
...variables,
...environment,
});

preparedTemplate += `\n${preparedDeployTemplate}`;
});

fs.writeFileSync(`${root}/.gitlab-ci.yml`, preparedTemplate);
Expand Down

0 comments on commit ebf2bb3

Please sign in to comment.