Volumes
Copy page
Every deploy and restart gives a service a fresh filesystem, so a file your app writes is gone the next time the service starts. A volume keeps one folder across deploys and restarts. Use a volume for a SQLite database, uploaded images or a small Postgres database behind a tool.
Add a volume on the first deploy
Section titled “Add a volume on the first deploy”To keep a folder from the very first deploy, name the folder on the deploy:
grayspar deploy --volume app=/app/dataThe name before the = is the service. A service at the root of your folder is called app, and a service in a subfolder takes that folder’s name. Running the same command on every deploy is safe, because a folder the service already keeps stays as it is.
Add a volume later
Section titled “Add a volume later”To keep a folder of a running service, run grayspar volume add with the folder’s path inside the service. The project redeploys by itself:
grayspar volume add /app/data✓ Added volume /app/data to app✓ Redeployed <project-name>When a project has several services, name the service with --service. A service keeps one volume.
Find the folder in your app
Section titled “Find the folder in your app”Grayspar puts the volume’s path in the GRAYSPAR_VOLUME_PATH variable. Read the folder from there, so your app and the volume always agree:
import osimport sqlite3
data_folder = os.environ.get("GRAYSPAR_VOLUME_PATH", "./data")database = sqlite3.connect(os.path.join(data_folder, "<database-name>.db"))See how full a volume is
Section titled “See how full a volume is”To list the volumes of a project and how much each one holds, run grayspar volume:
SERVICE PATH USEDapp /app/data 12 MB of 1.0 GBA volume grows by itself as it fills, as long as your team’s plan has storage left. When the plan’s storage is all in use, the team’s owners get an email saying which volume is full.
How a volume changes a deploy
Section titled “How a volume changes a deploy”A service with a volume restarts in place when it deploys, because two copies writing the same files would corrupt them. The service is down for the moment its new copy takes to start. A service with no volume switches to its new copy with no downtime.
Images that declare a volume
Section titled “Images that declare a volume”Some images declare a folder as data, such as the official Postgres image. Grayspar keeps that folder on a volume without being asked. An image that declares several folders fails its build with a message naming the folders, and --volume picks the one to keep.
Remove a volume
Section titled “Remove a volume”Removing a volume deletes its data, so only an owner of the team can do it, and the CLI asks first:
grayspar volume remove /app/dataGrayspar deletes the data only after the service has redeployed without the volume and is running.