Skip to content

CNC.yml

Configuration

Once generated, the YAML file can be accessed in the cnc.yml tab on your environment homepage to further customize your configuration.

  • Migrate commands: Add database migration commands, such as migrate: flask db migrate, directly under the relevant service to automate schema updates during deployment.

  • Build processes: Specify custom build/run commands to define how assets are compiled or scripts are executed during the build phase.

  • Resource and scaling management: Adjust CPU and memory limits, configure auto-scaling rules, and set up health checks to optimize performance and resilience.

Customizing Run Commands

You can customize the run commands for each service in the cnc.yml file. For example, you can add flags to a uvicorn command to specify debugging options for a staging environment.

services:
  backend:
    build:
      context: /
      dockerfile: Dockerfile
    command:
      - uvicorn
      - app.main:app
      - '--port=8080'
      - '--host=0.0.0.0'
      - '--reload'
      - '--log-level=debug'

Database Migrations

To automate database migrations during deployment, you can add migration commands to the cnc.yml file. For example, you can add a migrate command to the backend service to run Flask database migrations.

services:
  backend:
    build:
      context: /
      dockerfile: Dockerfile
    x-cnc:
      type: backend
      system:
        health_check: ''
      migrate:
        - python
        - manage.py
        - db
        - migrate

Managing Resources and Scaling

You can manage resources and scaling for each service in the cnc.yml file. For example, you can set CPU and memory limits for a service as well as the number of replicas to scale.

services:
  backend:
    deploy:
      resources:
        limits:
          cpus: 2
          memory: 2G
      replicas: 3 

Workers and Scheduled Tasks

You can define workers and scheduled tasks in the cnc.yml file to run background processes and automate tasks. For example, you can add a celery_worker service to process long-running jobs. You can also specify the number of worker replicas and CPU/Memory allocation.

services:
  backend:
    build:
      context: /
      dockerfile: Dockerfile
    x-cnc:
      workers:
        - name: celery_worker
          command: celery -A tasks worker --loglevel=info
          replicas: 3 
          system: # Optional, default to service limits if not defined
            cpus: 2
            memory: 4g

Scheduled Tasks

You can define scheduled tasks in the cnc.yml file to run periodic jobs. For example, you can add a check task statuses task to run every half hour.

      scheduled_tasks:
        - name: check task statuses
          command: ["node", "statuscheck.js"]
          schedule: "0 */30 * * * *"
          system:
            memory: 2g

Health Checks

You can define health checks in the cnc.yml file to monitor the health of your services. For example, you can add a health check endpoint for the backend service to ensure it is running correctly. Your cloud provider will expect the service to return a 200 status code.

services:
  backend:
    x-cnc:
      system:
        health_check: /health