Working with environments
Each project on Hosty has one production environment and as many development environments as you need, within the resources the admins set for the cluster. A development environment is a copy of the site for a branch, a test or a review, with a copy of the production data. You create and delete them as you like.
Production and development
The environment named production is the live site. Any other name makes a development environment.
| Production | Development |
|---|---|---|
Name | production, exactly | anything else, i.e. stage or feature-123 |
Servers | production nodes | development nodes, shared by the projects of the cluster |
Pods | 2 or more, added and removed with the load | 1 |
Database | the real data | a copy without the data of the excluded tables |
Backups | 3 times a day by default | none |
Cron jobs | on | off, unless turned on in hosty.yaml |
Who sees it | lead developers and CI | everyone on the project |
Deleted by | the admins only | anyone on the project |
replicas in hosty.yaml sets a fixed number of pods instead. The rest is the same on all environments, i.e. the code of PHP and Node.js applications is read-only everywhere.
The environments of a project live in two namespaces of the cluster: <project>-production and <project>-development. On MySQL, the database of a development environment is named <project>_development_<environment>_<application>.
Naming environments
A name:
- has up to 24 characters;
- has only letters, digits, - and _;
- starts and ends with a letter or a digit.
Hosty makes the name lowercase and replaces _ with -, so Feature_123 becomes feature-123. Only production is production: Production is refused, so that a branch can't be deployed to production by mistake.
We recommend naming environments after Git branches, with main deployed to production. It shows at a glance which code an environment runs, and lets CI delete the environments of deleted branches (see below).
Domains
Each application of a development environment gets a domain:
<application>-<environment>.<project>.<hosted zone>For example, backend-stage.example.<hosted zone> for the application backend of the environment stage. The domains of development environments are open to the internet and have HTTPS. To see the domains of an environment, run hosty domains <environment>. Production runs only on the domains of the site, set in hosts: see Adding a custom domain. A development environment can have its own domain too: see Setting up a staging environment.
Where the data comes from
A new environment starts with the data of production, from its latest backups:

- Database. Production is backed up 3 times a day, at 0:00, 8:00 and 16:00 UTC by default (backup.hours in hosty.yaml), or when someone runs hosty backup:create. Each backup has a full dump and a partial one. The partial dump has the structure of all tables, but no data of the tables listed in excludeTablesFromImportOnDevEnvs in hosty.yaml. A development environment imports the latest partial dump.
- Files. A development environment gets the files of each persistent storage from the latest backup of production, without the files excluded by syncArgsForDevEnvs of the storage, i.e. image styles.
You decide what development environments get. List in excludeTablesFromImportOnDevEnvs all tables with personal data, such as users, orders and submissions, and also caches, logs and other tables that make the import slower without being of any use. See Project configuration.
The data is imported only on the first deployment. After that, the data belongs to the environment, and later deployments only update the code. To get fresh data, delete the environment and deploy it again.
If the project has no partial backup yet, i.e. right after it moved to Hosty, a new development environment starts with an empty database. With partial backups turned off (backup.partial: false in hosty.yaml), development environments can't be created at all.
Creating and updating an environment
Creating an environment and updating it are the same steps, which CI runs on each push to a branch:
- Build the code. Install the dependencies and build the assets, i.e. composer install and npm run build, in CI or in the build hook of the application (hooks.build in hosty.yaml). Keep files the site doesn't need out of the folder of the application, such as caches and user content: they make every deployment slower.
- Build and push the images. Hosty CLI puts the code into images and pushes them to the repository of the project on Hosty. It builds only what changed since the last build, by the last commit of the code, so commit everything first.
hosty build --push stage- Deploy. Hosty CLI creates the environment, or updates it if it exists. The first deployment imports the data and takes a few minutes, longer for a large database.
hosty deploy stage- Run the post-deployment commands, i.e. database updates and cache clears:
hosty exec stage --command="drush deploy"For long commands, use hosty run stage -- drush deploy instead: it goes on even if the connection drops (see Using Hosty CLI).
- Open the environment. CI can print its domains with hosty domains stage.
Only release managers, that is CI, build and deploy. See CI/CD configuration for a full example.
Deleting an environment
hosty delete stageThe environment is deleted with its database and files, for good. If you want to create it again with the same name, give it a few minutes first.
Production can't be deleted with Hosty CLI. Ask the admins if you really need it.
Cleaning up old environments
Hosty doesn't delete development environments on its own: an environment lives until someone deletes it, and uses the resources of the cluster all that time. Delete the environments you no longer need.
If you name environments after branches, let CI do it. Run a scheduled job, i.e. every night, that deletes the environments whose branches are gone:
# Branches, with the names turned into environment names.
git branch --list --remotes | grep -v 'origin/HEAD' \
| sed -E -e 's|^ *origin/||' -e 's/[^[:alnum:]]+/-/g' -e 's/^-+|-+$//g' \
| tr '[:upper:]' '[:lower:]' | sort > branches.txt
# Environments, without production. "hosty ls" prints the names on its last
# line, or a message when there are none.
hosty ls > ls.txt
grep -q 'does not have any releases' ls.txt && exit 0
tail -n 1 ls.txt | tr -d '\r' | tr ' ' '\n' | grep -vx 'production' | sort > environments.txt
# Delete the environments that have no branch.
for environment in $(comm -13 branches.txt environments.txt); do
hosty delete "$environment" --yes
doneMake sure the branch names turn into environment names the same way as in the job that deploys them.