Tutorial: GitHub Actions deploys

Last updated 2 min read
Report issue

Overview#

This document provides a comprehensive guide on setting up GitHub Actions to automate the deployment of applications to GritivaCore. The goal is to ensure that every push to the main branch triggers a CI/CD pipeline that builds and deploys the application within five minutes.

Prerequisites#

Before you begin, ensure you have the following:

  • A GitHub repository.
  • Access to GritivaCore with permissions to create a service account and generate tokens.

Setting Up GitHub Actions#

Follow these steps to configure your GitHub Actions workflow for deployment.

Creating a Workflow#

  1. Create a service-account user in GritivaCore and generate a token with the operator role.
  2. Add the token to your GitHub repository:
    • Navigate to SettingsSecretsNew Secret and name it GRITIVA_TOKEN.

Configuring Deployment Steps#

Create a file named .github/workflows/deploy.yml in your repository with the following content:

YAML
name: Deploy
on: { push: { branches: [main] } }
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build image
        run: docker build -t myorg/myapp:${{ github.sha }} .
      - name: Push image
        run: docker push myorg/myapp:${{ github.sha }}
      - name: Deploy via Gritiva API
        env:
          GRITIVA_TOKEN: ${{ secrets.GRITIVA_TOKEN }}
        run: |
          curl -X POST https://api.gritiva.com/v1/scopes/prod/exec \
            -H "Authorization: Bearer $GRITIVA_TOKEN" \
            -d '{"command":"docker compose pull && docker compose up -d"}'
  1. Test the setup by pushing a commit to the main branch and tailing the logs in the GritivaCore panel.

Common Deployment Scenarios#

  • Deploying a new application version.
  • Rolling back to a previous version using the command:
    BASH

gritivactl scope exec prod -- docker compose pull && up -d

TEXT
- Handling environment-specific configurations.

## Troubleshooting

If you encounter issues during deployment, consider the following:
- Ensure the `GRITIVA_TOKEN` is correctly set in GitHub Secrets.
- Check the logs for any errors during the build or deployment steps.

## Conclusion

By following this guide, you can successfully set up GitHub Actions to automate your deployment process to GritivaCore, ensuring efficient and reliable application updates.

Best Practices

Best Practices
Consider the following best practices for your GitHub Actions workflows: - Use per-environment tokens and revoke leaked tokens promptly. - Avoid using `:latest` tags; prefer image digests for stability. - Implement pre-build health checks to ensure application readiness.

Further Reading

Further Reading
For deeper insights into GitHub Actions, refer to the [GitHub Actions documentation](https://docs.github.com/en/actions).