user1760100
user1760100

Reputation: 31

Build RPM package to selectively deploy sources

I'm reasonably new to RPM but i've been playing with it and need to do something a bit left field.

I must obey rules which say that I must use the same rpm package in each environment, I cannot use %pre and %post to modify files.

The problem is that my install is not doing a make, infact I'm copying a file structure of text files and xml files. However these files contain environment specific code, but sadly I must follow the guidelines.

The 'solution' I have considered is to use several source files, source0 being dev, source1 being test and source2 being production while source3 is a disaster recovery. Each source extracts to a folder with the environment name (this is desired!)

$deploy_folder/dev_code

$deploy_folder/test_code

$deploy_folder/prd_code

I will be given an environment variable which tells me the environment.

Thus far I have deployed all sources and then removed the unnecessary folders using a condition

if [[ $env_variable == "PRD" ]] ; then

rm -rf $buildroot/install/$deploy_folder/dev_code

rm -rf $buildroot/install/$deploy_folder/test_code

fi

*i've simplified the variables above somewhat

This appears to work at build time, however when I perform an rpm -i it does not deploy all code then remove the other folders at the final destination.

Clearly, I'm probably not using RPM in the correct spirit, so am i doing this the correct way? is there a better way given my files are essentially all environment specific?

How do I access what code is deployed to the final destination?

Thanks

Upvotes: 3

Views: 2116

Answers (1)

user648129
user648129

Reputation:

What you are asking is a single rpm for development, testing and production environment. At build time you will obviously need to build all files. I am assuming you are building everything fine i.e in %build section you have copied files to

$RPM_BUILD_ROOT/$deploy_folder/dev_code
$RPM_BUILD_ROOT/$deploy_folder/test_code
$RPM_BUILD_ROOT/$deploy_folder/prd_code

and after that included those files in rpm(s) generated using %files section.

You can always check whether build rpm has files at correct place using:

rpm -qpl <rpm file.rpm>

Because you want to base installation on presence of environment variables at install time %post can be used. It is a section which gets used after installation of rpm. If you want some cleaning to be done during uninstall, you can use %postun (or %preun) sections. Assuming $TESTENV is environment variable which has PRD for production, DEV for development and TEST for test, following piece in %post section can be used:

if if [ "$TESTENV" = "PRD" ]; then
    rm -rf $deploy_folder/dev_code
    rm -rf $deploy_folder/test_code
fi
if [ "$TESTENV" = "DEV" ]; then
    rm -rf $deploy_folder/prd_code
    rm -rf $deploy_folder/test_code
fi
if [ "$TESTENV" = "TEST" ]; then
    rm -rf $deploy_folder/dev_code
    rm -rf $deploy_folder/prd_code
fi

Creating a single rpm for PRD, TEST, DEV is not a recommended way to do things, but in case your requirement is that, your approach seems to be fine.

%pre, %post, %preun, %postun are sections which are used at install time and can check environment variable at install time. You cannot do it at build time obviously, so you have to use these sections. In case you have to avoid them then you may want to drop the idea of a single rpm for all prod, devel and test. Dropping a single rpm is a better idea. Single spec file can create three different rpms for prod, test and devel as sybpackages as well. Other way is to generate separate rpms for all three prod and test and devel from a single spec (which doesn't differentiate between different environments and doesn't have 3 copies of similar files in rpms.

Upvotes: 2

Related Questions