Prerequisites

Before deploying helixml/aispec in a production environment, ensure the following prerequisites are met:

  • A configured production server with access to the required resources.
  • Proper environment variables set for Production settings.
  • Database migration scripts must be up-to-date and applied.

Step 1: Cloning the Repository

Begin by cloning the helixml/aispec repository from the version control system:

git clone https://your-version-control-system-url/helixml/aispec.git
cd aispec

Step 2: Branching for Deployment

Switch to the production branch that you intend to deploy:

git checkout production

Make sure your local copy is updated:

git pull origin production

Step 3: Environment Configuration

Set the environment configurations for production. You can use a .env file or export environment variables directly. The example below uses a .env file:

DATABASE_URL=postgres://user:password@hostname:5432/dbname
SECRET_KEY=your-production-secret-key
DEBUG=False

Make sure to adapt values according to your production settings.

Step 4: Database Migration

If there are pending migrations, ensure they are applied. Use the following command to run the migrations:

python manage.py migrate

This command updates the production database schema to the latest version according to the defined models.

Step 5: Static File Collection

Collect static files necessary for the application. This step ensures that all static resources like CSS, JavaScript, and images are available to the application in production.

python manage.py collectstatic --noinput

Verify that the collected files are present in the specified STATIC_ROOT.

Step 6: Configure the Web Server

Depending on the web server in use (e.g., Nginx, Apache), you need to configure it to serve the application. Below is a sample configuration for Nginx.

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /static/ {
        alias /path/to/static/files/;
    }
}

Restart the Nginx server to apply changes:

sudo systemctl restart nginx

Step 7: Start the Application

Use a production-ready server like Gunicorn or uWSGI to serve your application. Here’s an example using Gunicorn:

gunicorn --bind 0.0.0.0:8000 aispec.wsgi:application

Ensure the process runs in the background or is managed by a supervisor for process management.

Step 8: Monitoring and Logging

Set up monitoring for your application to track performance and errors. Integrate logging using a solution such as Sentry or configure custom logging in your settings.

Example configuration for logging in settings.py:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '/path/to/logs/aispec.log',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}

Ensure the log file is writable by the application.

Step 9: Final Verification

Once the deployment process has completed, conduct a final verification of the application. Access the application via the configured domain and check the functionality. Monitor the logs for errors and performance issues.

References