Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --xdebug option and xdebug.dockerfile #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docker/xdebug.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM ${DOCKERIZE_BASE_IMAGE}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich würde empfehlen Multi-Stage Builds zu verwenden, damit wir kein duplizierten Code haben.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, checke ich


#
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 \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woher kommt die IP-Adresse?

Du kannst die DNS host.docker.internal angeben, über die Container immer den Host erreichen (https://docs.docker.com/docker-for-windows/networking/).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

&& 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}
21 changes: 18 additions & 3 deletions src/Console/Commands/DockerBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"))
{
Expand Down Expand Up @@ -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)));
}
}