Skip to content

Commit

Permalink
Setup ability to run composer outside of root
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbushnell committed Jan 2, 2025
1 parent 0d160e4 commit 8eafd59
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,30 @@ jobs:
## ⚙️ Configuration options
| Environment Name | Default value | Description |
|------------------------------------|-----------------|-------------------------------------------------------------------------------------------------------------------------|
| `FORGE_TOKEN` | | The [API token](https://forge.laravel.com/docs/accounts/api) to use to authenticate to your Forge account |
| `FORGE_SERVER` | | The ID of the server to use when provisioning new sites |
| `FORGE_APP_ID` | | The prefix for your domain and database |
| `FORGE_PR_NUMBER` | | The PR number for your sandbox pull request |
| `FORGE_PHP_VERSION` | `php83` | The version of PHP to use |
| `FORGE_DOMAIN` | | The domain to use (Ex: `domain.com`) |
| `FORGE_DEPLOY_SCRIPT` | | Additional steps to add to your deploy process. Use `;` to delineate between steps (Ex: `npm install; npm run build`) |
| `FORGE_ENV_VARS` | | Environment variables to append (or replace if they already exist) |
| `FORGE_ENV_VARS` | | Environment variables to append (or replace if they already exist) |
| `FORGE_COMPOSER_INSTALL_ON_MOUNT` | `true` | If `composer install` should be ran when the repo is mounted |
| `FORGE_ENABLE_DB` | `false` | Whether your site needs a database. If `true` one will be created for you and shared in the post-deploy comment |
| `FORGE_DB_PASSWORD` | | The master password for your `forge` database user. This will be placed into your project's .env automatically |
| `FORGE_BACKUP_PROVIDER` | | When set and when your sandbox uses a database it will be backed up to this provider. Accepts `s3` or `spaces` |
| `FORGE_BACKUP_REGION` | | The region for the backup service you are using |
| `FORGE_BACKUP_BUCKET` | | The bucket to use for the backup |
| `FORGE_BACKUP_ACCESS_KEY` | | The access key for connecting to the bucket |
| `FORGE_BACKUP_SECRET_KEY` | | The secret key for connecting to the bucket |
| `FORGE_GITHUB_TOKEN` | | Used to create a post-deploy comment within the pull request |
| `FORGE_REPO` | | The GitHub repo to deploy and mount for the sandbox generation (Ex: `myorg/repo`) |
| `FORGE_BRANCH` | | The branch to use when mounting your repo to the site |
| `FORGE_POST_MOUNT_COMMANDS` | | Commands to run after the repository is first mounted |
| Environment Name | Default value | Description |
|------------------------------------|-----------------|----------------------------------------------------------------------------------------------------------------------------|
| `FORGE_TOKEN` | | The [API token](https://forge.laravel.com/docs/accounts/api) to use to authenticate to your Forge account |
| `FORGE_SERVER` | | The ID of the server to use when provisioning new sites |
| `FORGE_APP_ID` | | The prefix for your domain and database |
| `FORGE_PR_NUMBER` | | The PR number for your sandbox pull request |
| `FORGE_PHP_VERSION` | `php83` | The version of PHP to use |
| `FORGE_DOMAIN` | | The domain to use (Ex: `domain.com`) |
| `FORGE_DEPLOY_SCRIPT` | | Additional steps to add to your deploy process. Use `;` to delineate between steps (Ex: `npm install; npm run build`) |
| `FORGE_ENV_VARS` | | Environment variables to append (or replace if they already exist) |
| `FORGE_ENV_VARS` | | Environment variables to append (or replace if they already exist) |
| `FORGE_COMPOSER_INSTALL_ON_MOUNT` | `true` | If `composer install` should be ran when the repo is mounted. |
| `FORGE_ENABLE_DB` | `false` | Whether your site needs a database. If `true` one will be created for you and shared in the post-deploy comment |
| `FORGE_DB_PASSWORD` | | The master password for your `forge` database user. This will be placed into your project's .env automatically |
| `FORGE_BACKUP_PROVIDER` | | When set and when your sandbox uses a database it will be backed up to this provider. Accepts `s3` or `spaces` |
| `FORGE_BACKUP_REGION` | | The region for the backup service you are using |
| `FORGE_BACKUP_BUCKET` | | The bucket to use for the backup |
| `FORGE_BACKUP_ACCESS_KEY` | | The access key for connecting to the bucket |
| `FORGE_BACKUP_SECRET_KEY` | | The secret key for connecting to the bucket |
| `FORGE_GITHUB_TOKEN` | | Used to create a post-deploy comment within the pull request |
| `FORGE_REPO` | | The GitHub repo to deploy and mount for the sandbox generation (Ex: `myorg/repo`) |
| `FORGE_BRANCH` | | The branch to use when mounting your repo to the site |
| `FORGE_POST_MOUNT_COMMANDS` | | Commands to run after the repository is first mounted. Use `;` to delineate between steps (Ex: `ls -lah; echo 'hi'`) |
| `FORGE_PATH_TO_COMPOSER_FILE` | | The path to your composer.json file if not in the root of the project (Ex: `src/`) |

## 🔒 Backups

Expand Down
10 changes: 9 additions & 1 deletion app/Data/Sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ public function updateDeployScript(): void
'# Default Blacksmith commands',
'cd $FORGE_SITE_PATH',
'git pull origin $FORGE_SITE_BRANCH',
'$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader',
];

// Setup composer install command and append the working directory flag if necessary
$composerCmd = '$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader';

if (config('forge.path_to_composer_file')) {
$composerCmd .= " --working-dir=" . config('forge.path_to_composer_file');
}

$defaultCommands[] = $composerCmd;

$userCommands = str(config('forge.deploy_script'))
->explode(';')
->filter()
Expand Down
Binary file modified builds/blacksmith
Binary file not shown.
3 changes: 3 additions & 0 deletions config/forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
// The token for the GitHub API to post details to the PR
'github_token' => env('FORGE_GITHUB_TOKEN'),

// Path to the composer.json file (if not in the root of the repo)
'path_to_composer_file' => env('FORGE_PATH_TO_COMPOSER_FILE'),

// Post-mount commands to run
'post_mount_commands' => env('FORGE_POST_MOUNT_COMMANDS'),
];

0 comments on commit 8eafd59

Please sign in to comment.