TS-351(QNAP)でGitLab-runnerを使ってLaravelを運用する方法の話
はいっ!今回はTS-351(QNAP)のNASの上にLaravel(php)で提供するWebサービスを提供する方法をまとめます!
前回、runnerの導入を書きましたね。TS-351(QNAP)でGitLab-runnerを爆速で作る方法の話
GitLab@TS-351 -> GitLab-runner@TS-351での疎通をしました
今回は、GitLabに更新をかけたときに、runnerに任意のスクリプトを走らせます。更新をかけるっつうのはGitにソースを上げるという事です
ま、難しいことはありませんが、前回指定しましたshellにて実行されるというわけです。docker-shellとかsshとかそんなのは…頑張ってください!
まずはスクリプトを書いておきます…
rsync -ar --delete ./ /opt/runner/ cd /opt/runner/ if [ -e ~/vendor/ ]; then rsync -arq ~/vendor/ /opt/runner/vendor/ else echo "cash vendor dir NOT found." fi if [ ! -d ./storage ]; then mkdir ./storage ; fi if [ ! -d ./vendor ]; then mkdir ./vendor ; fi if [ ! -d ./node_modules ]; then mkdir ./node_modules ; fi chmod -R 777 ./storage chmod -R 777 ./vendor chmod -R 777 ./node_modules service apache2 restart cp -f runner-config/laravel/.env .env composer update php artisan key:generate rsync -arq --delete /opt/runner/vendor/ ~/vendor/ ## check access... curl http://localhost | head
やっていることは、scriptが走っているディレクトリ(たぶん、/home/gitlab-runner/build/…この辺りはたぶんハッシュ… /プロジェクト名/ 辺り)がカレントで動いています。
公開環境(/opt/runner)と同期させます。deleteまで付けて完全一致させます
速度を考えると、composer キャッシュを戻します(/home/gitlab-runner/vendor)
laravelの場合、storageとかの作業ディレクトリなどがこけやすいのであらかじめ作って、パーミッションを切ります
んで、laravel系のおまじない (.env / composer / artisan)をして
終わったら、vendorをキャッシュさせて。
80ポートでハロー
ざざざーーーっと実行した結果はコチラ
Running with gitlab-runner 13.5.0 (ece86343) on laravel 8Xi4Wcyt Preparing the "shell" executor 00:00 Using Shell executor... Preparing environment 00:00 Running on 534833346f6a... Getting source from Git repository 00:00 Fetching changes with git depth set to 50... Reinitialized existing Git repository in /home/gitlab-runner/builds/8Xi4Wcyt/0/mmpp/learning_gitlab_ci/.git/ Checking out 17714427 as master... Removing coverage/Console/ Removing coverage/Exceptions/ Removing coverage/Http/ Removing coverage/Models/ Removing coverage/Providers/ Removing coverage/_css/ Removing coverage/_icons/ Removing coverage/_js/ Removing coverage/dashboard.html Removing coverage/index.html Skipping Git submodules setup Downloading artifacts 00:00 Downloading artifacts for phpunit (96)... Runtime platform arch=amd64 os=linux pid=24412 revision=ece86343 version=13.5.0 Downloading artifacts from coordinator... ok id=96 responseStatus=200 OK token=ywGY2Kt- Executing "step_script" stage of the job script 00:23 $ /bin/bash runner-config/laravel/run_script.sh --- project files sync... --- ___ project files synced ___ --- caching found... --- ~/vendor/ dir found. ___ caching founded ___ AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.3.3. Set the 'ServerName' directive globally to suppress this message Syntax OK * Restarting Apache httpd web server apache2 ...fail! --- composer update... --- Loading composer repositories with package information Updating dependencies Nothing to modify in lock file Installing dependencies from lock file (including require-dev) Nothing to install, update or remove Generating optimized autoload files > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover --ansi Discovered Package: facade/ignition Discovered Package: fideloper/proxy Discovered Package: fruitcake/laravel-cors Discovered Package: laravel/tinker Discovered Package: nesbot/carbon Discovered Package: nunomaduro/collision Package manifest generated successfully. 72 packages you are using are looking for funding. Use the `composer fund` command to find out more! ___ composer update ___ --- key:generate... --- Application key set successfully. ___ key:generate ___ --- caching store... --- ___ caching stored ___ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Laravel</title> <!-- Fonts --> <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet"> 100 17473 0 17473 0 0 449k 0 --:--:-- --:--:-- --:--:-- 449k (23) Failed writing body Cleaning up file based variables 00:00 Job succeeded
ねっ、シンプルでしょ
次回も、近々かなw
これ作るのにLaravelの開発環境 OS : ubuntu 20LTSで作ったのでwww
はぁ〜 ソースまで遠いなw