Exercises on deployment
Exercise 1 - Device information containerized and deployed
Go back to Exercise 3 - Device information from Exercises part 1 in Development Basics and deploy it to Okteto Cloud by making a:
- GitHub repository
- requirements.txt
- Dockerfile
- GitHub Actions pipeline file
At that point you should be able to have the API as a Docker container on your Docker Hub account.
From then on you can create a docker-compose.yml
file in the same repository and host the container on Okteto Cloud.
If you hadn't completed the exercise yet, this should be the contents of the .py
-file:
Details
from fastapi import FastAPI
import platform, psutil
import datetime
app = FastAPI()
@app.get("/device/platform")
async def get_platform():
return {'platform': platform.system(), 'datetime': datetime.datetime.now()}
@app.get("/device/platform/{show_version}")
async def get_platform_release(show_version: bool):
if(show_version):
return {'platform': platform.system(), 'release': platform.release(), 'version': platform.version(), 'datetime': datetime.datetime.now()}
return {'platform': platform.system(), 'release': platform.release(), 'datetime': datetime.datetime.now()}
@app.get("/device/processor")
async def get_processor():
return {'processor': platform.processor(), 'datetime': datetime.datetime.now()}
@app.get("/device/interfaces/all")
async def get_all_interfaces():
interfaces = []
# get all network interfaces (virtual and physical)
interface_addresses = psutil.net_if_addrs()
for interface_name in interface_addresses:
for address in interface_addresses[interface_name]:
if str(address.family) == 'AddressFamily.AF_INET': # only IP addresses
interface = {}
interface["interface"] = interface_name
interface["IP address"] = address.address
interface["netmask"] = address.netmask
interfaces.append(interface)
return {'interfaces': interfaces, 'datetime': datetime.datetime.now()}
@app.get("/device/interfaces/{index}")
async def get_interface_by_index(index: int):
interfaces = []
# get all network interfaces (virtual and physical)
interface_addresses = psutil.net_if_addrs()
for interface_name in interface_addresses:
for address in interface_addresses[interface_name]:
if str(address.family) == 'AddressFamily.AF_INET': # only IP addresses
interface = {}
interface["interface"] = interface_name
interface["IP address"] = address.address
interface["netmask"] = address.netmask
interfaces.append(interface)
if(index < 0 or index > len(interfaces)-1):
return {"error": "invalid index"}
return interfaces[index]
Try using the endpoints of the API to discover some information about the Okteto Cloud environment! 👀
Exercise 2 - Deploying an API container & a database
You will be deploying the following architecture to Okteto Cloud:
Two containers are involved here. Please check out the Docker Hub pages for more information on environment variables:
Create a new GitHub repository to host your docker-compose.yml
file. Try and find out through which variable you will be connecting the containers together.
To test your deployment out do the following:
- Perform a
POST
request to/books/
with the body:
{
"title" : "The Great Gatsby",
"isbn" : "ISBN1"
}
- Perform a
GET
request to/books/{ISBN}
with{ISBN}
beingISBN1
Exercise 3 - Deploying an API container & a No-SQL database
You will be deploying the following architecture to Okteto Cloud:
Two containers are involved here. Please check out the Docker Hub pages for more information on environment variables:
Create a new GitHub repository to host your docker-compose.yml
file or add to the previous one.
To test your deployment out do the following:
- Perform a
POST
request to/reviews/
with the body:
{
"userId" : 5,
"isbn" : "ISBN1",
"scoreNumber" : 4
}
- Perform a
GET
request to/reviews/user/{userId}
with{userid}
being5
Exercise 4 - Deploying a full Microservice architecture
You will be deploying the following architecture to Okteto Cloud:
Five containers are involved here. Please check out the Docker Hub pages for more information on environment variables:
- miverboven/brank-edge-service-ex
- mongo
- miverboven/review-service-ex
- mysql
- miverboven/book-info-service-ex
Create a new GitHub repository to host your docker-compose.yml
file or add to the previous one.
To test your deployment out do the following:
- Perform a
POST
request to/books/
of book-info-service-ex endpoint with the body:
{
"title" : "The Great Gatsby",
"isbn" : "ISBN1"
}
- Perform a
POST
request to/reviews/
of the review-service-ex endpoint with the body:
{
"userId" : 5,
"isbn" : "ISBN1",
"scoreNumber" : 4
}
- Perform a
GET
request torankings/user/{userId}
with{userid}
being5