-
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
10 changed files
with
127 additions
and
152 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
# Deploy | ||
|
||
1. apt-get install certbot -y && certbot certonly --standalone --agree-tos --register-unsafely-without-email --key-type rsa -d backend.oldpersiangames.org && certbot renew --dry-run | ||
1. get docker-compose.yml and put in /opt/opgmanager-backend/docker-compose.yml (remove build at app and uncomment image at app) | ||
1. copy .env file kenare docker-compose.yml, set mysql host to "db", and set user pass, add APP_KEY, also: | ||
SANCTUM_STATEFUL_DOMAINS=dash.oldpersiangames.org | ||
SESSION_DOMAIN=.oldpersiangames.org | ||
FRONTEND_URL=https://dash.oldpersiangames.org | ||
also TELEGRAM_TOKEN=bot_token and OWNER_TG_ID=yourid | ||
also TELEGRAM_API and TELEGRAM_HASH for your python bot | ||
1. docker compose pull && docker compose up --build -d && docker compose exec app bash -c "php artisan config:cache && php artisan route:cache && php artisan optimize" | ||
1. git clone https://${BACKUP_TOKEN}@github.com/oldpersiangames/opg-backups /opgactions/opg-backups && cd /opgactions/opg-backups && git config user.email [email protected] && git config user.name alihardan | ||
1. docker compose exec app bash -c "mysql -h db -u opg -p123456 opg < /opgactions/opg-backups/opgmanager.sql" | ||
1. docker compose exec app bash -c "chown -R application:application /opgactions" | ||
- apt-get install certbot -y && certbot certonly --standalone --agree-tos --register-unsafely-without-email --key-type rsa -d backend.oldpersiangames.org && certbot renew --dry-run | ||
- get docker-compose.yml and put in /opt/opgbackend/docker-compose.yml (remove build at app and uncomment image at app) | ||
- copy .env file kenare docker-compose.yml, set mysql host to "db", and set user pass, add APP_KEY, also: | ||
SANCTUM_STATEFUL_DOMAINS=dash.oldpersiangames.org | ||
SESSION_DOMAIN=.oldpersiangames.org | ||
FRONTEND_URL=https://dash.oldpersiangames.org | ||
also TELEGRAM_TOKEN=bot_token and OWNER_TG_ID=yourid | ||
also TELEGRAM_API and TELEGRAM_HASH for your python bot | ||
also OPG_KEY_HASH | ||
- docker compose pull && docker compose up --build -d | ||
- git clone https://${BACKUP_TOKEN}@github.com/oldpersiangames/opg-backups /opgactions/opg-backups && cd /opgactions/opg-backups && git config user.email [email protected] && git config user.name alihardan | ||
- docker compose exec app bash -c "mysql -h db -u opg -p123456 opg < /opgactions/opg-backups/opgbackend.sql" | ||
- docker compose exec app bash -c "chown -R application:application /opgactions" | ||
- docker compose exec app bash -c "php artisan config:cache && php artisan route:cache && php artisan optimize" |
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
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,77 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Process; | ||
use App\Models\Game; | ||
use App\Models\Item; | ||
use App\Models\TGFile; | ||
use SergiX44\Nutgram\Nutgram; | ||
|
||
class CICDController extends Controller | ||
{ | ||
public function makeBackup(Request $request) | ||
{ | ||
if (hash('sha256', $request->key) != env('OPG_KEY_HASH')) | ||
abort(403); | ||
|
||
Process::path('/opgactions/opg-backups')->run('mysqldump --skip-extended-insert --skip-dump-date -h' . env('DB_HOST') . ' -u' . env('DB_USERNAME') . ' -p' . env('DB_PASSWORD') . ' ' . env('DB_DATABASE') . ' > opgbackend.sql'); | ||
Process::path('/opgactions/opg-backups')->run('git add .'); | ||
Process::path('/opgactions/opg-backups')->run('git commit -m "' . Carbon::now()->setTimezone('UTC')->toDateTimeString() . '"'); | ||
Process::path('/opgactions/opg-backups')->run('git push'); | ||
} | ||
|
||
public function beforeIa(Request $request) | ||
{ | ||
if (hash('sha256', $request->key) != env('OPG_KEY_HASH')) | ||
abort(403); | ||
|
||
$games = Game::whereNull('ia_id')->where('selling', false) | ||
->whereNot('slug', 'grand-theft-auto-san-andreas-oldpersiangames') | ||
->get(['slug', 'tgfiles', 'games', 'title_en'])->map(function ($game) { | ||
$tgfiles = TGFile::whereIn('file_unique_id', $game->tgfiles)->orderByRaw("FIELD(file_unique_id, '" . implode("','", $game->tgfiles) . "')")->get(['file_name', 'file_size', 'file_id', 'file_unique_id', 'date']); | ||
$game->tgfiles = $tgfiles->toArray(); | ||
|
||
$game->title = $game->title_en ?? $game->games[0]['title_en'][0]; | ||
$game->type = 'game'; | ||
unset($game->title_en); | ||
unset($game->games); | ||
return $game; | ||
}); | ||
|
||
|
||
$items = Item::whereNull('ia_id')->where('selling', false) | ||
->get(['slug', 'tgfiles', 'title_en'])->map(function ($item) { | ||
$tgfiles = TGFile::whereIn('file_unique_id', $item->tgfiles)->orderByRaw("FIELD(file_unique_id, '" . implode("','", $item->tgfiles) . "')")->get(['file_name', 'file_size', 'file_id', 'file_unique_id', 'date']); | ||
$item->tgfiles = $tgfiles->toArray(); | ||
|
||
$item->title = $item->title_en; | ||
$item->type = 'item'; | ||
return $item; | ||
}); | ||
|
||
return [...$games, ...$items]; | ||
} | ||
|
||
public function setIa(Request $request, Nutgram $bot) | ||
{ | ||
if (hash('sha256', $request->key) != env('OPG_KEY_HASH')) | ||
abort(403); | ||
|
||
$value = ['ia_id' => $request->slug]; | ||
if ($request->has('filesJSON')) | ||
$value['files'] = $request->filesJSON; | ||
|
||
$item = Game::where('slug', $request->slug)->whereNull('ia_id')->first(); | ||
if (!$item) $item = Item::where('slug', $request->slug)->whereNull('ia_id')->first(); | ||
|
||
$item->update($value); | ||
|
||
$bot->sendMessage( | ||
text: $request->slug, | ||
chat_id: env("OWNER_TG_ID") | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.