Skip to content

Commit

Permalink
build: use standalone executable to avoid dotnet runtime (#2928)
Browse files Browse the repository at this point in the history
* build: use standalone executable to avoid dotnet runtime

* style: newlines are nice

* fix: cmd args

* fix: remove debug cmd

* fix: update tag

* fix: back to branch :(

* fix: debugging

* fix: remove debug stuff

* update tag
  • Loading branch information
mcmcgrath13 authored Nov 20, 2024
1 parent 4b5de32 commit ca8a743
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
1 change: 1 addition & 0 deletions containers/ecr-viewer/seed-scripts/docker-compose-seed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include:
- ../docker-compose.yml
services:
fhir-converter-service:
platform: linux/amd64
build:
context: ../../fhir-converter/
ports:
Expand Down
39 changes: 17 additions & 22 deletions containers/fhir-converter/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
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 v7.0-skylight-11 --single-branch /build/FHIR-Converter

WORKDIR /build/FHIR-Converter

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 clean
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
Expand All @@ -44,13 +36,16 @@ RUN curl 'https://rxnav.nlm.nih.gov/REST/allstatus.json?status=active' \
# Install requirements
WORKDIR /code

# Set --build-arg CACHBUSTSERVICE=<random number here> 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
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"]
6 changes: 5 additions & 1 deletion containers/fhir-converter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion containers/fhir-converter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions containers/fhir-converter/app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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} ",
Expand All @@ -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":
Expand Down

0 comments on commit ca8a743

Please sign in to comment.