Deploy Flask App in Heroku

How I deployed Flask web app straight from GitHub to Heroku

Just today, I finished a task I've never done before - deploying a Flask web application on Heroku. As background, I'm an aspiring software developer who was given a task by the recruiter to build a web app and deploy it to Heroku. I was given three days to finish it. I was thrilled for the challenge but also felt the pressure to complete the task on time.

I spent quite a time building my web application using Flask, ensuring it met all the requirements set by the hiring manager. Eventually, the web app was complete and the developer pushed it to GitHub.

Now, it was time to deploy the app on Heroku. As mentioned, I had never done it before and was a bit nervous. But, I am thrilled to figure it out. I started reading through the Heroku documentation and I saw it only has dedicated documentation for Django. Still, I've quite understood from the reading the key elements needed to enable the deployment.

After countless trials and errors, reading, again and again, the documentation and online resources, I finally figured out the correct steps to be taken.

The first step was to create a requirements.txt file in the root folder, which listed all the dependencies for the app. In my case, I've included Flask and requests, and most importantly, gunicorn.

Flask
requests
gunicorn

Next, I created a Procfile that defined the command to run the app using gunicorn.

web:gunicorn app:app

With the Flask project folder set up on GitHub, I went to the Heroku dashboard and selected the "Deployment method" as GitHub. I then selected the GitHub project repository for the Flask web app and enabled the connection between Heroku and GitHub necessary for the deployment. I also decided to turn on automatic deployment from the master branch, so that any code changes made in the GitHub repository would automatically update the deployed app.

Finally, in the Heroku settings, I selected the build pack for Python to ensure the app could be properly built and run on Heroku.

I then deployed the app and monitored the build logs if it would succeed. After a few tense moments, the app was up and running! I was thrilled that I had successfully deployed the app, even though it had been a bit of a challenge.

I learned a lot from the experience, including how to debug the app by checking the error logs and running the Heroku CLI from the Run Console command on the platform. I also realized the importance of ensuring all dependencies were properly listed in the requirements.txt file, especially the gunicorn.

Despite the challenges, I'm very satisfied with being able to deploy the app on my own. I realized that the accomplishment gave me confidence in my abilities. Maybe this is me overreacting but I'm grateful to the recruiter who allowed me to have such a rewarding experience.