-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add a more advance usecase documentation for ServerContainer (#688
) Expanding the docs for using the ServerContainer with an example involving FastAPI container that is using Redis container.
- Loading branch information
1 parent
5216b02
commit 2cf5a9f
Showing
6 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM python:3.9 | ||
|
||
WORKDIR /app | ||
|
||
RUN pip install fastapi[standard] redis | ||
|
||
COPY ./app /app | ||
|
||
EXPOSE 80 | ||
|
||
CMD ["fastapi", "run", "main.py", "--port", "80"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This app will use redis to store given key-value pairs. | ||
|
||
import os | ||
import redis | ||
|
||
from fastapi import FastAPI | ||
|
||
|
||
app = FastAPI() | ||
|
||
redis_host = os.getenv("REDIS_HOST") | ||
redis_port = os.getenv("REDIS_PORT") | ||
redis_client = redis.Redis(host=redis_host, port=redis_port) | ||
redis_client.ping() | ||
|
||
|
||
@app.get("/") | ||
def health_check(): | ||
return {"status": "ok"} | ||
|
||
|
||
@app.get("/get/{key}") | ||
def read_item(key: str): | ||
return {key: redis_client.get(key)} | ||
|
||
|
||
@app.post("/set") | ||
def create_item(key: str, value: str): | ||
redis_client.set(key, value) | ||
return {key: value} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters