Devops Exercise
I was asked to complete a devops exercise recently and I wanted to run it through with some additional information too.
You can find the source code here: https://gitlab.com/surdaft/devops-exercise
You can find the website here: https://devops-exercise.jackstupple.uk
The criteria of the exercise is to demonstrate a reasonable understanding of; CI/CD pipelines, terraform and an understanding of development practices. Gitlab was mentioned as an example of the pipeline service to use, I use gitlab anyway and so that was an obvious choice.
The application
I decided to build an application that was convenient for me to produce, I learned a little on the way, but there were no major blockers. I am pretty fluent with the twitch API and oauth practices, so I wrote a basic twitch integration that pulls down the top streams.
The frontend is powered by ReactJS, Vite and TypeScript. I am pretty fluent with React, Vite is new for me though. It was interesting working with it, I have since tried using NextJS and if I were to redo this example I think I would opt for that instead.
CI/CD
The CI/CD pipeline involved uses the docker image I created which has 2 steps; the build step, the serve step. Gitlab doesn't care about serve, but what it does is push this to the registry for folks to use. We extract the compiled assets and store as a tar.gz, terraform uses this as a poor mans way of grabbing the assets.
Terraform
Terraform handles the servers. I asked terraform to create a basic EC2 instance, which lives within a VPC and has a static IP address. This EC2 is provisioned by a bash script that does an nginx install (same as the serve from the docker container) and then pulls the compressed, compiled, assets from gitlab and plonks them in the nginx default serve directory.
Why did you choose EC2?
I felt as though the free tier for an EC2 server was sufficient for what I needed, also Fargate does not have a free tier as far as I am aware. Though Fargate would be a fantastic choice for serving the registry built docker image, avoiding the compressed assets situation.
Why do you have an elastic IP?
I have my website pointing to the server, so I can't have it moving around. https://devops-exercise.jackstupple.uk needs a consistent place to send users.
How does it have SSL? You did not configure that.
I use cloudflare SSL for my services, so cloudflare will produce an SSL for my website and then we communicate between each other on port 80, or with a private SSL key for other projects.
Why did you choose vite/react?
I like to use a frontend framework to make state based webpages convenient to build, I was aware of vite and thought I would play with it.
Why did you use typescript?
I like a good strict typed language, whilst it doesn't fully prevent bugs I feel that it expresses the purpose of functions much better. This is the first time using it with React and so the props and state were new to me, however hooks do not have this issue and I really should learn more about how they work.
If you could have an optimal deploy strategy what would it be?
I would optimally use a debian repository to host my packages, the gitlab pipeline would compile everything and create the deb file. Then push it to a repo. The other side of the pipeline would then be executed to trigger an update on the server, to pull down the new assets.
I would also implement jest tests into the pipeline to ensure that everything is looking healthy.
You do realise that once your server is started, it will never update the assets?
Yes, I know. That is a pickle that I was aware of but due to time constraints I felt it was fine to deploy the server once, at the end, and have no expectations to update.
Member discussion