From f229cf303f752f4c78fd7ebc0cb40af152d7c508 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Mon, 18 Nov 2024 16:38:01 -0500 Subject: [PATCH] build: use standalone executable to avoid dotnet runtime --- containers/fhir-converter/Dockerfile | 31 +++++++++--------------- containers/fhir-converter/Makefile | 6 ++++- containers/fhir-converter/README.md | 2 +- containers/fhir-converter/app/service.py | 5 ++-- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/containers/fhir-converter/Dockerfile b/containers/fhir-converter/Dockerfile index fc77e36cce..f2d6cb2013 100644 --- a/containers/fhir-converter/Dockerfile +++ b/containers/fhir-converter/Dockerfile @@ -1,7 +1,7 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build # Download FHIR-Converter -RUN git clone https://github.com/skylight-hq/FHIR-Converter.git --branch v7.0-skylight-9 --single-branch /build/FHIR-Converter +RUN git clone https://github.com/skylight-hq/FHIR-Converter.git --branch mcm/publish-standalone --single-branch /build/FHIR-Converter WORKDIR /build/FHIR-Converter @@ -9,31 +9,19 @@ RUN pwd && ls -la RUN echo test > src/Microsoft.Health.Fhir.TemplateManagement.UnitTests/TestData/DecompressedFiles/VXU_V04.liquid RUN if [ -f src/Microsoft.Health.Fhir.TemplateManagement.UnitTests/TestData/DecompressedFiles/.wh.VXU_V04.liquid ]; then rm src/Microsoft.Health.Fhir.TemplateManagement.UnitTests/TestData/DecompressedFiles/.wh.VXU_V04.liquid; fi -RUN mkdir bin && \ - wget https://github.com/deislabs/oras/releases/download/v0.12.0/oras_0.12.0_windows_amd64.tar.gz -O ./bin/oras.tar.gz && \ - tar -xvf ./bin/oras.tar.gz -C ./bin # Build Microsoft FHIR Converter -RUN dotnet build -c Release -o output +RUN dotnet publish src/Microsoft.Health.Fhir.Liquid.Converter.Tool/Microsoft.Health.Fhir.Liquid.Converter.Tool.csproj -c Release -r linux-x64 --self-contained true -o output -FROM mcr.microsoft.com/dotnet/runtime:6.0 AS runtime +# Set up python Server +FROM python:3.10-slim AS runtime # Copy FHIR-Converter binary from build stage COPY --from=build /build/FHIR-Converter/output /build/FHIR-Converter/output COPY --from=build /build/FHIR-Converter/data/Templates /build/FHIR-Converter/data/Templates -ENV PYTHONUNBUFFERED=1 - -# Install python via pyenv -RUN apt-get update && apt-get install -y curl git jq build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev -RUN curl https://pyenv.run | bash -RUN export PYENV_ROOT="$HOME/.pyenv" -RUN export PATH="$PYENV_ROOT/bin:$PATH" -RUN eval "$(pyenv init -)" -RUN /root/.pyenv/bin/pyenv install 3.10.13 -RUN /root/.pyenv/bin/pyenv global 3.10.13 - -RUN /root/.pyenv/shims/pip install --no-cache --upgrade pip setuptools +# # Install python via pyenv +RUN apt-get update && apt-get install -y curl jq libicu-dev # Get an up to date copy of active rxnorm codes and names RUN rm /build/FHIR-Converter/output/rxnorm.csv @@ -44,8 +32,11 @@ RUN curl 'https://rxnav.nlm.nih.gov/REST/allstatus.json?status=active' \ # Install requirements WORKDIR /code +# Set --build-arg CACHBUSTSERVICE= to only invalidate the python code installation +ARG CACHEBUSTSERVICE=1 + COPY requirements.txt . -RUN /root/.pyenv/shims/pip install -r requirements.txt +RUN pip install -r requirements.txt # Copy FastAPI app COPY app /code/app @@ -53,4 +44,4 @@ COPY assets /code/assets COPY README.md /code/README.md EXPOSE 8080 -CMD /root/.pyenv/shims/uvicorn app.main:app --host 0.0.0.0 --port 8080 +CMD uvicorn app.main:app --host 0.0.0.0 --port 8080 diff --git a/containers/fhir-converter/Makefile b/containers/fhir-converter/Makefile index af7c1f5982..6380c32681 100644 --- a/containers/fhir-converter/Makefile +++ b/containers/fhir-converter/Makefile @@ -42,4 +42,8 @@ build-image: build-image-no-cache: @echo "Building Docker image for the FHIR Converter service without cache..." - docker compose build --no-cache + docker compose build --no-cache + +build-image-no-cache-service: + @echo "Building Docker image for the FHIR Converter service without cache..." + docker compose build --build-arg CACHEBUSTSERVICE=$(shell date +%s) diff --git a/containers/fhir-converter/README.md b/containers/fhir-converter/README.md index 29a43504d5..67da973978 100644 --- a/containers/fhir-converter/README.md +++ b/containers/fhir-converter/README.md @@ -149,7 +149,7 @@ For local development, you may prefer to run the service directly from Python. T 4. Make a fresh virtual environment with `python -m venv .venv`. 5. Activate the virtual environment with `source .venv/bin/activate` (MacOS and Linux), `venv\Scripts\activate` (Windows Command Prompt), or `.venv\Scripts\Activate.ps1` (Windows PowerShell). 5. Install all of the Python dependencies for the ingestion service with `pip install -r requirements.txt` into your virtual environment. -6. Run the FHIR Converter on `localhost:8080` with `FHIR_CONVERTER_TOOl_PATH=~/fully/qualified/path/to/Microsoft.Health.Fhir.Liquid.Converter.Tool.dll python -m uvicorn app.main:app --host 0.0.0.0 --port 8080`. +6. Run the FHIR Converter on `localhost:8080` with `FHIR_CONVERTER_TOOl_PATH=~/fully/qualified/path/to/Microsoft.Health.Fhir.Liquid.Converter.Tool python -m uvicorn app.main:app --host 0.0.0.0 --port 8080`. ### Building the Docker Image diff --git a/containers/fhir-converter/app/service.py b/containers/fhir-converter/app/service.py index 98f1cc2883..4ab16fef35 100644 --- a/containers/fhir-converter/app/service.py +++ b/containers/fhir-converter/app/service.py @@ -91,7 +91,7 @@ def convert_to_fhir( # Setup path variables converter_project_path = os.getenv( "FHIR_CONVERTER_TOOL_PATH", - "/build/FHIR-Converter/output/Microsoft.Health.Fhir.Liquid.Converter.Tool.dll", + "/build/FHIR-Converter/output/Microsoft.Health.Fhir.Liquid.Converter.Tool", ) if input_type == "vxu" or input_type == "elr": template_directory_path = "/build/FHIR-Converter/data/Templates/Hl7v2" @@ -110,7 +110,7 @@ def convert_to_fhir( # Formulate command for the FHIR Converter. fhir_conversion_command = [ - f"dotnet {converter_project_path} ", + f"{converter_project_path} ", "convert -- ", f"--TemplateDirectory {template_directory_path} ", f"--RootTemplate {root_template.value} ", @@ -127,6 +127,7 @@ def convert_to_fhir( capture_output=True, text=True, ) + # Print the standard output dev_mode = os.getenv("DEV_MODE", "false").lower() if dev_mode == "true":