Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 24, 2024
2 parents 46ff677 + 72e25c9 commit d211c20
Show file tree
Hide file tree
Showing 23 changed files with 441 additions and 386 deletions.
2 changes: 1 addition & 1 deletion contrib/playwright/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ services:
timeout: 5s

ui-test:
image: "mcr.microsoft.com/playwright:${PLAYWRIGHT_TAG:-v1.44.1}"
image: "mcr.microsoft.com/playwright:${PLAYWRIGHT_TAG:-v1.48.1}"
depends_on:
# Starts the proxy and all other services
proxy:
Expand Down
24 changes: 12 additions & 12 deletions src/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#
ARG PYTHON_IMG_TAG=3.11
ARG MINIO_TAG=${MINIO_TAG:-RELEASE.2024-06-06T09-36-42Z}
FROM docker.io/minio/minio:${MINIO_TAG} as minio
FROM docker.io/minio/minio:${MINIO_TAG} AS minio


# Includes all labels and timezone info to extend from
FROM docker.io/python:${PYTHON_IMG_TAG}-slim-bookworm as base
FROM docker.io/python:${PYTHON_IMG_TAG}-slim-bookworm AS base
ARG APP_VERSION
ARG COMMIT_REF
ARG PYTHON_IMG_TAG
Expand All @@ -39,13 +39,13 @@ RUN set -ex \
&& update-ca-certificates
# Set locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8


# Extract dependencies from PDM lock to standard requirements.txt
FROM base as extract-deps
FROM base AS extract-deps
WORKDIR /opt/python
COPY pyproject.toml pdm.lock /opt/python/
RUN pip install --no-cache-dir --upgrade pip \
Expand All @@ -61,7 +61,7 @@ RUN pdm export --prod > requirements.txt \


# Build stage will all dependencies required to build Python wheels
FROM base as build
FROM base AS build
# NOTE this argument is specified during production build on Github workflow
# NOTE only the production API image contains the monitoring dependencies
ARG MONITORING
Expand Down Expand Up @@ -92,7 +92,7 @@ RUN pip install --user --no-warn-script-location --no-cache-dir \


# Run stage will minimal dependencies required to run Python libraries
FROM base as runtime
FROM base AS runtime
ARG PYTHON_IMG_TAG
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
Expand Down Expand Up @@ -146,7 +146,7 @@ HEALTHCHECK --start-period=10s --interval=5s --retries=20 --timeout=5s \


# Add certificates to use ODK Central over SSL (HTTPS, required)
FROM runtime as add-odk-certs
FROM runtime AS add-odk-certs
USER root
# Add the SSL cert for debug odkcentral
COPY --from=ghcr.io/hotosm/fmtm/proxy:debug \
Expand All @@ -155,7 +155,7 @@ RUN update-ca-certificates


# Stage to use during local development
FROM add-odk-certs as debug
FROM add-odk-certs AS debug
USER appuser
COPY --from=extract-deps --chown=appuser \
/opt/python/requirements-debug.txt \
Expand All @@ -173,7 +173,7 @@ CMD ["python", "-Xfrozen_modules=off", "-m", "debugpy", \


# Used during CI workflows (as root), with docs/test dependencies pre-installed
FROM add-odk-certs as ci
FROM add-odk-certs AS ci
ARG PYTHON_IMG_TAG
COPY --from=extract-deps \
/opt/python/requirements-ci.txt /opt/python/
Expand Down Expand Up @@ -201,7 +201,7 @@ CMD ["sleep", "infinity"]


# Final stage used during deployment
FROM runtime as prod
FROM runtime AS prod
# Pre-compile packages to .pyc (init speed gains)
RUN python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)"
# Note: 1 worker (process) per container, behind load balancer
Expand Down
5 changes: 0 additions & 5 deletions src/backend/app/central/central_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,6 @@ async def get_entities_data(
# Rename '__id' to 'id'
flattened_dict["id"] = flattened_dict.pop("__id")

# convert empty str osm_id to None
# when new entities are created osm_id will be empty
if flattened_dict.get("osm_id", "") == "":
flattened_dict["osm_id"] = None

all_entities.append(flattened_dict)

return all_entities
Expand Down
24 changes: 23 additions & 1 deletion src/backend/app/central/central_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,34 @@ class EntityOsmID(BaseModel):
id: str
osm_id: Optional[int] = None

@field_validator("osm_id", mode="before")
@classmethod
def convert_osm_id(cls, value):
"""Set osm_id to None if empty or invalid."""
if value in ("", " "): # Treat empty strings as None
return None
try:
return int(value) # Convert to integer if possible
except ValueError:
return value


class EntityTaskID(BaseModel):
"""Map of Entity UUID to FMTM Task ID."""

id: str
task_id: int
task_id: Optional[int] = None

@field_validator("task_id", mode="before")
@classmethod
def convert_task_id(cls, value):
"""Set task_id to None if empty or invalid."""
if value in ("", " "): # Treat empty strings as None
return None
try:
return int(value) # Convert to integer if possible
except ValueError:
return value


class EntityMappingStatus(EntityOsmID, EntityTaskID):
Expand Down
3 changes: 2 additions & 1 deletion src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ async def preview_split_by_square(
Use a lambda function to remove the "z" dimension from each
coordinate in the feature's geometry.
"""
boundary = merge_polygons(boundary)
if len(boundary["features"]) == 0:
boundary = merge_polygons(boundary)

return await run_in_threadpool(
lambda: split_by_square(
Expand Down
Loading

0 comments on commit d211c20

Please sign in to comment.