From 9e8bdd30d94282c6fd15cb65d13b23d389866f8f Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 11 Oct 2023 23:14:46 -0400 Subject: [PATCH 1/4] Added autodeploy --- .github/workflows/deploy.yml | 30 +++++++++++++++++++++++++ deploy.php | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 deploy.php diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..f942d25 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,30 @@ +name: deploy + +on: + release: + types: [released] + +concurrency: production_environment + +jobs: + production: + runs-on: ubuntu-latest + environment: Production + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.2" + + - name: Install dependencies + run: composer install --no-interaction --no-scripts --prefer-dist --no-dev + + + - name: Deploy + uses: deployphp/action@v1 + with: + private-key: ${{ secrets.DEPLOY_KEY }} + dep: deploy production --tag=${{ githib.ref }} diff --git a/deploy.php b/deploy.php new file mode 100644 index 0000000..aa622cc --- /dev/null +++ b/deploy.php @@ -0,0 +1,43 @@ +set('hostname', 'vps.benjamyn.love') + ->set('port', '22') + ->set('remote_user', 'root') + ->set('deploy_path'), '/opt/PriceyBotPanel'); + + +// Tasks +task('npm:build', function () { + $command = match (get('alias')) { + 'production' => 'production', + 'staging' => 'development', + default => 'production' +}; + +run("cd {{release_path}} && {{bin/npm}} run {$command}"); +}); + +// Hooks +after('deploy:vendors', 'npm:install'); +after('npm:install', 'npm:build'); +after('deploy:failed', 'deploy:unlock'); From cfa9be47058215490043555142b37c6669dac3e6 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 12 Oct 2023 00:55:34 -0400 Subject: [PATCH 2/4] Testing --- .github/workflows/deploy.yml | 10 ++++++-- composer.json | 6 ++--- composer.lock | 47 ++++++++++++++++++++++++++++++++++-- deploy.php | 4 +-- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f942d25..a263335 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -17,14 +17,20 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: + tools: composer + extensions: bcmath, ctype, fileinfo, json, odbc, mbstring, openssl, pdo, pdo_mysql, pdo_odbc tokenizer, xml, soap, redis, igbinary php-version: "8.2" + ssh-config: | + Host benhub + Port 9001 + User git - name: Install dependencies - run: composer install --no-interaction --no-scripts --prefer-dist --no-dev + run: composer install --no-interaction --no-scripts --prefer-dist - name: Deploy uses: deployphp/action@v1 with: private-key: ${{ secrets.DEPLOY_KEY }} - dep: deploy production --tag=${{ githib.ref }} + dep: deploy production diff --git a/composer.json b/composer.json index ba0c6a7..3e54354 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ }, "require-dev": { "barryvdh/laravel-ide-helper": "^2.13", + "deployer/deployer": "^7.3", "fakerphp/faker": "^1.9.1", "laravel/breeze": "^1.24", "laravel/pint": "^1.0", @@ -44,10 +45,7 @@ ], "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force", - "Illuminate\\Foundation\\ComposerScripts::postUpdate", - "@php artisan ide-helper:generate", - "@php artisan ide-helper:models --write-mixin", - "@php artisan ide-helper:meta" + "Illuminate\\Foundation\\ComposerScripts::postUpdate" ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" diff --git a/composer.lock b/composer.lock index 9dfa19f..d4ec390 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "feae295eec753591e7cf70bf21f57924", + "content-hash": "6f613b80fde0f91b5425be61accfc51f", "packages": [ { "name": "brick/math", @@ -6158,6 +6158,49 @@ ], "time": "2022-11-17T09:50:14+00:00" }, + { + "name": "deployer/deployer", + "version": "v7.3.1", + "source": { + "type": "git", + "url": "https://github.com/deployphp/deployer.git", + "reference": "c5c5e79d4e57445918ed24a9cdd3d85b0f261de3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/deployphp/deployer/zipball/c5c5e79d4e57445918ed24a9cdd3d85b0f261de3", + "reference": "c5c5e79d4e57445918ed24a9cdd3d85b0f261de3", + "shasum": "" + }, + "bin": [ + "dep" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anton Medvedev", + "email": "anton@medv.io" + } + ], + "description": "Deployment Tool", + "homepage": "https://deployer.org", + "support": { + "docs": "https://deployer.org/docs", + "issues": "https://github.com/deployphp/deployer/issues", + "source": "https://github.com/deployphp/deployer" + }, + "funding": [ + { + "url": "https://github.com/sponsors/antonmedv", + "type": "github" + } + ], + "time": "2023-04-05T09:24:30+00:00" + }, { "name": "doctrine/cache", "version": "2.2.0", @@ -9758,5 +9801,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/deploy.php b/deploy.php index aa622cc..bca695a 100644 --- a/deploy.php +++ b/deploy.php @@ -8,7 +8,7 @@ require 'contrib/npm.php'; // Config set('git_ssh_command', 'ssh'); -set('repository', 'git@ssh.git.lovelynet.net:9001/PriceyBot/PriceyBotPanel.git'); +set('repository', 'benhub/PriceyBot/PriceyBotPanel.git'); add('shared_files', []); add('shared_dirs', []); @@ -23,7 +23,7 @@ host('production') ->set('hostname', 'vps.benjamyn.love') ->set('port', '22') ->set('remote_user', 'root') - ->set('deploy_path'), '/opt/PriceyBotPanel'); + ->set('deploy_path', '/opt/PriceyBotPanel2'); // Tasks From bf8dda5a4ccb7873ee0d77609e37c5d17191804b Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 12 Oct 2023 01:28:34 -0400 Subject: [PATCH 3/4] Fixed deploy --- .github/workflows/deploy.yml | 4 ---- deploy.php | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a263335..5a8b2ec 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,10 +20,6 @@ jobs: tools: composer extensions: bcmath, ctype, fileinfo, json, odbc, mbstring, openssl, pdo, pdo_mysql, pdo_odbc tokenizer, xml, soap, redis, igbinary php-version: "8.2" - ssh-config: | - Host benhub - Port 9001 - User git - name: Install dependencies run: composer install --no-interaction --no-scripts --prefer-dist diff --git a/deploy.php b/deploy.php index bca695a..6a09e1e 100644 --- a/deploy.php +++ b/deploy.php @@ -8,7 +8,7 @@ require 'contrib/npm.php'; // Config set('git_ssh_command', 'ssh'); -set('repository', 'benhub/PriceyBot/PriceyBotPanel.git'); +set('repository', 'ssh://git@ssh.git.lovelynet.net:9001/PriceyBot/PriceyBotPanel.git'); add('shared_files', []); add('shared_dirs', []); @@ -33,10 +33,10 @@ task('npm:build', function () { 'staging' => 'development', default => 'production' }; - run("cd {{release_path}} && {{bin/npm}} run {$command}"); }); + // Hooks after('deploy:vendors', 'npm:install'); after('npm:install', 'npm:build'); From 33028358380eb54dfc65cbb21cb0430d855eef9c Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 12 Oct 2023 02:24:23 -0400 Subject: [PATCH 4/4] Fix idehelperissues? --- composer.json | 5 ++++- deploy.php | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3e54354..086f945 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,10 @@ ], "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force", - "Illuminate\\Foundation\\ComposerScripts::postUpdate" + "Illuminate\\Foundation\\ComposerScripts::postUpdate", + "@php artisan ide-helper:generate", + "@php artisan ide-helper:models --write-mixin", + "@php artisan ide-helper:meta" ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" diff --git a/deploy.php b/deploy.php index 6a09e1e..b2201c2 100644 --- a/deploy.php +++ b/deploy.php @@ -23,7 +23,7 @@ host('production') ->set('hostname', 'vps.benjamyn.love') ->set('port', '22') ->set('remote_user', 'root') - ->set('deploy_path', '/opt/PriceyBotPanel2'); + ->set('deploy_path', '/opt/PriceyBotPanel'); // Tasks @@ -36,8 +36,13 @@ task('npm:build', function () { run("cd {{release_path}} && {{bin/npm}} run {$command}"); }); +task('perm:fix', function () { + run("chown -R nginx:nginx /opt/PriceyBotPanel"); +}); + // Hooks after('deploy:vendors', 'npm:install'); after('npm:install', 'npm:build'); +after('npm:build', 'perm:fix'); after('deploy:failed', 'deploy:unlock');