Skip to content

Modules development via docker

Overview

The main idea is to simplify the initial setup process for Virto Commerce (VC) module development environment. This will speed up the onboarding process for new engineers who join our team. Developers would only need to install Docker and Visual Studio, but not external tools / services (VC Platform, SQL Server, Elastic Search, Redis). Coding is done in Visual Studio as usual, and the changes would be tracked and propagated from host to the container.

Read how to Deploy module from source code

Description

Virto Commerce Team have created docker-compose.yml to run VC Platform 2Manager web app.

VC Platform Manager web app was containerized as several services: Web service (Platform manager), External services for MS SQL Server, Elastic Search and Redis. It's run as a multi-container app and orchestrated by using Docker Compose.

Developing inside a Container

Storefront and Theme are not included in this solution.

Web service container is based on virtocommerce/platform latest Linux image.

The Developer writes and builds code for a new module in Visual Studio locally, on host machine. In order to ensure that any code edits on host machine are automatically propagated to the container, ./Modules and ./App_Data/Modules folders on host machine is automatically mapped to /opt/virtocommerce/platform/Modules and /opt/virtocommerce/platform/App_Data/Modules folders in the container. This is only possible through bind mounting. When a path in the host is mounted to a path in the container, the contents of the host directory will completely overwrite whatever is in the container directory, regardless of whether the container directory has files which were not present in the host directory at mount time. The result is that the container directory will be an exact snapshot of the host directory. This makes the development experience feel more natural. This is done by volume mapping in docker-compose file.

For the docker and docker-compose files configuring convenience, all configurable parameters have placed on separate .env file. In the .env file you can set values for:

  • PLATFORM_VERSION - tag for required virtocommerce/platform image (default value dev-linux-latest)
  • MODULES_VOLUME - path to the ./Modules folder on host machine
  • APP_DATA_MODULES - path to the ./App_Data/Modules folder on host machine
  • DB_PASS - SQl Server service password
  • REDIS_PASS - Redis service password (default value passwd@123)
  • SEARCH_PROVIDER - used in VC Platform search provider (default value ElasticSearch)

Prerequisites

How to install Docker for Windows

  • For Docker installation, first review the information at Docker for Windows: What to know before you install
  • Install Docker Desktop for Windows on your machine
  • During installation you'll need to choose Linux as operating system used inside your containers and install update for WSL 2 (Windows Subsystem for Linux)

How to use

  1. Copy ModulesDevelop folder to local machine
  2. Create an external network for the Docker engine. Run the following command in powershell with elevated admimistrator priviliges:
docker network create nat
  1. Parameterize values in the .env file.
APP_DATA_MODULES=c:\path\to\folder\modules

You can also parameterize the platform version and search provider in the .env file

PLATFORM_VERSION=dev-linux-latest
...
SEARCH_PROVIDER=ElasticSearch
  1. Build and launch docker-compose by command:
docker-compose -f c:\path\to\modulesdevelop\docker-compose.yml up --build -d
  1. Run Virto Commerce Platform Manager - http://localhost:8090/ (configure modules as sample data)
  2. Create new module as described in the article
  3. Write code for new module
  4. Build new module
  5. Copy built module to Modules folder
  6. Debug new module

Run Virto Commerce Platform Manager

Once the containers are started, open VC Platform Manager. This will launch the application and install default modules. After modules have been installed you need to restart the container with the platform what gives you the opportunity to configure sample data.

Choose sample data

Copy built module to Modules folder

  • Navigate to the Modules folder on local host
  • Create folder for newly created module
  • Copy your_module_project.Web folder to the created folder

Debugging the module

  • Build solution locally (press F6 in Visual Studio)
  • Within Visual Studio, select the Attach to Process action in the Debug window:

image

  • Chose Connection type Docker(Linux Container) (1)
  • In opened window and press the Find button to find the remote connection(2)
  • Select virtocommerce.platform.web container (3)
  • Press Ok button (4)

image

  • Once the container has been selected, then the running process can be attached. For debugging a .Net Core application select dotnet process:

image

If the new module has been rebuilt:

  • Overwrite folder for newly created module by your_module_project.Web
  • Restart the platform - click Setigns->Restart on Platform manager UI:

Reststrt platform

Cleanup environment after debugging

When debugging process has finished, stop docker-compose by command:

cmd docker-compose down

Don't forget to delete newly created module from the Modules and Modules\AppData folders.

If you need to recreate platform database for next debug session, remove db-volume by command:

cmd docker volume rm db-volume

How to

Troubleshooting


Last update: March 23, 2023