nsindocs Search the docs⌘K
  1. Docs
  2. NSIN CLOUD

GitOps

Describe your NSIN CLOUD apps and databases in one git repository. Every push is applied.

On this page

GitOps lets you describe your NSIN CLOUD apps and databases in one git repository. You edit a file, commit and push. NSIN CLOUD applies the change within about a minute.

The repository holds no application code. It only says what should exist: one file per app, one file per database. Once it is linked, the repository is the source of truth for everything it declares.

Repo layout

text
apps/shop.yaml                       the app "shop"
apps/api.yaml                        the app "api"
databases/shop-db.yaml               the database "shop-db"
settings.yaml                        optional, reserved
projects/dev/apps/example.yaml       the app "example" in the project "dev"
projects/dev/databases/dev-db.yaml   the database "dev-db" in the project "dev"
  • The root apps/ and databases/ are your default project.
  • projects/<name>/ is the project called <name>, with its own apps/ and databases/. If you don't have that project yet, the first sync creates it.
  • A project folder name uses lowercase letters, digits and dashes, and starts with a letter. A folder with another name is reported and skipped.
  • Names are unique per project. apps/api.yaml and projects/dev/apps/api.yaml are two different apps.
  • Only .yaml and .yml files directly inside apps/ and databases/ are read. Other files, sub-folders and dot-files are ignored, so a README is fine.
  • The name: inside a file is what counts, not the file name.

settings.yaml is optional and reserved for later. Its keys are read and ignored today.

Get started

  1. Open the GitOps page in the panel.
  2. Click Generate from my apps. It writes one file per app and per database from what you already run, in every project. Check them, then click Download zip.
  3. Create an empty repository on GitHub or GitLab. Private is fine. Don't add a README or a licence.
  4. Unzip the download and push it:
    bash
    git init -b main
    git add . && git commit -m "my infrastructure"
    git remote add origin https://github.com/you/infra.git
    git push -u origin main
  5. Back on the GitOps page, paste the repository's URL and branch. For a private repository add a token. For an ssh URL, pick one of your deploy keys instead. Click Link a repo.

Linking runs the first sync. If an app or database in a file already exists in that project with the same name, the sync takes it over. It does not create a second one.

NSIN CLOUD only reads the repository. It never writes to it.

App file

An app file is one source: block plus the app's settings.

yaml
# apps/shop.yaml
source:
  git_url: https://github.com/acme/shop.git
  branch: main
  token_ref: infra          # clone with the infra repo's own token
name: shop
build:
  dockerfile: ./Dockerfile  # or `auto: true`
  context: .
run:
  port: 3000
  replicas: 1
  start_command: node server.js   # optional; replaces the image CMD
  pre_deploy: npm run migrate     # optional; runs once per deploy, before the rollout
  resources: {cpu: "500m", memory: "512Mi"}
  healthcheck: {path: /healthz}
env:
  NODE_ENV: production
  DATABASE_URL: {from: database, name: shop-db, key: DATABASE_URL}
  STRIPE_KEY: {secret: true}   # value set in the panel, never in git
volumes:
  - {path: /data, size: 1Gi}
domains: [shop.ali.ir]

An app from a ready image needs no build::

yaml
# apps/api.yaml
source:
  image: ghcr.io/acme/api:1.4
name: api
run:
  port: 8080
  replicas: 2
env:
  DATABASE_URL: {from: database, name: shop-db, key: DATABASE_URL}

source

Required. Set git_url or image, not both.

KeyWhat it does
git_urlThe app's code repository, http or https. An ssh URL needs deploy_key.
branchThe branch to build. Only with git_url.
token_refThe only value is infra: clone this repository with the infra repo's own token. Only with git_url.
deploy_keyThe name of one of your deploy keys, for an ssh git_url. Use it or token_ref, not both.
imageA ready container image, like ghcr.io/acme/api:1.4.

Everything else

KeyWhat it doesDefault
nameRequired. The app's name: lowercase letters, digits and -, starting with a letter, at most 63 characters.—
build.dockerfilePath to the Dockerfile.found for you
build.autotrue builds without a Dockerfile. Use it or dockerfile, not both.false
build.contextThe build folder..
run.portRequired. The port your app listens on, 1–65535.—
run.replicasHow many copies run. 0 keeps the app stopped.1
run.resources.cpuCPU per copy, like "500m" or "1".500m
run.resources.memoryMemory per copy, like 512Mi.512Mi
run.healthcheck.pathHealth check path. Starts with /.none
run.start_commandThe line the app starts with. Replaces the image's CMD.none
run.pre_deployA line run once per deploy, before the rollout. For example, a migration.none
run.commandThe container's entrypoint, as a list: [node, server.js].the image's
run.nodeThe server a new app is created on. Use it or cluster, not both.chosen for you
run.clusterThe cluster a new app is created in.chosen for you
run.sandboxedtrue runs the app in a sandbox. false turns it off.left as it is
envEnvironment variables. See env.none
databasesDatabases this file declares, written the same way as a database file. See Database file.none
volumesDisks: {path: /data, size: 1Gi}. path is absolute. A bigger size grows the disk. A disk never shrinks.size 2Gi
domainsYour own hostnames, lowercase: [shop.ali.ir].none
portsExtra ports: {port: 5432, protocol: tcp, public: true}. protocol is tcp or udp.tcp
free_hostnamefalse turns off the app's free address. true turns it back on.left as it is

Your account's CPU, memory and disk limits apply. A file over them is refused with a clear message.

The file is a mirror of the app. If you leave out start_command or pre_deploy, the sync clears it. If you leave out sandboxed or free_hostname, the sync leaves that setting alone.

node and cluster are used only when the app is created. Changing them later gives a warning. The app does not move.

env

Each variable takes one of these forms:

FormMeaning
NODE_ENV: productionA plain value.
STRIPE_KEY: {secret: true}A secret. The value is set in the panel and never goes in git. See Secrets.
DATABASE_URL: {from: database, name: shop-db, key: DATABASE_URL}A value from a database in the same project.
APP_VERSION: {value: "1.4.2", build: true}A plain value with a scope.

Scope says where the value goes:

  • build: true also hands it to the image build, for example as a Dockerfile ARG. Default false.
  • runtime: false keeps it out of the running app. Default true.
  • NPM_TOKEN: {secret: true, build: true, runtime: false} is used by the build only.

Names match [A-Z_][A-Z0-9_]*. PORT and names starting with NSINCLOUD_ are reserved.

A {from: database} only reaches a database of the same project.

Database file

yaml
# databases/shop-db.yaml
name: shop-db
engine: postgres
version: "16"
size: 2Gi
KeyWhat it doesDefault
nameRequired. Same rules as an app name.—
engineRequired. One of postgres, pgvector, mysql, mariadb, redis, mongodb, minio, clickhouse, elasticsearch, meilisearch.—
versionThe engine version, as a string: "16".the engine's default
sizeDisk size.2Gi
classstandard or managed. Managed is for postgres, pgvector, mysql and mongodb.standard
hatrue for high availability. Implies managed.false
cpu, memoryThe size of a Standard database. Not allowed with managed.the engine's own

Every database key is used only when the database is created. A sync never changes a database that exists. If the file differs, the card shows a warning and the database stays as it is.

Pushes and syncs

NSIN CLOUD checks every linked repository for a new commit about once a minute, and syncs it. You can also click Sync now on the repository's card at any time.

A sync creates what is new, updates what changed, and deploys only the apps whose settings changed. A change to the source, Dockerfile or build folder rebuilds the app. A port, domain or env change does not.

Errors on the card

The repository's card lists every problem of the last sync, each with its file, like apps/shop.yaml: run.port: is required.

  • A file that doesn't read or is invalid: nothing at all is applied. This includes two files that declare the same app or database in one project.
  • A project folder with a bad name: that folder is skipped and the rest is applied. Nothing is deleted in that sync.
  • A file that can't be applied (for example, the account's balance is below zero, so a new app is skipped): that file is reported and the rest is applied.

If the card shows Cannot read repo, NSIN CLOUD can't reach the repository, so new pushes are not picked up. Check that the token still works and the URL and branch are right, then click Sync now. If the token changed, unlink and link the repository again with the new token.

Fix the file and push again. A failing commit is tried only once on its own, so to retry the same commit click Sync now.

Deleting things

A push never deletes data by accident. When a push would delete any of these, the sync holds it back:

  • an app whose file was removed
  • a database whose file was removed
  • a volume
  • a secret that holds a value

Everything else in that push is applied. The card turns blocked and shows the exact plan it held. To allow it, do one of these:

  • Click Allow destructive on the card.
  • Put [nsincloud: allow-destructive] in the commit message and push again.
bash
git commit -m "remove the old api [nsincloud: allow-destructive]"

Allow destructive reads the repository again before it deletes anything. It never runs an old plan. Deleting an app or a database also deletes its data.

What the panel can still do

While a repository declares an app, change the app in the file, not in the panel. The panel refuses these and names the file to edit:

  • app settings, scale, rename and delete
  • environment variables (except a secret's value)
  • domains and ports
  • removing or growing a disk (to grow one, raise its size in the file and push)
  • linking a database to the app
  • deleting a database the repository declares
  • renaming a project the repository declares, or making another project the default

To delete a declared app or database, remove its file and push. To rename or change a declared project, unlink the repository first.

These still work as usual: restart, deploy, rollback, logs, terminal, metrics and backups.

Stop works until the next sync, which starts the app again. To keep it stopped, set run.replicas: 0 in the file.

If the file sets free_hostname, the free address switch in the panel is locked. Change it in the file. If the file leaves it out, the switch stays in the panel.

If an app had its own nsincloud.yaml in its code repository, the infra repo wins. That file is ignored from then on, and the sync says so.

Secrets

Secrets never go in git. Write the name with {secret: true}:

yaml
env:
  STRIPE_KEY: {secret: true}

Then set its value on the app in the panel. This is the one thing the panel can change on a declared app. A secret you already set keeps its value.

Until it has a value, every sync shows a warning. A plain value whose name looks like a credential is an error in the file: use {secret: true} for it.

Click Unlink on the repository's card. Syncing stops. Every app and database it created stays as it is and can be changed in the panel again. Nothing in your git repository is touched.

esc