Adding a new project
A new project takes two steps. First, an admin adds it to Hosty, which prepares its place on a cluster. Then the developers deploy its code and backups, as described in Adding a new project for developers. This page covers the first step.
Before you start
- Work in the Hosty container (make cli) with an MFA session (hosty auth).
- Connect to the VPN of the cluster. OpenTofu creates resources inside the cluster, and its API is reachable only through the VPN.
- Everyone you give a role in the project must be in users in terraform/main.tf, including the user of CI. You can add them in the same change.
Choose a name
The name of the project is its key in projects. Hosty uses it everywhere: in the namespaces, IAM groups, ECR repository, database accounts and the domains of development environments. You can't rename a project later without creating it again.
- Use up to 12 characters: lowercase letters, digits and hyphens. Hosty CLI refuses a longer projectName in hosty.yaml.
- Keep it short and clear, like shop or acme-web.
Add the project to main.tf
Projects are listed in projects in the locals block of terraform/main.tf. Add a new entry:
locals {
# ...
projects = {
# ... other projects.
shop = {
# Cluster to run the project on.
cluster = "<cluster>"
# Custom domains of the project. You can add them later.
domains = ["example.com", "www.example.com"]
# People and CI, by their role in the project.
lead_developers = ["company.alice"]
developers = ["company.bob"]
release_managers = ["ci.shop"]
# Optional. Keep the database backups of this project for less time than
# database_backup_retention_days of the hosting.
# database_backup_retention_days = 30
}
}
}Option | Required | What it does |
|---|---|---|
cluster | Yes | The cluster that runs the project: cluster_name of one of the cluster modules in main.tf. |
domains | No | Custom domains of the project. They all go into one SSL certificate. Environments of the project can serve only these domains and the subdomains of <project>.<hosted zone>. A wildcard like *.example.com covers its subdomains. |
lead_developers | No | People who look after the project. They can do what developers can, and on production they also see logs, open a shell, run hosty run and hosty backup:create, and read and upload full backups. |
developers | No | People who work on development environments: logs, shell, hosty run and hosty delete. They can read partial backups of the database and the backups of files. |
release_managers | No | The user of CI. Only release managers push images and deploy, to production too. |
database_backup_retention_days | No | Days to keep the database backups of the project, if less than for the rest of the hosting. Use 1 to 30, or 120 and more: backups move to S3 Glacier Instant Retrieval after 30 days, which charges for at least 90 days there. |
All roles are optional, and a project can start with none of them. See Roles & Permissions for the details.
Give each project its own CI user, such as ci.shop. Its access keys end up in the CI of the project, so a shared user lets the CI of one project deploy another.
Apply the change
cd /src/terraform
tofu plan
tofu applyCheck the plan before you apply it: it should only add resources for the new project, and for new users if you added any.
OpenTofu creates:
Where | What |
|---|---|
IAM | Groups <project>-developers, <project>-lead-developers and <project>-release-managers, with access to the backups and the ECR repository of the project. |
ECR | Repository project-<project> for the images of the project. It keeps the 20 latest production images and deletes other images after 180 days. |
ACM | A certificate for domains, which you validate yourself (see below), and a wildcard certificate *.<project>.<hosted zone> for development environments, validated automatically. |
Route53 | *.<project>.<hosted zone>, pointing to the development load balancer of the cluster. |
Kubernetes | Namespaces <project>-production and <project>-development with Pod Security baseline, the roles of the people and CI, network policies, and admission policies for the domains and the ECR repository of the project. |
IAM roles of pods | Roles to import backups, to write backups (production only), and an empty one for the applications. |
Database | On MySQL, the accounts <project>_production and <project>_development, created by a job in the hosty-system namespace. Their passwords are in the secret hosty-database of each namespace. Hyphens in the name of the project become underscores. On PostgreSQL, each environment gets its own user on deployment instead. |
VPN | A profile <user>.<cluster>.ovpn in the bucket vpn.<hosted zone> for each person who is new on the cluster. |
Validate the custom domains
AWS issues the certificate for domains only after it finds the validation records in the DNS of those domains. Until then, Hosty CLI doesn't deploy the domains.
- Find the records in AWS Certificate Manager, in the region default_region of main.tf. Or list them with the AWS CLI:
aws acm list-certificates --region <region>
aws acm describe-certificate --region <region> --certificate-arn <arn> \
--query 'Certificate.DomainValidationOptions[].ResourceRecord'- Add each record as a CNAME in the DNS of the domain, for example in Cloudflare. Set them to "DNS only", not proxied.
- Wait until the status of the certificate is Issued. It usually takes a few minutes.
Pointing the domains themselves to the cluster is part of going live, described in Adding a custom domain. If the cluster has alb_cloudflare_only, the production load balancer accepts requests only from Cloudflare, so the domains must be proxied through it.
To add a domain later, add it to domains and apply again. The certificate is replaced, so validate the new records the same way.
Hand over to the developers
Give the lead developer of the project:
- the values for hosty.yaml: projectName (the name of the project), clusterName and clusterRegion;
- the access keys and the VPN profile of the CI user, for the secrets of CI, as described in Adding a new user.
The developers then follow Adding a new project and CI/CD configuration. Lead developers can upload the first backups. Only release managers can deploy, so the first deployment of production runs in CI.