lab-7-render-logo

Render

Render is a cloud platform as a service supporting several programming languages. Render is one of the few multi-language platforms which can host application servers for free without a credit card!

We shall set up render to auto deploy our application using git. First you need to fork the template repository into your github account. Start by following the link below.

Open proejct starter repo

Make sure you're logged into github then click the "Use this template" button.

lab-7-use-template

Provide repository name then click on the "Create repository from template" button

lab-7-create-repo

Next sign into render with your desired auth provider. It's preferred if you use GitHub since we'd be asking render to deploy our repository, but, this can be configured in the account if you prefer to sign in with another provider.

lab-7-login-render

Now create a new web service.

lab-7-create-service-menu

lab-7-create-webservice

Search for your newly created repository. Then scroll down to the advanced options.

lab-7-advanced-options

Add the following environment variables so the flask application can be configured accordingly.

lab-7-env-vars

Ensure the start command is set to fastapi run --host 0.0.0.0 --port 10000

lab-7-start-command

Finally create your web service.

lab-7-create-webservice-btn

After the web service is created, render would attempt to clone the code then run the build and launch commands specified in the previous step.

lab-7-deploy-snapshot

After it has completed you can then open your application at the url given.

The application currently uses an sqlite database however the files of the application are destroyed when it goes to sleep so the data will not persist between sessions.

You can create a postgres database on render, but, we need to update our application to connect to postgres first!

Update pyproject.toml and add ensure "psycopg2-binary" is included in the list, if not, add it. lab-7-psycopg-dep

THen continue as below lab-7-postgres

Give it a name then create the database.

lab-7-postgres-create-db

After it is created you can copy your database url.

lab-7-copy-db-url

Then navigate to your web service from the dashboard. slab-7-postgres-webservice

Then to the environment settings of your web service and update your database url environment variable to the previously copied url.

lab-7-env-var-update-postgres

This should trigger a new build. lab-7-rebuild-after-envvarupdate

Now that your repository is deployed you may try adding to the codebase and deploying new features. First clone your repository.

Creating a branch

In VSCode editor environments you can create a branch by clicking the branch icon on the bottom left.

lab-7-vscode-branch-icon

Then clicking create new branch and entering a branch name.

lab-7-vscode-newbranch

You should see that you are now working on the newly created local branch.

lab-7-newbranch

When making a change to the code you can navigate to the source control view as shown below, stage your changes and create a commit with a commit message.

lab-7-vscode-scourcecontrol

Then click on publish branch to push your changes to the repo.

lab-7-publish-branch

Making a pull Request

Now navigate to your repo on github.com. You can then switch to your newly created branch.

lab-7-branch-list

Then open a pull request. lab-7-open-pr

Give a meaningful name to your pull request. lab-7-pr-detail

Then finalize the creation. At this point another team member would review the changes of your pull request and decide to merge your branch with the main branch.

After the merge is completed render would auto deploy the new changes which you will be able to test in production.

And that's how you can deploy a fastapi application on render and manage new contributions using source control.

Change the menu item that says "Users" to "Todos" and implement the functionality to load the user todos

Complete the UI for the Todos endpoint.