Introduction

In this tutorial we will cover:

  • Hosting an API on render.
  • Using Github actions to run our tests prior to deploying to render.

Prerequisites:

  • Github account & how to push code to it
  • Render account (this can be a free account)
  • Pipenv

The API being hosted

For this tutorial I will be using a example fastapi API written with Python 3.13.0.

Feel free to fork from the tutorial-start branch if you wish to follow along.

If you wish to use your own API the general steps will be the same but make sure that both Render and Github Actions have support for it.

The project is a simple API that outputs Hello World and has 3 commands:

  • pipenv run dev to run the API locally for development
  • pipenv run prod to run the API in production context e.g when hosted on Render
  • pipenv run test to run the tests for the API.

Hosting an API on render

  1. On your Render dashboard create a new Web Service.

  2. Select your newly created Github project. You will need to setup a connection to Github for Render via this guide.

  3. Update the configuration for your programming language version to match the version of your project.

    For Python we need to set the PYTHON_VERSION to3.13.0 using an Environment Variable.

  4. Update the Build Command which will install our project dependencies on Render.

    For this project it will be pipenv install. We do not required the dev dependencies here as tests will be run on Github Actions.

  5. Update the Start Command which will be run to start up our API on render.

    For this project it will be pipenv run prod

  6. After the deployment is complete visit url for the website to see Hello World.

With the current setup as we push new changes to Github it will trigger deployments to Render automatically via deploy hooks.

Try updating the message to {"message": "Hello World Again!"} in main.py and push to Github to see this in effect.

Using Github actions to run our tests prior to deploying to render

Now we have our tests we can run use Github Actions to run our tests and only deploy to render if they pass.

  1. Disable the current auto-deploy on Render by setting "Auto Deploy" to "No" in the settings of your Render project.

  2. Add Github Actions script to the project at github/workflows/ci.yml.

    This script has two stages:

    • test: this will install the dependencies for running your tests and run them
    • deploy: this will deploy your code (if on main) to render

    Github Actions yml

    You should see your tests execute fine but it fails to deploy. This is because we still need to add the RENDER_DEPLOY_HOOK_URL.

Failed Github Actions

  1. Add RENDER_DEPLOY_HOOK_URL to the secrets for Github actions

    In the setting of your Render project find the Deploy Hook.

    Copy the value of this as a new repository secret for Github Actions, this is found at Settings -> Secrets and variables -> Actions.

  2. Try updating the message to {"message": "Hello World Again with Github Actions!"} but before pushing make sure your tests pass locally via pipenv run test.

    Passing Github Actions

Conclusion

Congratulations you have now successfully setup a CI/CD pipeline via Github Actions deploying to Render.

Completed Github Project

Live url - As this is hosted via the free version of Render it may require a minute to startup if it has been idle.