Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

How To Deploy Your Apps From RAD Studio To Docker

deploy from rad studio to docker featured image 2

Docker helps you to simplify and automate the deployment process for your applications effectively. It enables you to package your software in a way that is predictable and consistent. As a result, it has grown in popularity among development teams all over the world. This post will go over the specifics of deploying your application from IDE Software to Docker. Let’s get started.

What is Docker?

Docker is an open-source containerization platform for building, deploying, and managing applications. It enables you to package apps into containers, which simplifies the delivery significantly. It takes away repetitive tasks from the product development lifecycle to accelerate the process of building applications.

Why should you use Docker?

How do I deploy an app from RAD Studio to a Docker container?

Deploying from RAD Studio to Docker is pretty simple. You just need to follow these processes:

Configure the Project File

1. Create a file, called RADServerDockerDeploy.dpr. It will have the source code of the main file in the project.

2. Next, you have to specify the program.

program RADServerDockerDeploy;




{$APPTYPE CONSOLE}




{$R *.res}

3. Then you have to use different units, like System.Classes, System.Types, and System.SysUtil.

uses

System.Classes,

System.Types,

System.SysUtils,


 {$IF DEFINED(POSIX)}

 Posix.Stdlib,

 {$ENDIF POSIX}


IniFiles;

4. Now, you have to specify server packages, server module path and target settings path.

const

SERVER_PACKAGES = 'Server.Packages';

TARGET_MODULE_PATH = '/etc/ems/module.so';

TARGET_SETTINGS_PATH = '/etc/ems/emsserver.ini';

5. Then you have to define ResStream, IniFile, and LCommand variables.

var

 ResStream: TResourceStream;

 IniFile: TMemIniFile;

{$IF DEFINED(POSIX)}

 LCommand: String;

{$ENDIF}

6. Finally, you have to use these lines:

begin

  try

    // Add your RAD Server resource module .so file via Project|Resources and Images...|Add...

    // Be sure to set Identifier to Module and Type should be set to RCDATA

    ResStream := TResourceStream.Create(HInstance, 'Module', RT_RCDATA);

    try

      ResStream.Position := 0;

      ResStream.SaveToFile(TARGET_MODULE_PATH);

    finally

      ResStream.Free;

    end;




    IniFile := TMemIniFile.Create(TARGET_SETTINGS_PATH);




    IniFile.EraseSection(SERVER_PACKAGES);

    IniFile.WriteString(SERVER_PACKAGES,TARGET_MODULE_PATH,ExtractFileName(TARGET_MODULE_PATH));




    IniFile.UpdateFile;

    IniFile.Free;




    {$IF DEFINED(POSIX)}

    LCommand := 'service apache2 restart';

    _system(PAnsiChar(AnsiString(LCommand)));

    {$ENDIF POSIX}




  except

    on E: Exception do

      Writeln(E.ClassName, ': ', E.Message);

  end;

end.

What does the finished Delphi .Dproj file look like?

Due to the limitations of the blogging platform (which doesn’t like XML) please refer to the source code download for an example of configuring the .DPROJ file.

Where can I get the source code of deploying an app to Docker?

Get the full example source code of deploying your apps to Docker here: https://github.com/Embarcadero/pa-radserver-ib-docker/

Should I really use Docker for deployment?

Docker can decrease deployment time to seconds. So, the entire process becomes very swift. Besides, Docker is free of environmental limitations, which makes deployment consistent and scalable. So, you should definitely consider using it.


RAD Studio is a powerful IDE for building high-performance cross-platform applications quickly. Try it now, for free!

Exit mobile version