upsun resources:set.
Optional in single-runtime and composable images.
After your app is built, its file system is read-only.
To make changes to your app’s code, you need to use Git.
For enhanced flexibility, Upsun allows you to define and use writable directories called “mounts”.
Mounts give you write access to files generated by your app (such as cache and log files)
and uploaded files without going through Git.
When you define a mount, you are mounting an external directory to your app container,
much like you would plug a hard drive into your computer to transfer data.
- Mounts aren’t available during the build.
- When you back up an environment, the mounts on that environment are also backed up.
Define a mount
To define a mount, use the following configuration:<MOUNT_PATH> is the path to your mount within the app container (relative to the app’s root).
If you already have a directory with that name, you get a warning that it isn’t accessible after the build.
See how to troubleshoot the warning.
The accessibility to the web of a mounted directory depends on the
web.locations configuration.
Files can be all public, all private, or with different rules for different paths and file types.
Note that when you remove a tmp mount from your .upsun/config.yaml file,
the mounted directory isn’t deleted.
The files still exist on disk until manually removed,
or until the app container is moved to another host during a maintenance operation.
Example configuration
Ensure continuity when changing the name of your mount
Changing the name of your mount affects the defaultsource_path.
Suppose you have a /my/cache/ mount with an undefined source_path:
If you rename the mount to /cache/files/, it will point to a new, empty /cache/files/ directory.
To ensure continuity, you must explicitly define the source_path as the previous name of the mount, without leading
or trailing slashes:
The /cache/files/ mount now points to the original /my/cache/ directory, maintaining access to all your existing
files in that directory.
Share a mount between several apps
By design,storage mounts are shared between different instances of the same app,
which enables horizontal scaling.
In a multi-application context,
you can even share a storage mount between different applications in the same project.
To do so, you need to define a storage mount in each of your app containers,
and point each of those mounts to the same shared external network directory.
Use the following configuration:
<MOUNT_PATH_1>and<MOUNT_PATH_2>are the paths to each mount within their respective app container (relative to the app’s root).- When configuring the first
storagemount, you don’t need to include theservicekey. The first mount implicitly points to an external network directory. Theservicekey is required for subsequent mounts, to ensure they use the same external network directory as the first mount. - The
source_pathallows you to point each mount to the same subdirectory within the shared external network directory.
Example
Suppose you have abackend app and a frontend app, and you want both apps to share data from the same mount.To achieve this, complete the following steps:
- In your
backendapp configuration, define astoragemount:
storage mount named var/uploads in the backend app container.
The mount points to the backend/uploads directory within an external network directory.
- In your
frontendapp configuration, define anotherstoragemount:
storage mount named web/uploads in the frontend app container.
The service key allows you to specify that the web/uploads mount should use the same external network directory
as the mount previously defined in the backend app container.
The source_path key specifies which subdirectory within the external network directory both mounts should share (
here, the backend/uploads directory).
Note that another way to share data between apps through a mount is by
explicitly defining a Network Storage service.
Composable image only: Local mounts
If you need a local mount (i.e. unique per container), Upsun allows you to mount a directory within the/tmp directory of your app.
However, the following limitations apply:
- Content from
tmpmounts is removed when your app container is moved to another host during an infrastructure maintenance operation - The
/tmpdirectory has a maximum allocation of 8 GB
tmp mounts are ideal to store non-critical data, such as your application cache which can be seamlessly
rebuilt,
but aren’t suitable for storing files that are necessary for your app to run smoothly.
Note that Upsun will provide new local mounts in the near future.
Overlapping mounts
The locations of mounts as they are visible to application containers can overlap somewhat. For example: In this case, it does not matter that each mount is of a differentsource type.
Each mount is restricted to a subfolder within var, and all is well.
The following, however, is not allowed and will result in a failure:
The storage mount type specifically exists to share data between instances of the same application, whereas tmp and instance are meant to restrict data to build time and runtime of a single application instance, respectively.
These allowances are not compatible, and will result in an error if pushed.