To solve the issue of installing a custom Git repository and setting a custom deploy script using the Laravel Forge SDK, you need to ensure that the repository is properly initialized and the deployment script is correctly set before triggering the deployment. Here's a step-by-step solution:
-
Initialize the Git Repository: First, ensure that the repository is correctly set up on the site. You can use the
installGitRepositoryOnSitemethod, but make sure the payload is correctly formatted. -
Set the Deployment Script: After setting up the repository, update the deployment script to include any necessary build steps like
npm run build. -
Deploy the Site: Finally, trigger the deployment.
Here's how you can achieve this:
// Initialize the Git repository on the site
$forge->installGitRepositoryOnSite($site->serverId, $site->id, [
'provider' => 'custom',
'repository' => $repoSshUrl, // Ensure this is the correct SSH URL
'branch' => $branchName, // Ensure this is the correct branch name
'composer' => true, // Run composer install if needed
]);
// Update the deployment script
$forge->updateSiteDeploymentScript($site->serverId, $site->id, $this->getDeployScript());
// Deploy the site
$forge->deploySite($site->serverId, $site->id);
Key Points:
-
Repository Initialization: Ensure that the SSH URL and branch name are correct. The
providershould be set to'custom'if you're using a custom Git server. -
Deployment Script: The deployment script should include all necessary commands to build and deploy your application. For example, if you need to run
npm installandnpm run build, make sure these commands are included in the script returned by$this->getDeployScript(). -
Error Handling: If you encounter the error
fatal: not a git repository, it usually means the repository wasn't initialized correctly. Double-check the SSH URL and ensure that the server has access to the repository.
By following these steps, you should be able to set up the Git repository and deploy your site using the Forge SDK. If issues persist, consider checking the Forge logs for more detailed error messages.