My First Project - Part 3
My first deployment
The project
As mentioned in My introduction, my first project using Python was a gaming website for a massively-multiplayer online role-play game (MMORPG). I had started a corporation in-game (a player group/guild) and was keen on providing the other members with some out-of-game tools that other larger groups did. The game developers (CCP Games) have a host of information that players can access from the game server through various API requests, some require authentication, some you can just grab. It was this sort of information that I wanted to be able to conveniently supply to my corporation members.
This series describes the journey from this initial idea to the deployment of my first full Python application.
- Part 1 - My first steps
- Part 2 - My first tutorial
- Part 3 - My first deployment (this post)
Deployment
By the time that I reached Chapter 17 of Miguel’s tutorial, I had two applications ready to go: the tutorial application, and my own website application. There was no point trying to deploy both so, despite my earlier issues trying to do my own thing first, I decided to just stick with my website application for deployment. By this point, I reasoned, I was familiar enough with the similarities between the two and knew how they were linked together.
I had chosen to deploy my website via Digital Ocean (I wasn’t going to go with a Microsoft, Amazon or Google version) as they seemed like they had an excellent set of features and capabilities, plus the price was low too. Win, win. I’ll go over this at a future date maybe, but Digital Ocean also have a TON of useful guides for working with their services covering many different combinations of programming languages, database and web server types, and various versions of each.
This next new trick to learn, ssh-ing in to a remote server, was a lot of fun. Not going to lie, it felt pretty cool! Setting up the server as per the tutorial instructions was definitely a case of me having to follow blindly. I vaguely understood some of the concepts (setting up the firewall and closing certain ports, for example) but a large amount was a huge learning experience. For example, setting up the server so that the root user cannot login with a password was a new concept, but actually something that I took to my personal PC: setting up a separate administrator account that wasn’t my main login.
Linux
Before this point my only interaction with Linux was installing a lightweight version on to an old laptop to breathe some life into it before it passed. That process didn’t involve any terminal work or complex configuration, so I was (again) on completely new ground. Thankfully, since there’s so many different sites and tutorials, there’s a wealth of information and guides out there. I’ve never been stuck for long wondering what a command or an option means with all the help that’s out there.
Navigating around the various directories and learning how the operating system is organised was actually a lot of fun, and something I still enjoy doing today. I’ve learnt a lot about how and where things should be stored but I’m still getting my head around access authorisations for each and how to properly assign these to users (not that I’m sharing the servers with anyone just now)
Having said that, getting used to how the programs operate, how they are monitored and how to control them is something else that I am learning. It’s getting easier now that I’ve changed my laptop (not desktop, yet…) to using Fedora, but doing that from the command line, whilst excellent fun, still take a bit to get my head around sometimes.
Stumbling steps
A few small things kept tripping me up, GitHub was one example as it was now being used on a different terminal and I had to use the application token, rather than the normal sign on.
The other major one was moving to the production web server, rather than Flask’s built-in development one. This didn’t cause too many issues that weren’t just silly mistakes, mainly due to the well structured and detailed instructions in Chapter 17. One of the other big learnings that I took away from this tutorial was how to interact and configure with the nginx web server. There’s a lot involved in setting this up (particularly whilst still following along blindly), and I was very conscious that there was also a large security risk involved with this part. I’m not saying that there was a wealth of valuable information for some enterprising hacker to get their hands on, but I didn’t want to go through this whole process only to find that it could be easily destroyed without me knowing what happened!
Database
Setting up the MySQL database on the remote server also proved troublesome. I had to destroy and redo it a couple of times by getting stuck, locking myself out, or hitting an error that I didn’t understand. Up until this point, even though the tutorial was a few years old (Miguel has done an awesome job at updating it though), I hadn’t encountered any issues due to changes or updates in applications. However, whilst setting up the database, I did struggle to get the user access working.
In the end, after much Google-fu, I managed to work out that MySQL now used the same credentials as the operating system, so the access issues I was facing wasn’t that I had done something wrong (this time…), but rather that access was already granted, I just didn’t know it.
Once the database was set up and configured however, the creation of a new database and the tables required by the application was handled flawlessly by the Flask-Migrate package. I encountered a few wee errors here and there due to some compatibility between SQLite and MySQL (data types and lengths were a big one), but that was the sort of thing that even I was able to handle.
Launch day
It was a few years ago now, so I don’t quite remember the timeline of events, but I’m fairly certain that the weekend that I aimed to deploy the initial version didn’t pan out. Due to [insert large number of errors here] errors and other setbacks I had to reset my progress a few times and ended up stretching the deployment and launch over a couple of weekends.
I do remember when it actually went live though, there was legitimately a champagne celebration to mark the occasion! It was a long journey, both in terms of time taken and learning required, to get to this point, so I felt that it was definitely deserved.
As this was for my Eve Online corporation, I eagerly posted the good news to our corporation’s Discord server and let them know the good news!
I kid you not, within 2 minutes, I got someone message me saying they broke the website. And, they did indeed. You can assign a character biography in-game to give a history and flavour to your character and, I had thought I had allowed enough space in the database to incorporate this information, but apparently not. So, when the first or second person who logged in happened to have a description longer than I had allowed, the database rejected it and threw up an error!
Closing
Since the initial release of the application, I’ve improved it heavily (I might talk about refactoring in a future article!) and looking back over the initial release code for writing this series, I almost cringe as some parts. I say ‘almost’ because I’m actually very pleased with where I started and how it’s evolved since then.
This project was very important to me, not just because it was my first foray in to Python, but because this was something that I had always wanted to do and has fascinated me for a long time. It was also the first (giant!) step on to this pathway and has had some legitimately life altering effects since.
Lesson learned
There’s always a simpler answer
Honestly, this is one of the biggest lessons I’ve learned over the few years doing this. Starting from a complete beginner meant that a lot of my Google searches were not as refined as they should be, and I kept getting answers FAR more complex than I needed. I realise that a lot of the time complexity is part and parcel of the process, and that complexity is also largely experienced based too. Having said that, more beginner orientated projects usually only require beginner levels of complexity as well.
I’m still an amateur at all this, so I’m sure that this is probably more of an personal opinion, rather than a transferable lesson!