Recitation 7: Microservices and Docker¶
Prerequisites¶
You should have downloaded Docker. If you haven't follow the installation instructions here
Setup Instructions (10 min):¶
Fork this repo and clone it. Also start the docker engine.
Overview¶
During this recitation, students will create a simple FastAPI app, containerize it and deploy it.
Context¶
Sadly, you still are unsure when your recitation time is AND who your TAs are. There exist a microservice that tells you which TA's are responsible for each section.
Try it out using this link: https://whos-my-ta.fly.dev/section_id/a
All you have to do is build a new service that builds on top of this microservice by including the time of the recitation as well.
The endpoint has to return a JSON object in the following form:
{
"section": "section_name",
"start_time": "HH:MM",
"end_time": "HH:MM",
"ta": ["taName1", "taName2"]
}
Activity¶
- Implement the
section_info
endpoint according to the specifications. You can editapp/main.py
to do so. - Test it by running the app locally. To install necessary files:
pip install -r requirements.txt
- To run the app locally use the following command. Change the port number if you need to:
uvicorn app.main:app --host 0.0.0.0 --port 8080
- Implement
./Dockerfile
. You can use the slides and this link as resources. - Create the docker image using the command below, and check that the image has been created.
docker build -t YOUR_IMAGE_NAME .
- Implement
./docker-compose.yml
. You can use the slides for reference. - Create a container using the docker image using the command below.
docker-compose up -d
- Check that your container is running correctly by locally invoking the endpoint.
You can try http://localhost:8080/section_id/a.
Change the port number (8080) according to your
docker-compose.yml
.
Bonus¶
Try deploying your container using instructions from here.