diff --git a/docker/xdebug.dockerfile b/docker/xdebug.dockerfile new file mode 100644 index 0000000..90ec877 --- /dev/null +++ b/docker/xdebug.dockerfile @@ -0,0 +1,49 @@ +FROM ${DOCKERIZE_BASE_IMAGE} + +# +ENV APP_VERSION="${DOCKERIZE_VERSION}" + +# +ENV DOCKERIZE_VERSION="${DOCKERIZE_VERSION}" +ENV DOCKERIZE_BRANCH="${DOCKERIZE_BRANCH}" +ENV DOCKERIZE_COMMIT="${DOCKERIZE_COMMIT}" + +USER root + +RUN pecl install xdebug-2.9.8 \ + && docker-php-ext-enable xdebug \ + && echo "xdebug.remote_host = 10.254.254.254" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo "xdebug.remote_enable = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini + +# Copy all files +COPY --chown=www-data:www-data . /app + +# Pick the right .env file for the container +COPY --chown=www-data:www-data ${DOCKERIZE_ENV} /app/.env + + +RUN true \ +# +# Enable Locale +# + && sed "s/^#[ \t]*\(${DOCKERIZE_LOCALE}\)/\\1/" -i /etc/locale.gen \ +# +# Install/generate locale +# + && locale-gen \ +# +# Run composer +# + && composer --no-dev install \ +# +# Clear cache +# + && php artisan view:clear \ +# +# Create startup script +# + && printf "#!/bin/sh\nphp /app/artisan container:startup\n" > /container-startup.sh \ + && chmod a+x /container-startup.sh + +# Switch back to container user +USER ${DOCKERIZE_CONTAINER_USER} diff --git a/src/Console/Commands/DockerBuild.php b/src/Console/Commands/DockerBuild.php index bf96374..7c3a4d9 100644 --- a/src/Console/Commands/DockerBuild.php +++ b/src/Console/Commands/DockerBuild.php @@ -12,7 +12,7 @@ class DockerBuild extends Command * * @var string */ - protected $signature = 'docker:build {--p|print : Only print the Dockerfile} {--s|save : Only save the Dockerfile} {--P|push : Push the image}'; + protected $signature = 'docker:build {--p|print : Only print the Dockerfile} {--s|save : Only save the Dockerfile} {--P|push : Push the image} {--X|xdebug : Add Xdebug}'; /** * The console command description. @@ -67,7 +67,7 @@ public function build($silent = false) } // - $dockerfile = file_get_contents(base_path("vendor/janole/laravel-dockerize/docker/Dockerfile")); + $dockerfile = $this->getDockerfileContents($this->option('xdebug')); // $dockerfile = str_replace('${DOCKERIZE_BASE_IMAGE}', env("DOCKERIZE_BASE_IMAGE", "janole/laravel-nginx-postgres:unoconv"), $dockerfile); @@ -113,7 +113,7 @@ public function build($silent = false) $dockerfile = "# Dynamic Dockerfile\n# !!! DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN !!!\n\n$dockerfile"; @mkdir(base_path($buildpath)); file_put_contents(base_path("$buildpath/Dockerfile"), $dockerfile); - + // if ($this->option("save")) { @@ -244,4 +244,19 @@ private static function gitCountRefs() return @exec($cmd); } + + /** + * @param false $isXdebug + * @return false|string + */ + private static function getDockerfileContents($isXdebug = false) + { + $dockerfile = "Dockerfile"; + + if ($isXdebug) { + $dockerfile = "xdebug.dockerfile"; + } + + return file_get_contents(base_path(sprintf("vendor/janole/laravel-dockerize/docker/%s", $dockerfile))); + } }