LoginSignup
2
1

More than 3 years have passed since last update.

[Laravel] CircleCIにphp-gdをインストールする

Posted at

概要

CircleCIでテストを自動化している際に画像関連のテストで以下のエラーで引っかかってしまいました。

Error: Call to undefined function imagecreatetruecolor()

/home/circleci/ci-demo/backend/vendor/laravel/framework/src/Illuminate/Http/Testing/FileFactory.php:75
/home/circleci/ci-demo/backend/vendor/laravel/framework/src/Illuminate/Support/helpers.php:263
/home/circleci/ci-demo/backend/vendor/laravel/framework/src/Illuminate/Http/Testing/FileFactory.php:87
/home/circleci/ci-demo/backend/vendor/laravel/framework/src/Illuminate/Http/Testing/FileFactory.php:58

画像処理系のライブラリであるphp-gdがCircleCIイメージにインストールされていないために起こったエラーみたいです。

忘れないようにメモします。

環境

CircleCI 2.1
Laravel 8.12
PHP 7.3

実装

circleci/config.yml
version: 2.1
jobs:
  build:
    docker:
      - image: circleci/php:7.3.0-node-browsers
      - image: circleci/mysql:8.0.0
        command: mysqld --default-authentication-plugin=mysql_native_password
    environment:
      - DB_CONNECTION: circle_testing
      - APP_ENV: testing
      - MYSQL_ALLOW_EMPTY_PASSWORD: true
      - MYSQL_ROOT_HOST: '%'
      - MYSQL_DATABASE: circle_test
    working_directory: ~/ci-demo
    steps:
      - checkout
      - run: 
          name: Update apt-get
          command: sudo apt-get update
   //ここで追加
      - run:   
          name: Install php-gd
          command: |
            sudo apt-get -y install libpng-dev  
            sudo docker-php-ext-install  gd 
      - run:
          name: Docker php extensions install
          command: sudo docker-php-ext-install pdo_mysql
      - run:
          name: Wait for DB
          command: dockerize -wait tcp://127.0.0.1:3306 -timeout 3m 
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "backend/composer.json" }}
            - v1-dependencies-
      - run:
          working_directory: backend
          name: Install PHP libraries
          command: composer install -n --prefer-dist
      - save_cache:
          paths:
            - ./vendor
          key: v1-dependencies-{{ checksum "backend/composer.json" }}
      - run:
          working_directory: backend
          command: composer install
      - run:
          working_directory: backend
          command: php artisan migrate
      - run:
          working_directory: backend
          name: Run PHPUnit
          command: ./vendor/bin/phpunit

circleci/config.yml
      - run:
          name: Install php-gd
          command: |
            sudo apt-get -y install libpng-dev
            sudo docker-php-ext-install  gd
2
1
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
2
1