-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
# laravel-deploy-action | ||
Automatically deploy your Laravel app to remote server | ||
|
||
### Step one | ||
You need to create four environments that we need to connect the remote server, then create your workflow like below | ||
```yaml | ||
name: Deoloy | ||
on: [push] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
name: A Laravel deploy action example | ||
steps: | ||
- name: test | ||
uses: yankewei/laravel-deploy-action@main | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
password: ${{ secrets.SSH_PASSWORD }} | ||
app_env_data: ${{ secrets.APP_ENV_DATA }} | ||
``` | ||
Below is the environment description | ||
```yaml | ||
host: | ||
description: 'The remote server ip, support IPV4 only' | ||
required: true | ||
username: | ||
description: 'The ssh login user name' | ||
required: true | ||
password: | ||
description: 'The ssh login password' | ||
required: true | ||
app_env_data: | ||
description: 'The environment variable for application, will be written into .env file' | ||
required: true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
// Get the required information when connect remote server | ||
$host = getenv('HOST'); | ||
$username = getenv('USERNAME'); | ||
$password = getenv('PASSWORD'); | ||
|
||
// Create a session between with the remote server | ||
$ssh_session = ssh2_connect($host); | ||
|
||
// Use password to connect server | ||
if (!ssh2_auth_password($ssh_session, $username, $password)) { | ||
exit('Failed to connect the remote server'); | ||
} | ||
|
||
// Get the application environment variable from github action env | ||
$env = getenv('APP_ENV_DATA'); | ||
$env_array = explode("\n", $env); | ||
|
||
// Put the env data into .env file | ||
$cmd = 'cd /var/www/site;cat /dev/null > .env;'; | ||
foreach ($env_array as $value) { | ||
$cmd .= "echo $value >> .env;"; | ||
} | ||
|
||
// Run command and deploy application | ||
$cmd .= 'php artisan down;'; | ||
$cmd .= 'git pull origin main;'; | ||
$cmd .= 'composer install --no-dev;'; | ||
$cmd .= 'php artisan migrate --force;'; | ||
$cmd .= 'php artisan optimize;'; | ||
$cmd .= 'php artisan up;'; | ||
|
||
$stream = ssh2_exec($ssh_session, $cmd); | ||
|
||
echo stream_get_contents($stream); | ||
|
||
ssh2_disconnect($ssh_session); |