Introduction: Docker Support In Visual Studio IDE for Enterprise Server projects
In our last post, we discussed some of the support added into the Visual Studio IDE for working with Docker when using native COBOL projects. This time we will cover some of the specifics for working with Enterprise Server projects in conjunction with Docker; including deploying code to a containerised Enterprise Server from the IDE to debug. We will be building upon the content from the previous post, so it is worth reading that first.
Containerising ES (Enterprise Server) Projects
Enterprise Server projects are designed to deploy programs to a server running under an instance of ES. Typically, a developer would have an instance of ES running on their local machine to test against. There is usually a server set up in ES that is associated with the project in the IDE. This is then used to deploy and debug the application being developed. With the new containerisation support, the ES instance will instead be running inside a container instead of directly on the host machine. This isolates the execution environment from the development environment, giving the developer greater confidence that their code will perform correctly in production. Additionally, if the application is containerised in production, it is possible to test against the same environment locally.
Adding Docker support
Adding Docker support in a ES project is as simple as clicking the Add -> COBOL Docker Support button on the project node in Solution Explorer. When adding Docker support to a ES project, the developer will be prompted for a few items. This includes defining a server that should be started inside the containerised environment. There are two options for supplying a server definition.
- Create from associated server
- If the project is already associated with a local ES server, then a server definition can be exported from it. This definition can then be used to create instance within the container.
- Create new server from a server definition file
- Specify a name and the file location of the server definition
After the server definition has been provided and a number of items will be added to the ES project.
- This defines how the Docker image should be built. It retains the same structure as mentioned in the previous post with a base, build and final layers
- Folder containing PowerShell script and server definition file
- The PowerShell script gets invoked when the container starts. This setups ES and creates the server within the container. It also deploys any ES packages that are present
- Docker debug launch profile
- Profile for debugging within a container. Provides a means of configuring the debug launch settings.
Launching and Debugging a Container
Docker Debug Profile
When launching to debug inside a container, the developer needs to ensure that the Docker debug profile is active. This profile gets added when the Docker support is added, and is selectable in the launch profile dropdown in the top toolbar. To configure the launch settings, open the Debug page within the project properties. If the values are left blank, default values will be used.
What happens on launch
The steps to debugging a containerised ES project are similar to those of a containerised console project. For ES projects, the steps are as follows:
- Build project locally
- Build base layer of image from Dockerfile
- Start container from new image and run the DeployAndWait.ps PowerShell script inside the container. We also volume mount the output directory to a location in the container. By default, this is C:\app.
- PowerShell script starts up ES, creates the server from the included definition and deploys any services in the output directory.
- Debugger in the IDE attaches to ES instance running inside the container
Once a developer has triggered a Docker debug session, the Server Explorer tool window will automatically show a node for the ES instance. This node will be labelled with an IP address, this is the address of the ES instance within the container. Servers hosted by the ES instance will show up as sub nodes and can be interacted with as usual.
Visual Studio Container Tool Window
Visual Studio 2019 has a built in Containers tool window. It is possible to view and manage containers/images directly within the IDE.
This covers some of the specifics for enabling Docker support for Enterprise Server projects. In it we covered how to add container support to ES projects and how debugging works. I hope this has been useful and further information on the 6.0 release can be found in our docs.
Don't forget to attend the launch webinar to find out more: