Skip to content

Project specific Configuration

swsrmes edited this page Sep 8, 2022 · 12 revisions

Custom Config in the Global configuration

Some configurations must be done directly in the .config/swdc/env file like used image, hosts etc.

FOLDER_NAME has to be in uppercase. Example for image: Folder name is: sw5, VHOST_SW5_IMAGE

  • VHOST_FOLDER_NAME_IMAGE
    • Allows changing the image that is used for this directory.
    • Files are mount to /var/www/html, the image should expose a web service at port 80
    • Possible default values can be found here
  • VHOST_FOLDER_NAME_HOSTS
    • This can be a list of hosts comma separated. The first host will be used for the Installation
  • VHOST_FOLDER_NAME_CERT_NAME
    • This can be used to define another SSL certificate for this vhost.
    • Example: shop. You will need following files ~/.config/swdc/ssl/shop.crt and ~/.config/swdc/ssl/shop.key

Enabling Blackfire

If you have enabled Blackfire in the Global Configuration, you have to enable it too for the actual project like:

VHOST_[FOLDER_NAME_UPPER_CASE]_IMAGE=ghcr.io/shyim/shopware-docker/6/nginx:php74-blackfire

in the .config/swdc/env file

Enabling XDebug

XDebug needs to be enabled per Virtual Host. To enable it, open the SWDC configuration file ($HOME/.config/swdc/env) and add the following line:

VHOST_[FOLDER_NAME_UPPER_CASE]_IMAGE=ghcr.io/shyim/shopware-docker/6/nginx:php74-xdebug

After replacing your Folder Name and running swdc up XDebug should be activated.

To get XDebug started debugging, you need to enable it using the Chrome Extension: https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc. After this, you should get a debug request in your IDE.

Changing PHP configuration

Create a php.ini file in your project root with your configuration and restart swdc with swdc down && swdc up

Custom DockerFile build processes

Swdc currently supports a custom Dockerfile build process, but only within the app container of a given project.

Installing Docker PHP extensions (sample):

FROM ghcr.io/shyim/shopware-docker/6/nginx:php74

# See "https://github.com/mlocati/docker-php-extension-installer" for all options
RUN install-php-extensions ssh2

Tutorial

Ensuring your swdc install is currently in a down state (all containers are currently not running), you can now start your Dockerfile build.

Here we will follow a tutorial for custom WSL xdebug configuration with the nginx:php74-xdebug app container:

  1. cd ~/Code/[project_directory]
  2. mkdir .swdc
  3. nano .swdc/Dockerfile
  4. Copy this xdebug config to .swdc/xdebug.ini. You can use curl -sSL [file_raw_url] > .swdc/Dockerfile
  5. Copy this Dockerfile to .swdc/Dockerfile: curl -sSL [file_raw_url] > .swdc/Dockerfile
  6. Run swdc up. You will see your custom build commands run within the output of the up command

N.B: You can configure your Dockerfile how you like, but make sure to always specify the FROM [image_name] clause at the top of the Dockerfile. You can find this image name with docker ps -a (shows all pulled containers)

Using custom docker container as app container

Shopware docker detects automatically for your Shopware / Symfony application and provides complete images for any PHP version. Sometimes it is necessary to add a custom docker image, like when a Shopware App server is written in another language. To archive this, you can override in your project the docker configuration.

To override it, create a .swdc/service.yml in your project folder in your code directory. The content of this file will be appended to the service definition. Here is an example file:

image: my-app
environment:
  # The domain where it should be available
  # See https://github.com/nginx-proxy/nginx-proxy for all options
  VIRTUAL_HOST: my-app.dev.localhost
# Default docker-compose build a docker image of that path
build:
  context: ~/Code/random-go-app/

On the next run, swdc up will take this configuration and run that. Tip: You can use swdc up --build to let the build step rebuilt always

Resources

xdebug.ini

xdebug.remote_host=host.docker.internal
xdebug.remote_enable=1
xdebug.remote_autostart=0
#xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_log=/tmp/xdebug.log
xdebug.idekey=PHPSTORM
#xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir="/tmp/xdebug"
xdebug.profiler_output_name = "cachegrind.out.%R.%t"
xdebug.auto_trace=0
xdebug.trace_enable_trigger=1
xdebug.trace_output_dir="/var/www/html/traces"
xdebug.trace_output_name="trace.%R.%t"
xdebug.show_mem_delta=1

DockerFile

FROM ghcr.io/shyim/shopware-docker/6/nginx:php74-xdebug

RUN apk add bash nano busybox-extras
RUN mv /usr/local/etc/php/conf.d/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini.default
COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini