Deploying a Python app isn’t as simple as uploading and installing PHP apps such as WordPress. WordPress is installed on a server and database, but with Python you need to supply all that yourself. I have done much of the development on CodeAnywhere which can provide a container, a virtual computer which is fired up when you want to use it which is suitable for testing purposes. Flask creates a very lightweight web server but it isn’t suitable for production use, so a more robust solution needs to be found.
As already mentioned the developer needs to organise a rented virtual computer with server software and a database. I have set up a database on MongoDB provider MLab instead of installing MongoDB on the development container, as then I don’t have to change anything when deploying to a publicly accessible URL. A traditional web server is online 100% of the time and processes HTTP requests as they come in, some of which will time out (Jones, 2018). Plus it is a long process to set up a server from scratch.
Serverless
Many web apps can now be deployed using third-party services and “custom code run on ephemeral containers” (Maruti Techlabs, 2017) such as Amazon Web Services’ Lambda. Zappa is a tool that makes it easy to run Python web apps on Lambda. From the documentation:
“With Zappa, each request is given its own virtual HTTP “server” by Amazon API Gateway. AWS handles the horizontal scaling automatically, so no requests ever time out. Each request then calls your application from a memory cache in AWS Lambda and returns the response via Python’s WSGI interface. After your app returns, the “server” dies.” (Jones, 2018)
CianTube is already using a third-party database and the YouTube API so it is a good candidate for using Lambda to serve the core app.
I cloned the app from GitHub and installed it on my Mac as I needed to install the AWS credentials on the machine that the app is running on locally and I couldn’t do that on the CodeAnywhere container. Zappa needs to be installed in a Virtual Environment, which isolates the app from the rest of the system so it can’t do any damage if anything goes wrong. Once this is done, the terminal command zappa init sets up the deployment settings, including defining one or more stages so you can run an app on the web without exposing it to users before it is properly tested.
To deploy the app the command zappa deploy stagename is used, which packages and uploads the local files, and when complete the URL of the app is displayed. To update, the command zappa update production is used.
I did this and the app worked on the web without a problem.
References
Maruti Techlabs. (2017). What is Serverless Architecture? What are its criticisms and drawbacks?. [online] Available at: https://medium.com/@MarutiTech/what-is-serverless-architecture-what-are-its-criticisms-and-drawbacks-928659f9899a [Accessed 24 Apr. 2018].
Jones, R. (2018). Miserlou/Zappa. [online] Available at: https://github.com/Miserlou/Zappa#about [Accessed 24 Apr. 2018].