diff --git a/.devops/docker-build.yml b/.devops/docker-build.yml deleted file mode 100644 index cb60bad..0000000 --- a/.devops/docker-build.yml +++ /dev/null @@ -1,62 +0,0 @@ -# Deploy to Azure Kubernetes Service -# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service -# https://docs.microsoft.com/azure/devops/pipelines/languages/docker - -trigger: - branches: - include: - - '*' - paths: - include: - - app/* - - Dockerfiles/* - - launch.sh - - pyproject.toml - - .* - -pr: - - main - - master - - develop - -resources: - - repo: self - -variables: - dockerfileRelativePath: '$(DOCKERFILE)' # Dockerfile - - # Agent VM image name for Build - vmImageNameDefault: 'ubuntu-latest' - - # Image Repository Name - imageRepository: '$(docker_image_repository_name)' - - environment: 'LAB' - dockerRegistryServiceConnection: '$(LAB_CONTAINER_REGISTRY_SERVICE_CONN)' - containerRegistry: '$(LAB_CONTAINER_REGISTRY_NAME)' - selfHostedAgentPool: $(LAB_AGENT_POOL) - -stages: - - stage: 'build_and_publish_docker' - displayName: 'build_and_pusblih_to_${{ variables.environment }}' - dependsOn: [] - jobs: - - job: build_and_publish_docker_image - displayName: build docker image - pool: - vmImage: $(vmImageNameDefault) - steps: - - task: CmdLine@2 - inputs: - script: 'ls -la' - - task: Docker@2 - displayName: 'publish_image_to_${{ variables.environment }}' - condition: succeeded() - inputs: - command: 'buildAndPush' - containerRegistry: '$(dockerRegistryServiceConnection)' - repository: '$(imageRepository)' - Dockerfile: '$(Build.Repository.LocalPath)/$(dockerfileRelativePath)' - tags: | - $(Build.SourceBranchName)-$(Build.BuildId) - latest diff --git a/Dockerfile b/Dockerfile index c25e82b..6c9f16d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-slim-buster +FROM python:3.10-alpine WORKDIR /code diff --git a/app/main.py b/app/main.py index 670987f..e1520e7 100644 --- a/app/main.py +++ b/app/main.py @@ -1,18 +1,5 @@ -from fastapi import FastAPI -from app.routes.color import color -from app.routes.status import status_route -from app.routes.cosmosdb import cosmosdb - - -def include_router(app): - app.include_router(color, prefix='/color') - app.include_router(status_route, prefix='/status') - app.include_router(cosmosdb, prefix='/cosmosdb') - - -def configure_application(app): - include_router(app) - return app +from fastapi import FastAPI, Response +from http import HTTPStatus app = FastAPI() @@ -20,8 +7,19 @@ def configure_application(app): @app.get("/") async def home_root(): - return {"home_root": "ok"} + return Response(status_code=HTTPStatus.OK) + + +@app.get("/status") +async def status(): + return Response(status_code=HTTPStatus.OK) + +@app.get("/health") +async def health(): + return Response(status_code=HTTPStatus.OK) -configure_application(app) +@app.get("/healthz") +async def healthz(): + return Response(status_code=HTTPStatus.OK) diff --git a/app/routes/color.py b/app/routes/color.py deleted file mode 100644 index 77ff906..0000000 --- a/app/routes/color.py +++ /dev/null @@ -1,44 +0,0 @@ -from fastapi import APIRouter -import requests -import logging -from dapr.clients import DaprClient - -color = APIRouter() - - -@color.get("/") -async def home(): - return {"message": "home of color"} - - -@color.get("/dapr/http") -async def dapr_http_color(): - """ - return random color with a raw http request to dapr - """ - r = requests.get('http://localhost:3500/v1.0/invoke/backend/method/color') - color = r.text - logging.info(r) - return {"random color": f'{color}'} - - -@color.get("/dapr/sdk") -def dapr_sdk_color(): - """ - return random color with a sdk request to dapr - """ - with DaprClient() as daprClient: - result = daprClient.invoke_method( - 'backend', - 'color', - content_type="utf-8", - data=b'', - http_verb="GET") - - color = result.data.decode("utf-8") - - logging.info(str(color)) - return {"random color": f'{str(color)}'} - - - diff --git a/app/routes/cosmosdb.py b/app/routes/cosmosdb.py deleted file mode 100644 index d0ceb09..0000000 --- a/app/routes/cosmosdb.py +++ /dev/null @@ -1,30 +0,0 @@ -from fastapi import APIRouter -import logging -from dapr.clients import DaprClient -from python_random_strings import random_strings -import uuid - - -cosmosdb = APIRouter() - - -@cosmosdb.get("/") -async def home(): - return {"message": "home of cosmosdb"} - - -@cosmosdb.get("/dapr/sdk") -def dapr_sdk_cosmosdb(): - """ - create random value in cosmosdb with a sdk - """ - key = random_strings.random_lowercase(4) - value = str(uuid.uuid4()) - - with DaprClient() as daprClient: - daprClient.save_state(store_name="cosmosdb", key=key, value=value) - - logging.info("added cosmosdb key:f'{key}' and value f'{value}'") - - return {"cosmosdb key": f'{key}', "cosmosdb value": f'{value}'} - diff --git a/app/routes/status.py b/app/routes/status.py deleted file mode 100644 index ad301bc..0000000 --- a/app/routes/status.py +++ /dev/null @@ -1,9 +0,0 @@ -from fastapi import APIRouter, Response -from http import HTTPStatus - -status_route = APIRouter() - - -@status_route.get("/") -async def status(): - return Response(status_code=HTTPStatus.OK) diff --git a/docker-compose.yml b/docker-compose.yml index bf1b3f8..000b07f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,10 @@ version: "3.8" services: - webapp-python: - # image: "devops-webapp-python:latest" + status: build: dockerfile: ./Dockerfile context: . - container_name: webapp-python + container_name: status restart: always - environment: - - MY_CONFIGMAP_VALUE=1 - - MY_SECRET_VALUE=very secret 1 ports: - "8000:8000" diff --git a/requirements.txt b/requirements.txt index 66af423..97dc7cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,2 @@ fastapi uvicorn -pyyaml -unidecode -requests -dapr -python-random-strings