Delphi How To Deploy Your Apps From RAD Studio To Docker

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
How To Deploy Your Apps From RAD Studio To Docker
By Md. Ehsanul Haque Kanan August 19, 2021

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. That’s why it has become very popular among development teams around the globe. In this post, you will know the details of deploying your application from RAD Studio to Docker. Let’s dive in.

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?​

  • Streamlines the development lifecycle for fast and consistent delivery of your applications
  • Supports responsive deployment and scaling
  • Offers a lightweight, fast and cost-effective solution

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.
Код:
сonst
 
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: Для просмотра ссылки Войди или Зарегистрируйся

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.