PHPのDeployerをCircleCI上で実行して自動デプロイ

PHP

概要

CircleCIからDeployer
phpapp/README.md at master · matsubo/phpapp
deployer test. Contribute to matsubo/phpapp development by creating an account on GitHub.

Setup

% git clone [email protected]:matsubo/phpapp.git
% cd phpapp
% composer install

Command example

% time php vendor/bin/dep deploy test
✈︎ Deploying master on blog.teraren.com
✔ Executing task deploy:prepare
✔ Executing task deploy:lock
✔ Executing task deploy:release
➤ Executing task deploy:update_code
Cloning into '/home/matsu/Sites/teraren.com/phpapp/releases/2'...
Counting objects: 36, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (36/36), done.
Total 36 (delta 12), reused 36 (delta 12)
Connection to blog.teraren.com closed.
✔ Ok
✔ Executing task deploy:shared
✔ Executing task deploy:writable
✔ Executing task deploy:vendors
✔ Executing task deploy:clear_paths
✔ Executing task deploy:symlink
✔ Executing task deploy:unlock
✔ Executing task cleanup
Successfully deployed!
       15.56 real         0.65 user         0.60 sys

Setup history

% composer init
% composer require deployer/deployer --dev
% php vendor/bin/dep init
% vim deploy.php; vim hosts.yml

Nginx側の設定。普通な感じで。

server {
    listen 80;
    listen [::]:80;

    server_name phpapp.teraren.com;


    location / {
        root /home/matsu/Sites/teraren.com/phpapp/current/webroot;
        index index.php index.html index.htm;
        access_log /var/log/nginx/phpapp.teraren.com main;

        location ~ \.php {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
}

まとめ

  • DeployerとCircleCIの組み合わせはとても楽。
  • AutoScale用の設定が無いので、AWSのCodeDeployと連携した方が良さそうです。
    • CircleCI -> bastion -> Application server という構成のベストな設定は見つからなかった。自分でコマンドを色々書かないといけなさそうな気がする。それを考えるtおCodeDeployに任せた方が楽な気がする。

Comments

タイトルとURLをコピーしました