logo
eng-flag

Heroku Cheatsheet

Table of Contents

  1. Introduction to Heroku
  2. Heroku CLI
  3. Apps
  4. Deployment
  5. Configuration
  6. Scaling
  7. Add-ons
  8. Logging and Monitoring
  9. Databases
  10. Custom Domains
  11. Collaborating
  12. Pipelines
  13. Heroku CI
  14. Best Practices

Introduction to Heroku

Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud. It supports several programming languages including Ruby, Java, Node.js, Scala, Clojure, Python, PHP, and Go.

Key Benefits:

  • Easy deployment
  • Scalability
  • Managed platform
  • Add-on ecosystem
  • Developer-friendly

Heroku CLI

The Heroku Command Line Interface (CLI) makes it easy to create and manage your Heroku apps directly from the terminal.

  1. Installation: Follow the instructions at: https://devcenter.heroku.com/articles/heroku-cli

  2. Login to Heroku:

    heroku login
    
  3. Basic Command Structure:

    heroku <command> <options>
    
  4. Get Help:

    heroku help
    heroku help <command>
    

Apps

  1. Create a New App:

    heroku create my-app-name
    
  2. List Your Apps:

    heroku apps
    
  3. Get App Info:

    heroku apps:info --app my-app-name
    
  4. Rename an App:

    heroku apps:rename new-name --app old-name
    
  5. Delete an App:

    heroku apps:destroy --app my-app-name --confirm my-app-name
    

Deployment

  1. Deploy with Git:

    git push heroku main
    
  2. Deploy from a Specific Branch:

    git push heroku feature-branch:main
    
  3. Deploy a Specific Commit:

    git push heroku <commit-hash>:main
    
  4. Set the Buildpack:

    heroku buildpacks:set heroku/nodejs
    
  5. View Build Logs:

    heroku builds:info
    

Configuration

  1. Set Config Vars:

    heroku config:set KEY=value
    
  2. Get Config Vars:

    heroku config
    
  3. Remove a Config Var:

    heroku config:unset KEY
    
  4. Set Multiple Config Vars:

    heroku config:set KEY1=value1 KEY2=value2
    

Scaling

  1. Scale Dynos:

    heroku ps:scale web=2 worker=1
    
  2. View Current Dyno Formation:

    heroku ps
    
  3. Restart All Dynos:

    heroku ps:restart
    
  4. Stop All Dynos:

    heroku ps:scale web=0 worker=0
    

Add-ons

  1. List Available Add-ons:

    heroku addons:services
    
  2. Add an Add-on:

    heroku addons:create heroku-postgresql:hobby-dev
    
  3. List Installed Add-ons:

    heroku addons
    
  4. Remove an Add-on:

    heroku addons:destroy heroku-postgresql
    

Logging and Monitoring

  1. View Logs:

    heroku logs
    
  2. Tail Logs:

    heroku logs --tail
    
  3. View Specific Number of Log Lines:

    heroku logs -n 200
    
  4. View Application Metrics:

    heroku metrics
    

Databases

  1. Create a PostgreSQL Database:

    heroku addons:create heroku-postgresql:hobby-dev
    
  2. Connect to PostgreSQL:

    heroku pg:psql
    
  3. Run a Database Backup:

    heroku pg:backups:capture
    
  4. Download Latest Backup:

    heroku pg:backups:download
    

Custom Domains

  1. Add a Custom Domain:

    heroku domains:add www.example.com
    
  2. List Domains:

    heroku domains
    
  3. Remove a Domain:

    heroku domains:remove www.example.com
    
  4. Add SSL Certificate:

    heroku certs:add server.crt server.key
    

Collaborating

  1. Add a Collaborator:

    heroku access:add user@example.com
    
  2. List Collaborators:

    heroku access
    
  3. Remove a Collaborator:

    heroku access:remove user@example.com
    

Pipelines

  1. Create a Pipeline:

    heroku pipelines:create my-pipeline
    
  2. Add an App to a Pipeline:

    heroku pipelines:add my-pipeline --app my-app --stage production
    
  3. Promote an App:

    heroku pipelines:promote --app my-staging-app
    
  4. View Pipeline:

    heroku pipelines:info my-pipeline
    

Heroku CI

  1. Enable Heroku CI:

    heroku ci:enable --app my-app
    
  2. Run CI:

    heroku ci:run --app my-app
    
  3. View CI Results:

    heroku ci:info --app my-app
    

Best Practices

  1. Use Environment Variables for Configuration Store configuration in environment variables, not in your code.

  2. Implement Proper Logging Use Heroku's logging system to diagnose issues and monitor your app.

  3. Scale Your App Appropriately Use Heroku's scaling features to handle traffic efficiently.

  4. Use Buildpacks Wisely Choose the right buildpacks for your application stack.

  5. Utilize Add-ons Take advantage of Heroku's add-on ecosystem for additional functionality.

  6. Implement Continuous Integration/Continuous Deployment (CI/CD) Use Heroku Pipelines and Heroku CI for streamlined deployment processes.

  7. Regular Backups Regularly backup your databases and other important data.

  8. Monitor Application Performance Use Heroku's metrics and New Relic add-on to monitor your app's performance.

  9. Optimize for Ephemerality Design your app to work with Heroku's ephemeral filesystem.

  10. Keep Your Dependencies Updated Regularly update your application's dependencies to ensure security and performance.

2024 © All rights reserved - buraxta.com