Home  Github   How to depl ...

How to deploy heroku app from github

GitHub provides a service called GitHub Actions that allows you to automate workflows directly from your GitHub repository. With GitHub Actions, you can build, test, and deploy your applications directly from your repository based on triggers such as commits, pull requests, or other events.

Key Features of GitHub Actions:

  1. Workflow Automation: Define custom workflows using YAML files (workflow files) directly within your repository under the .github/workflows directory.

  2. Deployment: GitHub Actions can automate deployment processes to various platforms including cloud providers like AWS, Azure, Google Cloud, and platforms like Heroku, Firebase, Netlify, etc.

  3. Continuous Integration/Continuous Deployment (CI/CD): Set up CI/CD pipelines to automatically build, test, and deploy your code whenever changes are pushed to your repository.

  4. Community Actions: GitHub Actions has a marketplace where you can find pre-built actions contributed by the community for various tasks, which can be integrated into your workflows.

Example Use Case:

Let's outline a simple example of deploying a Node.js application to Heroku using GitHub Actions.

  1. Create Workflow File: Create a workflow file (e.g., .github/workflows/deploy.yml) in your repository.

    name: Deploy to Heroku
    
    on:
      push:
        branches:
          - main  # or your main branch name
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout Repository
            uses: actions/checkout@v2
    
          - name: Setup Node.js
            uses: actions/setup-node@v2
            with:
              node-version: '14'
    
          - name: Install Dependencies
            run: npm install
    
          - name: Login to Heroku
            env:
              HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
            run: echo "$HEROKU_API_KEY" | docker login --username=_ --password-stdin registry.heroku.com
    
          - name: Deploy to Heroku
            env:
              HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
            run: |
              heroku container:push web --app your-heroku-app-name
              heroku container:release web --app your-heroku-app-name
    
  2. Configure Secrets: Set up the HEROKU_API_KEY secret in your repository settings (Settings -> Secrets) with your Heroku API key.

  3. Commit and Push: Commit this workflow file to your repository's .github/workflows directory and push it to your main branch.

  4. Workflow Execution: GitHub Actions will automatically execute this workflow whenever you push changes to the main branch. It will install dependencies, login to Heroku using the provided API key, build your application, and deploy it to Heroku.

Published on: Jun 27, 2024, 01:33 AM  
 

Comments

Add your comment