Skip to content

Commit

Permalink
fix: include all necessary libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreteles committed Oct 26, 2023
1 parent 4f0426d commit cd881ad
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 5 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends curl gcc g++ git make && \
apt-get clean && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* && \
pip install langflow>=0.5.3 && \
rm -rf /var/lib/apt/lists/*

COPY generateRequirements.py /tmp/generateRequirements.py

RUN python3 /tmp/generateRequirements.py --out ./requirements.txt && \
pip install -r ./requirements.txt && \
pip install langflow>=0.5.4 && \
pip cache purge && \
rm -rf /root/.cache/pip && \
useradd -m -u 1000 langflow && \
Expand All @@ -23,6 +28,6 @@ WORKDIR $HOME/app

ENTRYPOINT ["./run.sh"]

HEALTHCHECK CMD curl --fail http://0.0.0.0:7860/ || exit 1
HEALTHCHECK CMD curl --fail http://127.0.0.1:7860/ || exit 1

EXPOSE 7860
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
version: '3.8'
services:
langflow:
image: Sideral-tech/langflow-docker:latest
image: ghcr.io/sideral-tech/langflow-docker:latest
restart: unless-stopped
ports:
- 127.0.0.1:7860:7860
- 7860:7860
volumes:
- /data/langflow/data:/home/langflow/.cache/langflow
- /data/langflow/logs:/home/langflow/app/logs
Expand Down
127 changes: 127 additions & 0 deletions generateRequirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env python3

import argparse
import urllib.request
import json

try:
import tomli
except ImportError:
from pip._vendor import tomli


def get_latest_version():
url = "https://api.github.com/repos/logspace-ai/langflow/releases/latest"
response = urllib.request.urlopen(url)
data = json.loads(response.read())
return data["name"]


def get_latest_pyproject():
# TODO: Use latest version
#
# Temporarily disabling this as it's missing langflow dependencies
#
# url = f"https://raw.githubusercontent.com/logspace-ai/langflow/{get_latest_version()}/pyproject.toml"
#
# Use dev branch for now
url = "https://raw.githubusercontent.com/logspace-ai/langflow/dev/pyproject.toml"
response = urllib.request.urlopen(url)
data = response.read()
return data.decode("utf-8")


def load_toml():
return tomli.loads(get_latest_pyproject())


def write_requirements(dependencies, output_path):
with open(output_path, "w") as file:
for dep, version in dependencies.items():
file.write(f"{dep}{version}\n")


def convert_dependency_version(version):
if isinstance(version, dict):
version = version.get("version", "")
if "^" in version:
# Caret requirements
parts = version.replace("^", "").split(".")
if parts[0] == "0":
if parts[1] == "0":
return f">={version.replace('^', '')},<0.0.{str(int(parts[2])+1)}"
return f">={version.replace('^', '')},<0.{str(int(parts[1])+1)}.0"
return f">={version.replace('^', '')},<{str(int(parts[0])+1)}.0.0"
elif "~" in version:
# Tilde requirements
parts = version.replace("~", "").split(".")
if len(parts) == 3:
return f">={version.replace('~', '')},<{parts[0]}.{str(int(parts[1])+1)}.0"
elif len(parts) == 2:
return f">={version.replace('~', '')},<{parts[0]}.{str(int(parts[1])+1)}"
else:
return f">={version.replace('~', '')},<{str(int(parts[0])+1)}.0.0"
elif "*" in version:
# Wildcard requirements
parts = version.split(".")
if len(parts) == 2:
return f">={parts[0]}.0.0,<{str(int(parts[0])+1)}.0.0"
elif len(parts) == 3:
return f">={version.replace('*', '0')},<{parts[0]}.{str(int(parts[1])+1)}.0"
else:
return ">=0.0.0"
elif "," in version:
# Multiple requirements
return ",".join(
[convert_dependency_version(v.strip()) for v in version.split(",")]
)
elif any(op in version for op in [">=", "<=", ">", "<", "!=", "=="]):
# Inequality and Exact requirements
return version
else:
# Assume exact version if none of the above
return f"=={version}"


def convert_pyproject_to_requirements(output_path):
pyproject = load_toml()

dependencies = pyproject["tool"]["poetry"]["dependencies"]
extras = pyproject["tool"]["poetry"]["extras"]

dep_lines = {}

for name, dep in dependencies.items():
if "pywin32" in name:
continue
if name != "python" and not isinstance(dep, dict):
version = convert_dependency_version(dep)
dep_lines[name] = version
elif isinstance(dep, dict):
version = convert_dependency_version(dep.get("version", ""))
dep_lines[name] = version

for _, deps in extras.items():
for dep in deps:
if dep not in dep_lines: # avoid duplicate entries
dep_version = dependencies.get(dep, "")
if dep_version:
version = convert_dependency_version(dep_version)
dep_lines[dep] = version

write_requirements(dep_lines, output_path)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Convert pyproject.toml to requirements.txt."
)
parser.add_argument(
"--out",
dest="output_path",
default="requirements.txt",
help="Path to the output requirements.txt file.",
)
args = parser.parse_args()

convert_pyproject_to_requirements(args.output_path)

0 comments on commit cd881ad

Please sign in to comment.