Python: Configure the GitHub Actions workflow
This documentation is part of the Deploy with GitHub Actions guide. You can view the complete guide here: How to deploy your Python code using GitHub Actions.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Python cloud solution designed to simplify your deployments:
- Deploy your application to production in just seconds with a simple
git push.- Use your own domain name, with automatic HTTPS certificate setup for secure connections managed for you.
- Take advantage of automatic backups, one-click updates, and predictable pricing, so you can focus on your code instead of infrastructure management.
- Benefit from high performance and security on a private, dedicated infrastructure. Your environment is isolated and protected.
Save time and streamline your workflow: your code can be up and running with Stackhero's Python cloud hosting in just 5 minutes.
In your Git repository, create a directory called .github/workflows if it does not already exist. Then add a file named deploy-to-stackhero.yml inside it.
# File: .github/workflows/deploy-to-stackhero.yml
name: Deploy to Stackhero
run-name: Deploy branch "${{ github.ref_name }}" to Stackhero
on:
push:
# List of branches that will trigger the deploy action following a git push.
# Don't forget to create an environment corresponding to the branch name in GitHub (in "Settings"/"Environments").
# Then add the corresponding secret "STACKHERO_SSH_PRIVATE_KEY" and variable "STACKHERO_ENDPOINT" in this environment.
branches: [ "production", "staging" ]
jobs:
Deploy:
environment: ${{ github.ref_name }}
runs-on: ubuntu-latest
steps:
- uses: stackhero-io/github-actions-deploy-to-stackhero@v1
with:
# The secret "STACKHERO_SSH_PRIVATE_KEY" and the variable "STACKHERO_ENDPOINT" should be defined in the corresponding branch environment on GitHub under "Settings"/"Environments".
ssh_private_key: ${{ secrets.STACKHERO_SSH_PRIVATE_KEY }}
endpoint: ${{ vars.STACKHERO_ENDPOINT }}
Once you have added the workflow file, you can commit your changes:
git add -A .
git commit -m "Add GitHub Actions to deploy to Stackhero"
You can create a production branch with:
git checkout -b production
And push your changes to GitHub:
git push --set-upstream origin production
This will push your code to the production branch on GitHub and trigger GitHub Actions, which will deploy your code to your Stackhero instance.
To check your deployment status, simply go to your GitHub project page and click on Actions.
GitHub Actions that deployed to production
That's it. You now have automatic deployments to production using GitHub Actions.