Action bootstrapping

There are several scripts automatically executed before the actual action command starts.
This behaviour can be overridden by specifying a different Docker-image in the packet file definition, if this feature is enabled.

Scripts are executed in the following order:

Instance level - iteration 1

init_instance.*

Before modules are enabled, packet files with a name that starts with ‘init_instance.’ are executed. These files can first be parsed with Apache Velocity so that environment variables and such can be made available for the other scripts below.

Packet infraxys-system-include-always uses this to create environment variables for attributes that have been configured for the “container” or “environment”-level. This packet is typically added to a container that’s shared through the root-project. This way all instances of all environments will automatically have this functionality.

Module level

init.*

After all modules are made available, files in every enabled module-root that have a name starting with ‘init.’ (include the dot ‘.') are executed in alphabetical order.

The current working directory is set to that of the init-file before it’s being sourced.

Use it for things like:

  • Setting global variables about the module.
  • Configure the environment for the language(s) used in the module (see the example below).
  • Connect to a cloud provider (The aws-commons module uses this).
  • Generate SSH configuration (The infraxys-core module creates SSH config AFTER cloud providers are configured. Order of executing is determined by the init-filename).
  • Process Infraxys variables (also in the infraxys-core module).

This file is run with the current-directory at the root of the module, so the current working directory is always that of init.sh.

Example init.150.sh:

export PYTHONPATH="$(pwd)/bin:$PYTHONPATH";
export MY_MODULE_ROOT="$(pwd)";

# enable all shell-functions defined in files under "shared":
for f in shared/*.sh; do
    source $f;
done;

auto_source directory

After all init.* files have run, a list is generated of all files, for every enabled module, that are under module-root “auto-source”.

These files are sourced in alphabetical order.

Use this to make custom bash-functions available, run code that needs other modules to be configured, …

after_modules_enabled.*

The next iteration is sourcing all files with a name starting with ‘after_modules_enabled.’ in the enabled module-roots.

Use this to execute code after all modules are configured but before (non-init.*) instance-scripts are executed.

Instance level - iteration 2

after_modules_enabled.*

Before the actual action is executed, all packet files under the current instance that have a name starting with ‘after_modules_enabled.’ are sourced.

The Terraform Helper packet uses this to gather all Terraform-related files from all instances under the currently running one. This helper-packet is typically inherited by other packets that use Terraform.