From 2ca6c4c60dde6c91a3eaf2c7526f413646d2d2e9 Mon Sep 17 00:00:00 2001 From: shibafu Date: Wed, 16 Jan 2019 00:42:05 +0900 Subject: [PATCH] =?UTF-8?q?Docker=E3=82=B3=E3=83=B3=E3=83=86=E3=83=8A?= =?UTF-8?q?=E5=86=85=E3=81=ABXdebug=E3=82=92=E5=B0=8E=E5=85=A5=20(#33)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * コンテナにxdebugをインストール * env fileをDockerに読ませるようにした * 環境変数 APP_DEBUG に応じてXdebugをロードしてApacheを起動するようにした * シェルスクリプトのWindows対策 (.gitattribute) --- .env.example | 12 ++++++------ .gitattributes | 1 + Dockerfile | 7 +++++++ dist/bin/tissue-entrypoint.sh | 8 ++++++++ dist/php.d/99-xdebug.ini | 5 +++++ docker-compose.yml | 9 ++------- 6 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 dist/bin/tissue-entrypoint.sh create mode 100644 dist/php.d/99-xdebug.ini diff --git a/.env.example b/.env.example index 84e517d..a41650b 100644 --- a/.env.example +++ b/.env.example @@ -5,12 +5,12 @@ APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=homestead -DB_USERNAME=homestead -DB_PASSWORD=secret +DB_CONNECTION=pgsql +DB_HOST=db +DB_PORT=5432 +DB_DATABASE=tissue +DB_USERNAME=tissue +DB_PASSWORD=tissue BROADCAST_DRIVER=log CACHE_DRIVER=file diff --git a/.gitattributes b/.gitattributes index 967315d..78179de 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,3 +3,4 @@ *.scss linguist-vendored *.js linguist-vendored CHANGELOG.md export-ignore +*.sh text eol=lf \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4960985..65d49a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,17 @@ ENV APACHE_DOCUMENT_ROOT /var/www/html/public RUN apt-get update \ && apt-get install -y git libpq-dev unzip \ && docker-php-ext-install pdo_pgsql \ + && pecl install xdebug \ && curl -sS https://getcomposer.org/installer | php \ && mv composer.phar /usr/local/bin/composer \ && sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf \ && sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf \ && a2enmod rewrite +COPY dist/bin /usr/local/bin/ +COPY dist/php.d /usr/local/etc/php/php.d/ + +ENTRYPOINT ["tissue-entrypoint.sh"] +CMD ["apache2-foreground"] + WORKDIR /var/www/html diff --git a/dist/bin/tissue-entrypoint.sh b/dist/bin/tissue-entrypoint.sh new file mode 100644 index 0000000..49280f5 --- /dev/null +++ b/dist/bin/tissue-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +if [[ "$APP_DEBUG" == "true" ]]; then + export PHP_INI_SCAN_DIR=":/usr/local/etc/php/php.d" +fi + +exec docker-php-entrypoint "$@" diff --git a/dist/php.d/99-xdebug.ini b/dist/php.d/99-xdebug.ini new file mode 100644 index 0000000..a6e8b8c --- /dev/null +++ b/dist/php.d/99-xdebug.ini @@ -0,0 +1,5 @@ +; Dockerでのデバッグ用設定 +zend_extension=xdebug.so +xdebug.remote_enable=true +xdebug.remote_autostart=true +xdebug.remote_host=host.docker.internal \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index f5fbae3..6055b8d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,13 +3,8 @@ version: "3" services: web: build: . - environment: - DB_CONNECTION: pgsql - DB_HOST: db - DB_PORT: 5432 - DB_DATABASE: tissue - DB_USERNAME: tissue - DB_PASSWORD: tissue + env_file: + - .env volumes: - .:/var/www/html networks: