Compare commits
2 commits
ff75dfaa82
...
2246c597f1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2246c597f1 | ||
![]() |
06ba3f7ae0 |
7 changed files with 130 additions and 21 deletions
96
README.md
96
README.md
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
An environment management application for PHP developers.
|
An environment management application for PHP developers.
|
||||||
|
|
||||||
## Dev Notes
|
# Dev Notes
|
||||||
|
|
||||||
**Argument priority:**
|
**Argument priority:**
|
||||||
|
|
||||||
|
@ -10,25 +10,91 @@ An environment management application for PHP developers.
|
||||||
- Any set within `{projectDirectory}/spinner.yaml`
|
- Any set within `{projectDirectory}/spinner.yaml`
|
||||||
- Fall back to `/config/spinner.yaml`
|
- Fall back to `/config/spinner.yaml`
|
||||||
|
|
||||||
## Commands
|
# Commands
|
||||||
|
|
||||||
### `spin:up`
|
## Command: `spin:up`
|
||||||
|
|
||||||
#### Arguments
|
Creates a new PHP development environment and mounts your project files.
|
||||||
|
|
||||||
- `name` - **Required**: The name for your Docker containers.
|
### Arguments
|
||||||
- `path` - **Required**: The **absolute path** to your project root directory.
|
|
||||||
- `php` - **Optional**: If passed, sets the PHP version used by your container. Can be overridden
|
|
||||||
by creating a `spinner.yaml` file in your project root directory and defining the key `options.environment.php.version`
|
|
||||||
|
|
||||||
#### Options
|
> #### Argument: name
|
||||||
|
>
|
||||||
|
> **Required?** ✅
|
||||||
|
>
|
||||||
|
> The name of your Docker containers. Your containers will spin up with the name {name}-{service}-1 i.e.
|
||||||
|
>
|
||||||
|
> `spinner spin:up name=test path=/path`
|
||||||
|
>
|
||||||
|
> Results in containers named `test-php-1` and `test-nginx-1`
|
||||||
|
|
||||||
- `disable-node` - **Optional**: Disables Node. Can also define the key `options.environment.node.enabled` in your
|
> #### Argument: path
|
||||||
`spinner.yaml` file.
|
>
|
||||||
- `disable-server` - **Optional:** Does not install a web server.
|
> **Required?** ✅
|
||||||
|
>
|
||||||
|
> The **absolute path** on your system to the project you want to create containers for.
|
||||||
|
|
||||||
## Example Usage
|
### Options
|
||||||
|
|
||||||
`spinner spin:up name=test path=/abs/path/to/project`
|
> #### Option: --php
|
||||||
|
>
|
||||||
|
> **Required?** ❌
|
||||||
|
>
|
||||||
|
> Defines the PHP version that your container will use. You can omit this flag and set the PHP version inside your
|
||||||
|
> projects `spinner.yaml` file. Otherwise, will use the default value found in `config/spinner.yaml`
|
||||||
|
|
||||||
`spinner spin:up test /abs/path/to/project 8.4 --disable-server --disable-node`
|
> #### Option: --node
|
||||||
|
>
|
||||||
|
> **Required?** ❌
|
||||||
|
>
|
||||||
|
> Set which version of Node to install in your container. Is ignored if the `--disable-node` flag is
|
||||||
|
> passed, or if Node is disabled in your projects `spinner.yaml` file. Equivalent to setting `options.environment.node.version = x`
|
||||||
|
> in your projects Spinner config.
|
||||||
|
|
||||||
|
> #### Option: --disable-node
|
||||||
|
>
|
||||||
|
> **Required?** ❌
|
||||||
|
>
|
||||||
|
> Disables Node for your environment, so it isn't included in your PHP container. Equivalent to setting `options.environment.node.enabled = false`
|
||||||
|
> in your Spinner config.
|
||||||
|
|
||||||
|
> #### Option: --disable-server
|
||||||
|
>
|
||||||
|
> **Required?** ❌
|
||||||
|
>
|
||||||
|
> Does not install a webserver (so no Nginx). Useful if you just need a PHP container to run
|
||||||
|
> unit tests or something.
|
||||||
|
|
||||||
|
> #### Option: --disable-xdebug
|
||||||
|
>
|
||||||
|
> **Required?** ❌
|
||||||
|
>
|
||||||
|
> Do not install XDebug in your environment.
|
||||||
|
|
||||||
|
## XDebug Setup
|
||||||
|
|
||||||
|
These instructions are for PHPStorm. I don't know about working with other IDE's, although they
|
||||||
|
should be fairly universal.
|
||||||
|
|
||||||
|
### Server Settings
|
||||||
|
|
||||||
|
- `File` -> `Settings` (`Preferences` on MacOS)
|
||||||
|
- `PHP` -> `Servers` -> `+`
|
||||||
|
- Give your "server" a name and use the values shown below.
|
||||||
|
|
||||||
|
| Setting | Value |
|
||||||
|
|-------------------------|----------------------------------------------------------------------------------------------------------------|
|
||||||
|
| Host | 127.0.0.1 |
|
||||||
|
| Port | **Local** port **PHP** container is running on. i.e. if your docker container shows 52033:9003, use **52033**. |
|
||||||
|
| Debugger | Xdebug |
|
||||||
|
| Use path mappings? | ✅ |
|
||||||
|
| File/Directory | Select **your project root** |
|
||||||
|
| Absolute path on server | /var/www/html |
|
||||||
|
|
||||||
|
### Remote Debugger
|
||||||
|
|
||||||
|
- `Run` -> `Edit Configurations`
|
||||||
|
- `+` -> `PHP Remote Debug`
|
||||||
|
- Give it a name
|
||||||
|
- Use the server you created before
|
||||||
|
- Use **SPINNER** as IDE key
|
|
@ -1,6 +1,10 @@
|
||||||
RUN pecl install xdebug redis \
|
#RUN pecl install xdebug redis \
|
||||||
&& docker-php-ext-enable redis
|
# && docker-php-ext-enable redis
|
||||||
|
#
|
||||||
|
#COPY ./xdebug.ini.tmp "${PHP_INI_DIR}/conf.d/xdebug.ini"
|
||||||
|
#RUN docker-php-ext-install opcache > /dev/null
|
||||||
|
#COPY ./opcache.ini "${PHP_INI_DIR}/conf.d"
|
||||||
|
|
||||||
COPY ./xdebug.ini.tmp "${PHP_INI_DIR}/conf.d/xdebug.ini"
|
RUN pecl install xdebug
|
||||||
RUN docker-php-ext-install opcache > /dev/null
|
|
||||||
COPY ./opcache.ini "${PHP_INI_DIR}/conf.d"
|
COPY ./xdebug.ini "${PHP_INI_DIR}/conf.d/xdebug.ini"
|
8
config/php-fpm/xdebug.ini
Normal file
8
config/php-fpm/xdebug.ini
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[xdebug]
|
||||||
|
zend_extension=xdebug.so
|
||||||
|
xdebug.mode=debug,develop,coverage
|
||||||
|
xdebug.start_with_request=yes
|
||||||
|
xdebug.client_host=host.docker.internal
|
||||||
|
xdebug.client_port=9003
|
||||||
|
xdebug.idekey=SPINNER
|
||||||
|
xdebug.log=/tmp/xdebug.log
|
|
@ -2,6 +2,7 @@ options:
|
||||||
environment:
|
environment:
|
||||||
php:
|
php:
|
||||||
version: 8.4
|
version: 8.4
|
||||||
|
xdebug: true
|
||||||
node:
|
node:
|
||||||
enabled: true
|
enabled: true
|
||||||
version: 23
|
version: 23
|
||||||
|
|
|
@ -71,6 +71,18 @@ class Config
|
||||||
return $this->getEnvironmentOption('server', 'enabled');
|
return $this->getEnvironmentOption('server', 'enabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function isXDebugEnabled(InputInterface $input): bool
|
||||||
|
{
|
||||||
|
if ($input->getOption('disable-xdebug')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getEnvironmentOption('php', 'xdebug');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
|
@ -126,6 +138,8 @@ class Config
|
||||||
DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE),
|
DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE),
|
||||||
DataPathInterface::CONFIG_NGINX_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_NGINX_DOCKERFILE),
|
DataPathInterface::CONFIG_NGINX_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_NGINX_DOCKERFILE),
|
||||||
'nodeDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/Node.Dockerfile'),
|
'nodeDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/Node.Dockerfile'),
|
||||||
|
'xdebugIniTemplate' => new SpinnerFilePath('config/php-fpm/xdebug.ini'),
|
||||||
|
'xdebugDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/XDebug.Dockerfile'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,10 +34,20 @@ class PHPDockerFileBuilder extends AbstractFileBuilder
|
||||||
$this->content = str_replace('${PHP_VERSION}', (string) $this->config->getPhpVersion($input), $this->content);
|
$this->content = str_replace('${PHP_VERSION}', (string) $this->config->getPhpVersion($input), $this->content);
|
||||||
|
|
||||||
if ($this->config->isNodeEnabled($input)) {
|
if ($this->config->isNodeEnabled($input)) {
|
||||||
$this->content .= "\r\n\r\n" . file_get_contents($this->config->getFilePaths()->get('nodeDockerfileTemplate')->getAbsolutePath());
|
$this->addNewLine();
|
||||||
|
$this->content .= file_get_contents($this->config->getFilePaths()->get('nodeDockerfileTemplate')->getAbsolutePath());
|
||||||
$this->content = str_replace('${NODE_VERSION}', (string) $this->config->getNodeVersion($input), $this->content);
|
$this->content = str_replace('${NODE_VERSION}', (string) $this->config->getNodeVersion($input), $this->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->config->isXdebugEnabled($input)) {
|
||||||
|
$this->addNewLine();
|
||||||
|
$this->content .= file_get_contents($this->config->getFilePaths()->get('xdebugDockerfileTemplate')->getAbsolutePath());
|
||||||
|
file_put_contents(
|
||||||
|
(new SpinnerFilePath(sprintf('data/environments/%s/php-fpm/xdebug.ini', $input->getArgument('name'))))->getProvidedPath(),
|
||||||
|
file_get_contents($this->config->getFilePaths()->get('xdebugIniTemplate')->getAbsolutePath())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,12 @@ class SpinCommand extends AbstractSpinnerCommand
|
||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
'Set this flag to disable Node.js for your environment.'
|
'Set this flag to disable Node.js for your environment.'
|
||||||
)
|
)
|
||||||
|
->addOption(
|
||||||
|
'disable-xdebug',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
'Set this flag to disable XDebug for your environment.'
|
||||||
|
)
|
||||||
->addOption('node', null, InputOption::VALUE_OPTIONAL, 'The Node.js version to use (e.g. 20).');
|
->addOption('node', null, InputOption::VALUE_OPTIONAL, 'The Node.js version to use (e.g. 20).');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue