Skip to content

Commit

Permalink
Upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilleumierc committed Nov 13, 2024
1 parent 52f0944 commit e8dc75c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
FROM python:3.12

COPY ./bridge-style /tmp/bridge-style
COPY requirements.txt /tmp/
RUN pip install /tmp/bridge-style && \
pip install --disable-pip-version-check --no-cache-dir --requirement=/tmp/requirements.txt && \
rm --recursive --force /tmp/*
COPY ./app /app

WORKDIR /app

CMD ["fastapi", "run", "main.py", "--port", "80"]
34 changes: 13 additions & 21 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os
import io
import zipfile
from typing import List, Optional

from typing import List, Optional

import traceback
import yaml
Expand All @@ -27,25 +24,26 @@ class Lyrx(BaseModel):
type: str
version: str
build: int
layers: Optional[List[str]]
layerDefinitions: List[dict]
binaryReferences: Optional[List[dict]]
elevationSurfaces: Optional[List[dict]]
rGBColorProfile: Optional[str]
cMYKColorProfile: Optional[str]
layers: list[str] | None = None
layerDefinitions: list[dict]
binaryReferences: list[dict] | None = None
elevationSurfaces: list[dict] | None = None
rGBColorProfile: str | None = None
cMYKColorProfile: str | None


app = FastAPI()

LOG = logging.getLogger("app")
with open('config.yaml') as f:
with open("config.yaml") as f:
config = yaml.load(f, Loader=yaml.FullLoader)
logging.config.dictConfig(config)


@app.post("/v1/lyrx2sld/")
async def lyrx_to_sld(lyrx: Lyrx, replaceesri: bool = False):

options = {'tolowercase': True, 'replaceesri': replaceesri}
options = {"tolowercase": True, "replaceesri": replaceesri}
warnings = []

try:
Expand All @@ -69,20 +67,14 @@ async def lyrx_to_sld(lyrx: Lyrx, replaceesri: bool = False):
return Response(
content=s.getvalue(),
media_type="application/x-zip-compressed",
headers={
'Content-Disposition': 'attachment;filename=style.zip'
}
)
headers={"Content-Disposition": "attachment;filename=style.zip"},
)

except Exception as e:
errors = traceback.format_exception(None, e, e.__traceback__)
for error in errors:
LOG.error(error)
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content=jsonable_encoder(
{
'warnings': warnings,
'errors': errors
})
)
content=jsonable_encoder({"warnings": warnings, "errors": errors}),
)
2 changes: 1 addition & 1 deletion app/start-reload2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ else
fi

# Start Uvicorn with live reload
exec uvicorn --reload --reload-dir /usr/local/lib/python3.7/site-packages/bridgestyle --reload-dir /app --host $HOST --port $PORT --log-level $LOG_LEVEL "$APP_MODULE"
exec uvicorn --reload --reload-dir /usr/local/lib/python3.12/site-packages/bridgestyle --reload-dir /app --host $HOST --port $PORT --log-level $LOG_LEVEL "$APP_MODULE"
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ services:
ports:
- 80:80
volumes:
- ./bridge-style/bridgestyle:/usr/local/lib/python3.7/site-packages/bridgestyle # For debug purpose
- ./bridge-style/bridgestyle:/usr/local/lib/python3.12/site-packages/bridgestyle # For debug purpose
- ./app:/app # For debug purpose
8 changes: 5 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
requests
PyYAML
fastapi[standard]==0.115.0
pydantic==2.9.2
PyYAML==6.0.2
requests==2.32.3
# For debugging
pydevd_pycharm~=213.7172.25
# pydevd_pycharm~=213.7172.25

0 comments on commit e8dc75c

Please sign in to comment.