trendyminds / blacksmith-cli
A Forge-provisioning CLI tool for sandboxes
Installs: 70
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^8.2.0
- illuminate/http: ^11.35
- illuminate/validation: ^11.36
- intonate/tinker-zero: ^1.2
- laravel/forge-sdk: ^3.19
Requires (Dev)
- laravel-zero/framework: ^11.0.2
- laravel/pint: ^1.18.1
- mockery/mockery: ^1.6.12
- pestphp/pest: ^3.5.1
README
A Forge-provisioning CLI tool for sandboxes
✅ Requirements
When provisioning a sandbox you'll need:
- A Forge API token
- An ID of a Forge server to deploy to
It is imperative to leverage GitHub secrets to ensure you are not commit this type of sensitive data to your codebase and potentially exposing this data to the outside world.
🚀 Creating and destroying sandboxes
Below is an example of a GitHub action that will create a new sandbox when it is labeled with a "sandbox" tag in the pull request. When the pull request is closed it will run the decommission action.
name: Sandbox on: pull_request: types: [labeled, reopened, closed] jobs: sandbox: if: contains(github.event.pull_request.labels.*.name, 'sandbox') runs-on: ubuntu-latest env: FORGE_APP_ID: app FORGE_DOMAIN: example.com FORGE_DEPLOY_SCRIPT: "npm install; npm run build" FORGE_TOKEN: ${{ secrets.BLACKSMITH_FORGE_TOKEN }} FORGE_SERVER: ${{ secrets.BLACKSMITH_SANDBOX_SERVER }} FORGE_REPO: ${{ github.repository }} FORGE_BRANCH: ${{ github.head_ref }} FORGE_PR_NUMBER: ${{ github.event.number }} FORGE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: php-version: 8.3 coverage: none - name: Install Blacksmith run: composer global require trendyminds/blacksmith-cli - name: Create Sandbox (If PR was just opened or reopened) if: github.event.action != 'closed' run: blacksmith create - name: Destroy Sandbox (When PR is closed) if: github.event.action == 'closed' run: blacksmith destroy
⚙️ Configuration options
🔒 Backups
Unfortunately, Forge's backup configuration and storage processes are asynchronous and, because of this, a lengthy and arbitrary sleep()
method is used when running these. That means it's possible a database backup when your sandbox is decommissioned may not complete successfully. For tried-and-true backups consider running a separate backup process on Forge to ensure you have a method to restore databases if necessary.
Statamic notes
Git Automation
Git automation should be enabled by including STATAMIC_GIT_AUTOMATIC
in your environment variables and setting it to false
.
This means content commits have to be manually performed by visiting Utilties > Git. However, it greatly simplifies your sandbox:
- You do not need to run Redis in every Statamic sandbox you create handling queued commits
- You do not need to commit every single content save to your pull request if you do not queue your commits
While STATAMIC_GIT_AUTOMATIC=false
means some occasional manual labor, it makes the setup simpler and also enables you to create Statamic sandboxes that shouldn't have committed sandbox changes.