Debugging Delphi applications inside a Windows Docker container 27/02/2018 / JARUZAFA Hi there! Ever wondered how to deploy delphi applications inside a Windows Docker container? And how to debug them once they’re inside the container? Search no more! I will explain how to run a Windows Docker container with PAServer up and running, ready to debug your applications. This can came in handy when: Your service/app/… works great, but it fails miserably when it’s executed in a container and you need to debug it You want a quick & dirty deploy way of your service/app/… into a container, without the hassle of building a Dockerfile Remember that in Windows containers you don’t have a GUI, so you only can run service-like apps (no VCL, no Firemonkey…). The fast way To follow this tutorial you’ll need: Docker for Windows https://store./editions/community/docker-ce-desktop-windows RadStudio Tokyo release 2 (10.2.2) https://www./products/rad-studio 5 minutes Ok, let’s go ahead, follow these steps: Run Docker for Windows In context menu: Switch to Windows containers Open powershelland run: docker pull jaruzafa/paserverwindows docker run -d -h mypaserver jaruzafa/paserverwindows Now you have a Docker Windows container running PAServer at default port (64211) on host “mypaserver” Fire up RadStudio and open your project (or a console blank project just for testing) Right-click on your target plataform (Windows 32 or 64) and select “Properties” At “Profile” combo select “Add New...” Hostname: mypaserver Port: 64211 No password Important! If your target platform is Windows 32 make sure that: Project->Options->Delphi compiler->Linking->Include remote debug symbols->TRUE(otherwise you’ll get an error, eventually) Click OK and set a breakpoint on your code. Run with debug (or press F9) and wait until your breakpoint is reached 🙂 Enjoy the life This video shows all the steps https:///QngC1upfKs4 Under the hood So you want to know what’s going on to hack it and customize for your own needs, right? Good, I love your attitude. Let’s go and take a look on what you need to debug delphi apps in a container. The image First of all we need to build an image with windows and PAServer installed and running. This Dockerfile will do the job: FROM microsoft/windowsservercore ADD install_paserver.bat /paserver/install_paserver.bat ADD http://altd./releases/studio/19.0/PAServer/Release2/setup_paserver.exe ;/paserver WORKDIR /paserver RUN install_paserver.bat EXPOSE 64211 CMD ["/Program Files (x86)/Embarcadero/PAServer/19.0/paserver.exe"] It downloads the PAServer setup package from Embarcadero servers, installs it, expose the port 64211, and starts paserver.exe Pretty straightforward don’t you think? But wait… what’s that install_paserver.bat? why don’t just call setup_paserver.exe? For some reason (unkown to me), setup_paserver.exe returns an error code=1, when running on silent mode. That error code breaks the docker build, so I came up with an install_paserver.bat that forces error code to 0: setup_paserver.exe -i silent exit /b 0 So far so good! Build the image (mind the point ‘.’ at the end, it’s important): docker build -t paserverwindows . After a while you’ll have the docker image, named “paserverwindows”. The container Now that you have the image, your next step is running it: docker run -d -h mypaserver paserverwindows RadStudio side That’s it. It just works like a regular Remote Debugging project. You may name your container with a hostname using the -h parameter. If you want to tune your PAServer with a password or a custom port you’ll need to copy out configuration file. If you need more info, go to PASever documentation. http://docwiki./RADStudio/Tokyo/en/PAServer,_the_Platform_Assistant_Server_Application Some thoughts Source is available at jaruzafa/paserver-dockerwin https://github.com/jaruzafa/paserver-dockerwin Unfortunately, I couldn’t use microsoft/nanoserver image (just sized 1GB) because it lacks of 32-bit Runtime, needed for PAServer. You can run the container in interactive modewith: docker run -i -h mypaserver jaruzafa/paserverwindows But…. the console interface is quite laggy and it turn to be unusable. I have not found a solution to this, but if you come up with one, please leave a comment. I hope you have enjoyed this post as much as I have enjoyed writing it. Comments, bug reports and thoughts will be highly appreciated! ---------------------------------------------- The higher the degree, the greater the respect given to the humblest! |
|