Skip to content

Commit

Permalink
Merge pull request #27 from HarkuLi/main
Browse files Browse the repository at this point in the history
Let Xdebug work without specific settings for different OSes + some slight improvement
  • Loading branch information
sherifabdlnaby authored May 26, 2022
2 parents 65a34cd + 9597571 commit 86f1354
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ RUN apk --no-cache add git openssh bash; \
# Enable Xdebug
docker-php-ext-enable xdebug

# For Xdebuger to work, it needs the docker host ID
# For Xdebuger to work, it needs the docker host IP
# - in Mac AND Windows, `host.docker.internal` resolve to Docker host IP
# - in Linux, `172.17.0.1` is the host IP
# By default, `host.docker.internal` is set as extra host in docker-compose.yml, so it also works in Linux without any
# additional setting. This env is reserved for people who want to customize their own compose configuration.
ENV XDEBUG_CLIENT_HOST="host.docker.internal"

# ---------------------------------------------------- Scripts ---------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ COMMAND ?= /bin/sh

# --------------------------

.PHONY: build deploy start stop logs restart shell up rm help
.PHONY: deploy up build-up build down start stop logs images ps command \
command-root shell-root shell restart rm help

deploy: ## Start using Prod Image in Prod Mode
${COMPOSE_PREFIX_CMD} docker-compose -f docker-compose.prod.yml up --build -d
Expand Down Expand Up @@ -46,10 +47,10 @@ command-root: ## Execute command as root ( make command-root COMMAND=<command>
@${COMPOSE_PREFIX_CMD} docker-compose run --rm -u root app ${COMMAND}

shell-root: ## Enter container shell as root
@${COMPOSE_PREFIX_CMD} docker-compose exec -u root app /bin/bash
@${COMPOSE_PREFIX_CMD} docker-compose exec -u root app /bin/sh

shell: ## Enter container shell
@${COMPOSE_PREFIX_CMD} docker-compose exec app /bin/bash
@${COMPOSE_PREFIX_CMD} docker-compose exec app /bin/sh

restart: ## Restart container
@${COMPOSE_PREFIX_CMD} docker-compose restart
Expand Down
35 changes: 15 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

## How to use with my project ?

- Copy this repository `Dockerfile`, `docker` Directory, `Makefile`, and `.dockerignore` to your application root directory and configure it to your needs.
- Copy this repository `Dockerfile`, `docker` Directory, `Makefile`, `docker-compose.yml`, `docker-compose.prod.yml` and `.dockerignore` to your application root directory and configure it to your needs.

## How to configure image to run my project ?

Expand All @@ -79,7 +79,7 @@ Your application will be split into two components.

# Requirements

- [Docker 20.05 or higher](https://docs.docker.com/install/)
- [Docker 20.10.0 or higher](https://docs.docker.com/install/)
- [Docker-Compose 1.27 or higher](https://docs.docker.com/compose/install/) (optional)
- PHP >= 7 Application

Expand All @@ -88,7 +88,7 @@ Your application will be split into two components.
#### 1. Add Template to your repo.

1. Download This Repository
2. Copy `Dockerfile`, `docker` Directory, `Makefile`, and `.dockerignore` Into your Application Repository.
2. Copy `Dockerfile`, `docker` Directory, `Makefile`, `docker-compose.yml`, `docker-compose.prod.yml` and `.dockerignore` Into your Application Repository.

OR

Expand All @@ -114,18 +114,18 @@ OR
However, in an environment where CI/CD pipelines will build the image, they will need to supply some build-time arguments for the image. (tho defaults exist.)

#### Build Time Arguments
| **ARG** | **Description**
| **Default** |
--------------------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
| `PHP_VERSION` | PHP Version used in the Image | `7.4` | | `PHP_ALPINE_VERSION` | Alpine
Version for the PHP Image | `3.15` | | `NGINX_VERSION` | Nginx Version | `1.21` | | `COMPOSER_VERSION` |
Composer Version used in Image | `2.0` | | `COMPOSER_AUTH` | A Json Object with Bitbucket or Github token to
clone private Repos with composer.</br>[Reference](https://getcomposer.org/doc/03-cli.md#composer-auth) | `{}`
| | `RUNTIME_DEPS` | List of all OS Packages needed for PHP Runtime | `zip` | | `XDEBUG_VERSION` | Xdebug
Version to use in Development Image | `3.0.3` |

#### Image Targets

| **ARG** | **Description** | **Default** |
|----------------------|-----------------|-------------|
| `PHP_VERSION` | PHP Version used in the Image | `7.4` |
| `PHP_ALPINE_VERSION` | Alpine Version for the PHP Image | `3.15` |
| `NGINX_VERSION` | Nginx Version | `1.21` |
| `COMPOSER_VERSION` | Composer Version used in Image | `2.0` |
| `COMPOSER_AUTH` | A Json Object with Bitbucket or Github token to clone private Repos with composer.</br>[Reference](https://getcomposer.org/doc/03-cli.md#composer-auth) | `{}` |
| `XDEBUG_VERSION` | Xdebug Version to use in Development Image | `3.1.3` |

#### Image Targets

| **Target** | Env | Desc | Size | Based On |
|------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|-------------------------------|
| app | Production | The PHP Application with immutable code/dependencies. By default starts `PHP-FPM` process listening on `9000`. Command can be extended to run any PHP Consumer/Job, entrypoint will still start the pre-run setup and then run the supplied command. | ~135mb | PHP Official Image (Alpine) |
Expand Down Expand Up @@ -198,11 +198,6 @@ In `docker/` directory there is `post-build-*` and `pre-run-*` scripts that are
fail when it cannot connect to
DB. [Make sure you configure doctrine to avoid this extra DB Check connection.](https://symfony.com/doc/current/reference/configuration/doctrine.html#:~:text=The-,server_version,-option%20was%20added)
3. Xdebug not working
- Xdebug is configured to work with Linux, to make it work for Mac/Windows, please change `XDEBUG_CLIENT_HOST` env
variable to `host.docker.internal` in `docker-compose.yml` file.
# License
[MIT License](https://raw.githubusercontent.com/sherifabdlnaby/kubephp/blob/master/LICENSE)
Expand Down
7 changes: 2 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ services:
COMPOSER_AUTH: "{}"
APP_BASE_DIR: ${APP_BASE_DIR-.}
restart: unless-stopped
environment:
# For Xdebuger to work, it needs the docker host ID
# - in Mac AND Windows, `host.docker.internal` resolve to Docker host IP
# - in Linux, `172.17.0.1` is the host IP
XDEBUG_CLIENT_HOST: ${XDEBUG_CLIENT_HOST-host.docker.internal}
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- ${APP_BASE_DIR-.}:/app

Expand Down
3 changes: 1 addition & 2 deletions docker/fpm/fpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ pm = dynamic
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 2
pm.process_idle_timeout = 10s
pm.max_children = 50

; do not clear environment variables sent to the PHP Script, pass OS env vars to PHP. (Important for K8S)
clear_env = no

; Disable access logs in fpm's stdout/err as it will be in nginx acces logs.
; Disable access logs in fpm's stdout/err as it will be in nginx access logs.
;access.log = /dev/stderr

; Run as www-data
Expand Down

0 comments on commit 86f1354

Please sign in to comment.