Share
Embed
Transcript
37 slides
-
⾃⼰紹介 金澤 裕毅 - 出身:宮城県仙台市 - 在住:北海道札幌市 - 2013年11月にランサーズSREとしてJOIN -
2017年からPHPのバージョンアップ担当 - 趣味:将棋(ウォーズ二段)、バドミントン - Github:yKanazawa - Twitter: @yakitori009 - Language: C++, Java, PHP, Go 2022.08.27 PHPカンファレンス沖縄 -
ランサーズとは? 日本における「フリーランスプラットフォーム」のパイオニア クラウドソーシングの基本的なモデル グローバルでのクラウドソーシングプレーヤー 経営資源の オープン化 企業 (クライアント) 働き方の 柔軟化・多様化
個人 (ランサー) 2015 2009 2008 作業・納品 エスクロー決済 Upwork (アップワーク) 旧Elance+ODesk Freelancer.com (フリーランサー・ドットコム) Elance 1998 ODesk 2004 2022.08.27 PHPカンファレンス沖縄 -
バージョンアップの歴史 2022.08.27 PHPカンファレンス沖縄 1.3 → 2.8 2.8 → 2.10 2.10→
4.x .. more 5.3 → 5.6 5.6 → 7.3 2017/3 バージョンアップ開始 2019/2/5完了 約2年 PHP5.6に必須 CakePHP2.10に必須 PHP7.3に必須 2019/3/27完了 約2カ⽉ 2019/4/17完了 約1⽇ 2019/5/28完了 約1.5カ⽉ 現在継続中 1.3 5.3 + -
ランサーズのサーバー構成(2019年頃) PHP7.3 CakePHP2.10 lancers PHP7.3 CakePHP2.10 lancers PHP7.3 CakePHP2.10 lancers
EC2 instance CloudFront Route 53 ALB Auto Scaling App Aurora Reader Aurora Reader Aurora Writer ランサーズ Batch MySQL5.7 ALB Admin 管理画⾯ 全て同じ リポジトリ S3 CloudFront API Gateway Lambda サムネイル表⽰ ElastiCache Redis 2022.08.27 PHPカンファレンス沖縄 -
リポジトリを分離してCakePHP4で再構築 PHP7.3 CakePHP4 Lancers_admin PHP7.3 CakePHP2.10 lancers PHP7.3 CakePHP4 Lancers_batch
EC2 instance CloudFront Route 53 ALB Auto Scaling App Aurora Reader Aurora Reader Aurora Writer ランサーズ Batch MySQL5.7 ALB Admin 管理画⾯ S3 CloudFront API Gateway Lambda サムネイル表⽰ ElastiCache Redis 2022.08.27 PHPカンファレンス沖縄 -
本番環境をコンテナ化(2022年現在) PHP7.3 CakePHP4.3 PHP7.3 CakePHP2.10 PHP7.3 CakePHP4.3 EC2 instance CloudFront
Route 53 ALB Auto Scaling App Aurora Reader Aurora Reader Aurora Writer ランサーズ Batch (Scheduling Task) ALB Admin 管理画⾯ Fargate CloudWatch Logs AWS Logsで転送 Kinesis Firehose S3 CloudFront API Gateway Lambda サムネイル表⽰ ElastiCache Redis デプロイ 2022.08.27 PHPカンファレンス沖縄 -
本番コンテナ化により得られるメリット Docker化前 Docker化後 ソースコードのリリース 独⾃のデプロイシステムで⼿動 リリース マージ後にCIで⾃動リリース 本番サーバーの設定変更 ansibleで差分更新 Dockerfileで常に新規構築
デプロイ時間 30秒以内 5分程度 オートスケーリング時の処理 EC2のAMI起動後にデプロイシ ステムから最新のソースを取得 常に最新のソースで起動 Immutable Infrastructure化で バージョンアップしやすい体制に 2022.08.27 PHPカンファレンス沖縄 -
Batchと管理画⾯からPHP8.1対応 PHP7.3 CakePHP4.3 PHP7.3 CakePHP2.10 PHP7.3 CakePHP4.3 EC2 instance CloudFront
Route 53 ALB Auto Scaling App Aurora Reader Aurora Reader Aurora Writer ランサーズ Batch (Scheduling Task) ALB Admin 管理画⾯ Fargate CloudWatch Logs AWS Logsで転送 Kinesis Firehose S3 CloudFront API Gateway Lambda サムネイル表⽰ ElastiCache Redis デプロイ 2022.08.27 PHPカンファレンス沖縄 -
remiリポジトリがaarch64⾮対応 ・x86_64 ・remi7:http://rpms.remirepo.net/enterprise/7/remi/x86_64/repoview/ ・PHP8.1のパッケージあり ・remi8:http://rpms.remirepo.net/enterprise/8/remi/x86_64/repoview/ ・PHP8.1のパッケージあり ・aarch64 ・remi7:http://rpms.remirepo.net/enterprise/7/remi/aarch64/repoview/ ・PHP8.1のパッケージなし ・remi8:http://rpms.remirepo.net/enterprise/8/remi/aarch64/repoview/
・このURL自体存在しない 2022.08.27 PHPカンファレンス沖縄 →remiが今後aarch64に対応する見込みは薄そう ・https://forum.remirepo.net/viewtopic.php?id=4016 -
対応⽅法 ・Docker Buildをやめる ・x86_64で構築済のコンテナをECRにアップロード ・それを取得して使ってもらう ・※Docker for Macのエミュレーション機能で対応 ・本番環境でAWSのArm系プロセッサは使えない ・Amazon
Linux2をやめる ・他のLinux系コンテナで構築する 2022.08.27 PHPカンファレンス沖縄 -
PHPCompatibilityによる静的解析 root@batch:/var/www/lancers_batch# bin/phpcs -p src/ --standard=PHPCompatibility --untime-set testVersion 8.1 ................................W...........................
60 / 596 (10%) … ............................................................ 540 / 596 (91%) ........................................................ 596 / 596 (100%) FILE: /var/www/lancers_batch/src/Command/InsertAggregatedImpressionLogsCommand.php ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- 118 | WARNING | Method name "InsertAggregatedImpressionLogsCommand::__insertAggregatedImpressionLogs" is discouraged; PHP has reserved all method names with a double underscore prefix | | for future use. 186 | WARNING | Method name "InsertAggregatedImpressionLogsCommand::__dateValidations" is discouraged; PHP has reserved all method names with a double underscore prefix for future use. 208 | WARNING | Method name "InsertAggregatedImpressionLogsCommand::__arrayCsvTextToArray" is discouraged; PHP has reserved all method names with a double underscore prefix for future | | use. 322 | WARNING | Method name "InsertAggregatedImpressionLogsCommand::__isPositeveInteger" is discouraged; PHP has reserved all method names with a double underscore prefix for future use. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- … ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- FOUND 1 ERROR AFFECTING 1 LINE ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- 354 | ERROR | Since PHP 7.0, functions inspecting arguments, like debug_backtrace(), no longer report the original value as passed to a parameter, but will instead provide the current | | value. The parameter "$className" was changed on line 351. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- Time: 16.81 secs; Memory: 18MB 2022.08.27 PHPカンファレンス沖縄 -
Rectorで最新の記法に⾃動修正 composer require rector/rector --dev vendor/bin/rector init <?php declare(strict_types=1); use
Rector¥CodeQuality¥Rector¥Class_¥InlineConstructorDefaultToPropertyRector; use Rector¥Config¥RectorConfig; use Rector¥Set¥ValueObject¥LevelSetList; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/templates’, __DIR__ . '/tests', ]); $rectorConfig->sets([ LevelSetList::UP_TO_PHP_81, ]); $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); }; 2022.08.27 PHPカンファレンス沖縄 bin/rector process src/ templates/ ・セットアップ ・rector.phpを生成 ・rectorコマンドの実行 ・rector.phpのカスタマイズ PHPのバージョンを指定 -
CakePHPとPHPのサポートバージョン PHP Min ver PHP Max ver PHPUnit Min ver
PHPUnit Max ver CakePHP 2.10 5.3 7.4 3.7 5.7.* CakePHP4.3 7.2 8.* 8.5.0 9.* CakePHP4.4 7.4 8.* 8.5.0 9.* 2022.08.27 PHPカンファレンス沖縄 -
ランサーズ本体のPHP8.1対応 PHP7.3 CakePHP2.10 + CakePHP4.3 PHP7.3 → 8.1 CakePHP4.3 EC2
instance CloudFront Route 53 ALB Auto Scaling App Aurora Reader Aurora Reader Aurora Writer ランサーズ Batch (Scheduling Task) ALB Admin 管理画⾯ Fargate CloudWatch Logs AWS Logsで転送 Kinesis Firehose S3 CloudFront API Gateway Lambda サムネイル表⽰ ElastiCache Redis デプロイ 2022.08.27 PHPカンファレンス沖縄 PHP7.3 → 8.1 CakePHP4.3 -
CakePHP2とCakePHP4の混在環境 + App + Config + Controller + Lib +
Model + Test + Vendor + cakephp + cakephp + debug_kit + phpunit + View + config + src + tests + vendor + cakephp + cakephp + debug_kit + phpunit + webroot CakePHP2 CakePHP4 CakePHP2.10 git管理 CakePHP4.3 Composer管理 PHPUnit5.7 git管理 PHPUnit9 Composer管理 2022.08.27 PHPカンファレンス沖縄 -
CakePHP2とCakePHP4の混在環境 + App + Config + switch.yml + Controller +
Lib + Model + Test + Vendor + View + config + app.php + bootstrap.php + src + Controller + Lib + Model + tests + vendor + webroot --- cakephp4: … - /mypage - /mypage/ - /mypage/index - /mypage/index/* - /mypage/charge - /mypage/charge/* … - /user/login - /user/login/* ここに列挙したパスのみ CakePHP4で処理する CakePHP2 CakePHP4 2022.08.27 PHPカンファレンス沖縄 -
PHP8対応版CakePHP2に置き換え + App + Config + Controller + Lib +
Model + Test + Vendor + cakephp + cakephp + debug_kit + phpunit + View + config + src + tests + vendor + cakephp + cakephp + debug_kit + phpunit + webroot CakePHP2 CakePHP4 PHP8対応版 CakePHP2 CakePHP4.3 Composer管理 PHPUnit5.7 git管理 PHPUnit9 Composer管理 2022.08.27 PHPカンファレンス沖縄 -
課題:PHPUnit5.7はPHP8.1に対応するのか? + App + Config + Controller + Lib +
Model + Test + Vendor + cakephp + cakephp + debug_kit + phpunit + View + config + src + tests + vendor + cakephp + cakephp + debug_kit + phpunit + webroot CakePHP2 CakePHP4 PHP8対応版 CakePHP2 CakePHP4.3 Composer管理 PHPUnit5.7︖ PHPUnit9 Composer管理 2022.08.27 PHPカンファレンス沖縄 -
バージョンアップ協⼒者募集中! 進捗 管理画⾯ CakePHP4 約75% バッチ CakePHP4 約50% 本体 CakePHP2
+ CakePHP4 これから 2022.08.27 PHPカンファレンス沖縄 ・ランサーズの時間報酬で直接依頼します ・PHPCon参加者による副業実績あり 移⾏中