Working with Files

Learn how to manage configuration files for Containers in Humanitec

What are Files?

Files are injected into the file-system of the Container at Runtime. They are normally used to provide configuration files for processes that cannot be configured via Environment Variables.

Files differ from Volumes in that they cover specific files rather than directories. Files are also reset on every deployment. You should use Files for things related to configuration that might need to be changed by developers. You should use Volumes for things related to data that the app creates or consumes.

On deployment, Humanitec collects Files defined for containers in a Workload into either a ConfigMap or Secret Kubernetes object. They are then inserted into a to containers's file-system via a projected volume.

Path and Permission Mode

Files are inserted into the Container's file-system at a particular Path and with a particular Permission Mode.

The path must be an absolute path to a file. This means it must start with / and cannot end with /. It must be a valid Unix style file path.

The Permission Mode defines the permission bits on the file in the file-system. Unix like systems (including Linux) define 3 possible sets of permissions for a file:

  • Permissions for the owner of the file

  • Permissions for the group that owns the file

  • Permissions for all users on the system

Each of these permissions can be any combination of Read, Write or Execute. The block of permissions is traditionally written as 3 Octal digits with each digit representing 3 bits for Read, Write and Execute for each of the permissions. You can use tools like permissions-calculator.org to help you calculate the Octal mode for a file. Humanitec defaults to 0777 which allows read, write and execute on all files.

Using Placeholders

Sometimes the value of some configuration will change depending on the Environment that a workload is deployed into. For example, you may want your workload to connect to a different database in a development than in a production environment. To allow for this, Humanitec provides placeholders that can be inserted into the variable values.

Placeholders are of the form ${...} where the content is a placeholder path. Any number of placeholders can be included in the value of a variable. For example:

Hello ${values.PLACEHOLDER_EXAMPLE}!

Will resolve the shared value PLACEHOLDER_EXAMPLE at deployment time and insert the value into the string above.

Find out more about placeholder you can use:

Secrets

Sometimes a file contains a sensitive value that should not be visible to other developers. An example of this would be database credentials. Secrets should be stored as shared Values and Secrets and then referenced in a file using a placeholder. If the content of a placeholder is a secret, Humanitec will automatically convert the entire value into a secret.

Add a File

Environment Variables are added as "Variables" to Containers inside a Workload.

UI
CLI
API
UI
  1. Enter the Workload Details screen for the Workload you want to work on.

  2. Ensure you are in Draft mode. If you are not, you can select it from the Deployment drop-down.

  3. Choose the container in the workload you want to update.

  4. Enter the full path of where the file should be located in the Container's file-system.

  5. Enter the mode for the file as an octal number. The most permissive permissions is 0777.

  6. Click Create to create the file and bring up the editor.

Typing Enter or Tab moves you to the next field

CLI

Our CLI is currently in closed beta. Please contact us if you want to learn more.

API

Adding Files involves adding a property to the files section of the container object in the spec section of a module in a Deployment Set. See Deployment Deltas in the API Documentation for more details of how this can be done.

Working with the File Editor

UI
CLI
API
UI
  1. Enter the content of the file in the main area,

  2. To help with editing, you can select a syntax highlighting scheme.

  3. Click Done to save your changes.

  4. Click Cancel to discard your changes.

Working with the Editor.
CLI

Our CLI is currently in closed beta. Please contact us if you want to learn more.

API

There is no editor in the API.