Configuration and Structure

It looks like tank is literally spitting them everywhere. Generally we differentiate between studio, project and localized configuration types, as well as per-bundle configuration, and configuration within shotgun itself.

Let's define some abstract root paths, which are used when denoting any paths

Everything written in the following is based on my knowledge so far, obtained through reverse-engineering.

BUNDLE Configuration

A bundle is identified exclusively through it's manifest, info.yml. It's well documented, and handled by tank entirely. You won't have to touch it unless you are an app developer.

It's worth nothing though that the tk-core bundle has special wrapper scripts at BUNDLE/setup/root_binaries/tank[.bat] which are copied to the PROJECT configuration whenever a new project is setup. They are called by the shotgun web GUI, see How Shotgun Web integrates with Tank.

TANK_STUDIO Configuration and Installation

By default, the TANK_STUDIO root only contains basic configuration that will rarely change, and an installation of tk-core (a single version), and all required engines and apps. The term required means that tank will automatically install what's needed based on PROJECT configuration when the first one is initialized. As most people start out with the tk-config-default one, they will end up with about 625MB on disk. The data is quite redundant, so git compresses it down to 150MB. The engines and apps may exist in various versions in parallel, which allows you to switch between them safely.

tk-core maintains its own installation, organizing its bundles like so:

TANK_STUDIO/install/BUNDLE_TYPE/SOURCE    /BUNDLE_NAME/VERSION/
TANK_STUDIO/install/engines    /app_store/tk-maya     /v0.4.1

The core itself is located at TANK_STUDIO/install/core.

Therefore, core doesn't support versions, as it has to serve as an entry point that needs to be known very well. In theory, I believe multi-version cores can be implemented even with the current version, but consistent upgrade paths might be difficult to achieve if people jump between versions.

A fresh installation places the studio configuration into TANK_STUDIO/config/core, which contains the following files

PROJECT Configuration

This seems to be a more hard-coded location, as it is always in the PROJECT root, no matter where you install the tank configuration to, and is required for tank to find its context from any path within the project. To do that, it will search upwards from a given project path and try to find a 'tank' directory, which will be used to find the pipeline configuration for that project, and complete the bootstrapping process.

It hosts the following files

TANK_PROJECT Configuration

This is a big one, as it keeps plenty of interesting caches and configuration files and shows that tank tries really hard to be somewhat pseudo relocatable. Primarily it masks that the actual installation is in the TANK_STUDIO root.

The caches are located at TANK_PROJECT/cache

The second largest part is the TANK_PROJECT/install directory, which superficially looks like the TANK_STUDIO/install location. Except for it's all fake to simulate some expected structure for some scripts that should work there and in the actual TANK_STUDIO/install location.

The interesting files are in TANK_PROJECT/install/core

Now we enter the heart of the configuration, TANK_PROJECT/config. It noteworthy that it is a bundle, which means that it can be 'installed' with git and versioned. It's part of the 'evolving configuration' paradigm, and can be replaced by other, possibly pre-made, configurations 'relatively' easily. Those could be tk-config-default or tk-config-multi-root.

The config bundle can be supposedly be used by apps and frameworks to grab icons, hooks and configuration files. However, I believe it's primarily used by tk-core and then given to other bundles through APIs. Didn't dig into that though.

As most of the contents is well described in the official docs, I will focus on the files interesting to the tank startup. Let's look at TANK_PROJECT/config/core. All files not mentioned here are the same as in TANK_STUDIO/config/core

SHOTGUN Configuration

The PipelineConfiguration entity contains the project's TANK_PROJECT root paths for all platforms, and allows the shotgun web gui to find the tank executable at TANK_PROJECT/tank to obtain tank related information and work with the file system.

In conjunction with the shotgun plugin (formerly java plugin), this allows shotgun to execute arbitrary files and obtain their standard output, standard error and exit code. This is used to populate right-click menues with configured launchers, and to execute tank commands on the user's machine.

How Shotgun Web integrates with Tank

The shotgun plugin is able to execute files, and that's it. This capability is used to launch the project-specific tank executable. This one is known thanks to the 'primary' (or whichever) PipelineConfiguration entity associated with the project.

This command is a boostrapper which loads tk-core and uses it for evaluating the configuration, returning values interpreted by java script (?).

Those are typical invocation the gui frontend does, including their return values

${config}/tank shotgun_cache_actions Asset shotgun_mac_asset.txt
ins writes the specified text file - apparently configuration loading is slow enough to require
 a speed up. This is something to think about when bringing in own tools,  
 who should be fast too
${config}/tank shotgun_get_actions shotgun_mac_asset.txt shotgun_asset.yml
 Runs in 0.017 seconds, bash only
> launch_nuke$Launch Nuke$$False
> show_in_filesystem$Show in File System$$True
> launch_photoshop$Launch Photoshop$$False
> preview_folders$Preview Create Folders$$True
> create_folders$Create Folders$$True
> launch_screeningroom$Show in Screening Room$$False
> launch_maya$Launch Maya$$False
${config}/tank shotgun_run_action launch_nuke Task 2517
 launches nuke, after redirecting the call to tank_cmd_login.sh, which is similar to tank_cmd.sh
 but uses a different shebang. Copy-past at its finest.
 In the end it launches tank like so (after setting the PYTHONPATH accordingly)
 /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python [...]/dependencies/lib/tank/studio/install/core/scripts/tank_cmd.py [...]/dependencies/lib/tank/studio shotgun_run_action launch_maya Task 2517 --pc=[...]/PROJECT/etc/tank
 It is refusing to use the CWD for anything (as a native context for instance)
 This command takes exactly 7s due to various shotgun queries, until it finally launches nuke

Conclusions are

The tank command startup sequence

As called by the web gui, or from the commandline

Note that the TANK_STUDIO/tank startup sequence is similar, but determines by the presence or absence of files what kind of installation it is. For example, the presence of the TANK_STUDIO/config/core/templates.yml indicates a project installation, and maybe even that it is localized.

Tank Context and how engines start up

In order to bring contextual information to the application, tank can use various ways. Generally, it can do it by path, and by entity.

When launching something from the built-in launchers, the context is set using a pickled dict, containing entity data.

Environment Variables