LoginSignup
3
0

More than 1 year has passed since last update.

Laravel9にバージョンアップしたらGoogle App Engineへデプロイするときにエラーが発生

Posted at

エラー内容

$ gcloud app deploy

...
  - Installing laravel/tinker (v2.7.2): Extracting archive
  - Installing league/flysystem-google-cloud-storage (3.0.15): Extracting archive
  - Installing spatie/laravel-google-cloud-storage (2.0.3): Extracting archive
Deprecation Notice: Return type of Symfony\Component\Finder\Iterator\FilenameFilterIterator::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///layers/google.php.composer-install/composer/bin/composer/vendor/symfony/finder/Iterator/FilenameFilterIterator.php:28
    Failed to extract symfony/polyfill-mbstring: (9) '/usr/bin/unzip' -qq '/workspace/vendor/composer/tmp-05b27721e86cb8c0edcc204595ee1d4d' -d '/workspace/vendor/composer/f6e0dc9c'

[/workspace/vendor/composer/tmp-05b27721e86cb8c0edcc204595ee1d4d]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of /workspace/vendor/composer/tmp-05b27721e86cb8c0edcc204595ee1d4d or
        /workspace/vendor/composer/tmp-05b27721e86cb8c0edcc204595ee1d4d.zip, and cannot find /workspace/vendor/composer/tmp-05b27721e86cb8c0edcc204595ee1d4d.ZIP, period.

    The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
    Unzip with unzip command failed, falling back to ZipArchive class
    Install of symfony/polyfill-mbstring failed

                                                                                           
  [UnexpectedValueException]                                                               
  '/workspace/vendor/composer/tmp-05b27721e86cb8c0edcc204595ee1d4d' is not a zip archive.  
                                                                                           

install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-scripts] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>]...
Full build logs: https://console.cloud.google.com/cloud-build/builds;region=asia-northeast1/935d2d8f-a143-489b-8218-9c718e899057?project=757493885841
Error: Process completed with exit code 1.

spatie/laravel-google-cloud-storage (2.0.3) アーカイブを解凍するときに Failed to extract symfony/polyfill-mbstring: (9) '/usr/bin/unzip' -qq symfony/polyfill-mbstringunzip して失敗している。

zipが壊れている...??

composer.json の中身

composer.json
{
    "require": {
        "php": "^8.1",
        "ext-json": "*",
        "ext-zip": "*",
        "fruitcake/laravel-cors": "^3.0",
        "google/cloud-logging": "^1.24",
        "guzzlehttp/guzzle": "^7.4",
        "laravel/framework": "^9.14",
        "laravel/tinker": "^2.7",
        "spatie/laravel-google-cloud-storage": "^2.0"
    },
    "require-dev": {
        "barryvdh/laravel-ide-helper": "^2.12",
        "beyondcode/laravel-dump-server": "^1.8",
        "spatie/laravel-ignition": "^1.2",
        "fakerphp/faker": "^1.19",
        "mockery/mockery": "^1.5",
        "nunomaduro/collision": "^6.2",
        "phpunit/phpunit": "^9.5",
        "roave/security-advisories": "dev-master"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
}

Laravel7系からLaravel9系へバージョンアップする過程で廃止されたパッケージを差し替えています。

  • superbalist/laravel-google-cloud-storage: "^2.2" から "spatie/laravel-google-cloud-storage": "^2.0"
  • "facade/ignition": "^2.0" から "spatie/laravel-ignition": "^1.2"

この2つのライブラリが symfony/polyfill-mbstring などの symfony/polyfill-* パッケージに依存してます。

zipを展開できないならzipでダウンロードさせなければいい

composer install するときに --prefer-source オプションを指定できれば良さそう。
ただ、 gcloud app deploy コマンドにオプションを渡せなさそう...

composer.json で設定するしかないかも?

composer.json
{
    "config": {
        "preferred-install": {
            "spatie/laravel-google-cloud-storage": "source",
            "spatie/laravel-ignition": "source",
            "symfony/polyfill-*": "source",
            "*": "dist"
        },
    },
}

参考サイトを見つけて指定できることを知りました。
これでエラーを回避できました。

追伸

問題解決した後にIssue上がってました...
エラーは断続的に発生する、頻繁に発生する...たまにうまくいく...まさにこの挙動でした。

原因はGitHubの問題で、修正のPRが上がってました。。

結局、Laravelにバージョンアップしたのは根本的な原因ではなかった...。
このタスクを1週間後にやってればエラー直ってたんじゃ...😭

1日無駄にしてしまった。。

参考

https://zenn.dev/kshiva1126/scraps/e0b4bf94182139
https://nextat.co.jp/staff/archives/232
https://hara-chan.com/it/programming/prefer-dist-prefer-source-difference/

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0