File Coverage

blib/lib/Ixchel/Actions/xeno_build.pm
Criterion Covered Total %
statement 44 401 10.9
branch 0 194 0.0
condition 0 81 0.0
subroutine 15 20 75.0
pod 3 5 60.0
total 62 701 8.8


line stmt bran cond sub pod time code
1             package Ixchel::Actions::xeno_build;
2              
3 1     1   125081 use 5.006;
  1         4  
4 1     1   6 use strict;
  1         16  
  1         37  
5 1     1   5 use warnings;
  1         3  
  1         71  
6 1     1   1686 use File::Slurp;
  1         51724  
  1         105  
7 1     1   549 use String::ShellQuote;
  1         1318  
  1         80  
8 1     1   474 use Rex::Commands::Gather;
  1         171239  
  1         7  
9 1     1   1574 use File::Temp qw/ tempdir /;
  1         2  
  1         76  
10 1     1   20 use Rex::Commands::Pkg;
  1         16913  
  1         13  
11 1     1   735 use LWP::UserAgent ();
  1         80420  
  1         46  
12 1     1   20 use Ixchel::functions::perl_module_via_pkg;
  1         15  
  1         161  
13 1     1   18 use Ixchel::functions::install_cpanm;
  1         4  
  1         96  
14 1     1   17 use Ixchel::functions::python_module_via_pkg;
  1         5  
  1         89  
15 1     1   17 use Ixchel::functions::install_pip;
  1         5  
  1         109  
16 1     1   9 use Cwd;
  1         3  
  1         105  
17 1     1   8 use base 'Ixchel::Actions::base';
  1         2  
  1         60  
18              
19             =head1 NAME
20              
21             Ixchel::Actions::xeno_build - Builds and installs stuff based on the supplied hash.
22              
23             =head1 VERSION
24              
25             Version 0.1.0
26              
27             =cut
28              
29             our $VERSION = '0.1.0';
30              
31             =head1 SYNOPSIS
32              
33             =head1 OPTIONS
34              
35             =head2 build_hash
36              
37             A build hash containing the options to use for installing and building.
38              
39             =head1 BUILD HASH
40              
41             =head2 BUILD OPTIONS AND VALUES
42              
43             =head3 options
44              
45             - .options.build_dir :: Build dir to use. If not defined, .config.xeno_options.build_dir
46             is used. If that is undef, '/tmp/' is used.
47             - Default :: undef
48              
49             . options.tmpdir :: The path for a automatically created tmpdir under .options.build_dir.
50             This will be removed one once xeno_build has finished running. This allows for easy cleanup
51             when using templating with fetch and exec when using templating. This is created via
52             L->newdir.
53              
54             - .options.$var :: Additional variable to define.
55              
56             =head3 order
57              
58             An array of the order it should process the steps in. The default is as below.
59              
60             fetch
61             pkgs
62             perl
63             python
64             exec
65              
66             So lets say you have a .exec in the hash, but .order does not contain 'exec' any place in
67             the array, then whatever is in .exec will not be processed.
68              
69             If you want to run exec twice with different values, you can create .exec0 and .exec with
70             the desired stuff and set the order like below.
71              
72             exec0
73             pkgs
74             exec
75              
76             First .exec0, then pkgs, and then .exec will be ran. The type is determined via removing
77             the end from it via the regexp s/[0-9]*$//. So .perl123 would be ran as perl type.
78              
79             Unknown types will result in an error.
80              
81             =head3 vars
82              
83             This is a hash of variables to pass to the template as var.
84              
85             =head3 templated_vars
86              
87             These are vars that are to be templated. The output is copied to
88             the matching name to under vars.
89              
90             =head2 TYPES
91              
92             - .$type.for :: 'for' may be specified for any of the types. It is a
93             array of OS families it is for.
94             - Default :: undef
95              
96             =head3 fetch
97              
98             - .fetch.items.$name.url :: URL to fetch.
99              
100             - .fetch.items.$name.dst :: Where to write it to.
101              
102             - .fetch.template :: If the url and dst should be treated as a template.
103             - Default :: 0
104              
105             .fetch.items is a hash for the purpose of allowing it to easily be referenced later in exec. If .fetch.items.$name.url or
106             .fetch.items.$name.dst is templated, the template output is saved as that variable so it can easily be used in exec.
107              
108             Variables for template are as below.
109              
110             - config :: Ixchel config.
111              
112             - options :: Stuff defined via .options.
113              
114             - os :: OS as per L.
115              
116             =head3 pkgs
117              
118             - .pkgs.present :: A hash of arrays. The keys are the OS seen by
119             L and values in the array will be ensured to be
120             present via L.
121             - Default :: undef
122              
123             - .pkgs.latest :: A hash of arrays. The keys are the OS seen by
124             L and values in the array will be ensured to be
125             latest via L.
126             - Default :: undef
127              
128             - .pkgs.absent :: A hash of arrays. The keys are the OS seen by
129             L and values in the array will be ensured to be
130             absent via L.
131              
132             So if you want to install apache24 and exa on FreeBSD and jq on Debian, it would be like below.
133              
134             {
135             pkgs => {
136             latest => {
137             FreeBSD => [ 'apache24', 'exa' ],
138             Debian => [ 'jq' ],
139             },
140             },
141             }
142              
143             =head3 perl
144              
145             - .perl.modules :: A array of modules to to install via cpanm.
146             - Default :: []
147              
148             - .perl.reinstall :: A Perl boolean for if it should --reinstall should be passed.
149             - Default :: 0
150              
151             - .perl.notest :: A Perl boolean for if it should --notest should be passed.
152             - Default :: 0
153              
154             - .perl.force :: A Perl boolean for if it should --force should be passed.
155             - Default :: 0
156              
157             - .perl.install :: Ensures that cpanm is installed, which will also ensure that Perl is installed.
158             If undef or 0, then cpanm won't be installed and will be assumed to already be present. If
159             set to true, it will be installed if anything is specificed in .perl.modules.
160             - Default :: 1
161              
162             - .perl.cpanm_install :: Install cpanm even if .cpanm.modules does not contain any modules.
163             - Default :: 0
164              
165             - .perl.pkgs :: A list of modules to install via packages if possible.
166             - Default :: []
167              
168             - perl.pkgs_always_try :: A Perl boolean for if the array for .cpanm.modules should be appended to
169             .cpanm.pkgs.
170             - Default :: 1
171              
172             - perl.pkgs_require :: A list of modules to install via packages. Will fail if any of these fail.
173             - Default :: []
174              
175             For the packages, if you want to make sure the package DB is up to date, you will want to set
176             .pkgs.update_package_db_force to "1".
177              
178             =head3 python
179              
180             Install python stuff.
181              
182             - .python.pip_install :: A Perl boolean for if it should install python. By default only installs
183             python and pip if .python.pip[0] or .python.pkgs[0] is defined.
184             - Default :: 1
185              
186             - .python.modules :: A array items to install via pip.
187             - Default :: []
188              
189             - .python.pkgs :: A array items to install via packages if possible.
190             - Default :: []
191              
192             - .python.pkgs_require :: A array items that must be install via pkgs.
193             - Default :: []
194              
195             - python.pkgs_always_try :: If pkgs should always be tried first prior to pip.
196             - Default :: 1
197              
198             =head3 exec
199              
200             - .exec.commands :: A array of hash to use for running commands.
201             - Default :: []
202              
203             - .exec.command :: A command to run.
204             - Default :: undef
205              
206             . exec.dir :: Directory to use. If undef, this will use .options.tmpdir .
207             - Default :: undef
208              
209             - .exec.exits :: A array of acceptable exit values. May start with >, >=, <, or <= .
210             - Default :: [0]
211              
212             - .exec.template :: If the command in question should be treated as a TT template.
213             - Default :: [0]
214              
215             Either .exec.commands or .exec.command must be used. If .exec.commands is used, each value in
216             the array is a hash using the same keys, minus .commands, as .exec. So if .exec.commands[0].exits
217             is undef, then .exec.exits is used as the default.
218              
219             If .exec.commands[0] or .exec.command is undef, then nothing will be ran and even if .exec exists.
220             Similarly if .command for a hash under .exec.commands, then nothing will be ran for that hash,
221             it will be skipped.
222              
223             =head2 TEMPLATES
224              
225             Template is done via L