Skip to content

Latest commit

 

History

History
118 lines (73 loc) · 7.58 KB

readme.md

File metadata and controls

118 lines (73 loc) · 7.58 KB

Developing inside a Container

Overview

The main idea is to simplify the initial setup process for development environment. This will speed up the onboarding process for new engineers who join to our team. Developers would only need to download Docker and Visual Studio, and not have to install external tools and services (IIS, SQL Server, Virto Commerce Platform Manager). Code edits will be done from the Visual Studio as per normal and the changes will be tracked and propagated from host to the container.

Virto Commerce Platform Manager web app containerized as 2 services: 1 for web service and 1 for database. It runs as a multi-container app and orchestrate it using Docker Compose.

Developing inside a Container

Web service container based on virtocommerce/platform latest image. Additionally Web service Docker file contains code for download and install Virto Commerce modules and Visual Studio Remote Tool to enabling the debug of a .Net Framework app.

When the Web service container is started, then the Virto Commerce Platform Manager and msvsmon.exe is executed on the container as well, because msvsmon.exe and IIS is defined as an entrypoint. Msvsmon.exe is interacting with Visual Studio and therefore developer is able to set a breakpoint and debug the code.

Developer write and build code for a new module in Visual Studio locally on host machine. To ensure that any code edits on host machine are automatically propagated to the container, folder with built module on host machine is mapped to c:\vc-platform\modules folder in the container. This is only possible through bind mounting, which works similar to a mklink mount in Windows. When a path in the host 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.

Prerequisites

How to install Docker for Windows

How to use

  1. Fork repository
  2. Clone repository to local machine
  3. Open solution in Visual Studio
  4. Write code for new module
  5. Build solution

Current solution based on template for a new Virto Commerce module creation. To template solution added support for Docker Compose to a Visual Studio 2019 project, it adds the following elements in the solution:

  • New Visual Studio Project named “docker-compose” with the following files:
    • docker-compose.yml
    • docker-compose.override.yml
    • docker-compose.vs.debug.yml
    • Dockerfile
    • .dockerignore

How to build and run Docker containers

When you open solution Visual Studio tools for Docker automatically build and up docker-compose. First start can take long time for downloading base images (microsoft/mssql-server-windows-express, mcr.microsoft.com/dotnet/framework/aspnet, virtocommerce/platform) and building image from Docker file.

Visual Studio tools for Docker monitor changes in docker-compose.yml, docker-compose.override.yml, docker-compose.vs.debug.yml, Dockerfile and rebuild docker images automatically if files was changed.

Each time you open the solution, Visual Studio automatically creates containers for Web service and database service.

You can look for building images and starting up the containers in the output window by choosing Container tools in the drop-down menu.

container-tools-window

When the solution closes, the created containers are automatically deleted. This means that all changes were made to the database or to the Virto Commerce Platform Manager configuration during application debugging will be lost after the solution is closed.

How to write the code

Solution consists of 5 logically divided parts (projects):

  • .Core – this is where keep the models and abstractions of Virto Commerce module services
  • .Data – here you can find all the service implementations, repositories, entity models, migration data and configurations
  • .Web – contains the module definition, WEB API, Scripts and Localization resources
  • .Test – for testing the service and repository layer methods with Unit test
  • docker-compose - orchestration support for solution

Developer should write code for a new module in .Core, .Data and .Web projects as usual in Visual Studio locally on host machine. Also developer should write tests for the new module in .Test project.

How to debug module

Docker bind Virto Commerce platform manager web app to 80 port. So if you have locally installed IIS server you should to stop it or set for local IIS other than 80 port.

  • Build solution locally (press F6 in Visual Studio)
  • Run Virto Commerce Platform Manager in your browser: http:\localhost for w3wp.exe process will up in the container
  • Within Visual Studio, select the Attach to Process action in the Debug window:

Menu

  • Chose Connection type Remote in opened window and press the Find button to find the remote connection:

Find remote

The screenshot below shows the detected containers:

Remote container

  • Select container and press Select button.

  • Once the container has been selected, then the running process can be attached. For debugging a IIS web application select w3wp.exe process:

Attach

You can read more about Visual Studio remote debugging in this article.

Troubleshooting

License

Copyright (c) Virto Solutions LTD. All rights reserved.

Licensed under the Virto Commerce Open Software License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://virtocommerce.com/opensourcelicense

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.