How To Deploy Your Apps From RAD Studio To Docker
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.
{$APPTYPE CONSOLE}
{$R *.res}
program RADServerDockerDeploy;
{$APPTYPE CONSOLE}
{$R *.res} |
3. Then you have to use different units, like System.Classes, System.Types, and System.SysUtil.
System.Classes,
System.Types,
System.SysUtils,
{$IF DEFINED(POSIX)}
Posix.Stdlib,
{$ENDIF POSIX}
IniFiles;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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.
SERVER_PACKAGES = ‘Server.Packages’;
TARGET_MODULE_PATH = ‘/etc/ems/module.so’;
TARGET_SETTINGS_PATH = ‘/etc/ems/emsserver.ini’;
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.
ResStream: TResourceStream;
IniFile: TMemIniFile;
{$IF DEFINED(POSIX)}
LCommand: String;
{$ENDIF}
var
ResStream: TResourceStream;
IniFile: TMemIniFile;
{$IF DEFINED(POSIX)}
LCommand: String;
{$ENDIF} |
6. Finally, you have to use these lines:
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
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.