Add procedure to deploy langflow on AWS (#1177)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-12-07 10:52:11 -03:00 • committed by GitHub
commit b2d867e9aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 5645 additions and 27 deletions

View file

@ -63,7 +63,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
# This is the path to the db in the root of the project.
# When the user runs the Langflow the database url will
# be set dinamically.
sqlalchemy.url = sqlite:///../../../langflow.db
# sqlalchemy.url = sqlite:///../../../langflow.db
[post_write_hooks]

View file

@ -86,29 +86,31 @@ class Settings(BaseSettings):
value = langflow_database_url
logger.debug("Using LANGFLOW_DATABASE_URL env variable.")
else:
logger.debug("No DATABASE_URL env variable, using sqlite database")
# logger.debug("No DATABASE_URL env variable, using sqlite database")
logger.debug("No DATABASE_URL env variable, using custom database from secrets of {}".format(os.environ["host"]))
# Originally, we used sqlite:///./langflow.db
# so we need to migrate to the new format
# if there is a database in that location
if not values["CONFIG_DIR"]:
raise ValueError(
"CONFIG_DIR not set, please set it or provide a DATABASE_URL"
)
# if not values["CONFIG_DIR"]:
# raise ValueError(
# "CONFIG_DIR not set, please set it or provide a DATABASE_URL"
# )
new_path = f"{values['CONFIG_DIR']}/langflow.db"
if Path("./langflow.db").exists():
if Path(new_path).exists():
logger.debug(f"Database already exists at {new_path}, using it")
else:
try:
logger.debug("Copying existing database to new location")
copy2("./langflow.db", new_path)
logger.debug(f"Copied existing database to {new_path}")
except Exception:
logger.error("Failed to copy database, using default path")
new_path = "./langflow.db"
# new_path = f"{values['CONFIG_DIR']}/langflow.db"
# if Path("./langflow.db").exists():
# if Path(new_path).exists():
# logger.debug(f"Database already exists at {new_path}, using it")
# else:
# try:
# logger.debug("Copying existing database to new location")
# copy2("./langflow.db", new_path)
# logger.debug(f"Copied existing database to {new_path}")
# except Exception:
# logger.error("Failed to copy database, using default path")
# new_path = "./langflow.db"
value = f"sqlite:///{new_path}"
# value = f"sqlite:///{new_path}"
value = "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"])
return value

View file

@ -46,8 +46,10 @@ class Settings(BaseSettings):
value = langflow_database_url
logger.debug("Using LANGFLOW_DATABASE_URL env variable.")
else:
logger.debug("No DATABASE_URL env variable, using sqlite database")
value = "sqlite:///./langflow.db"
# logger.debug("No DATABASE_URL env variable, using sqlite database")
logger.debug("No DATABASE_URL env variable, using custom database from secrets of {}".format(os.environ["host"]))
# value = "sqlite:///./langflow.db"
value = "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"])
return value

View file

@ -0,0 +1,26 @@
#baseline
FROM --platform=linux/amd64 node:19-bullseye-slim AS base
RUN mkdir -p /home/node/app
RUN chown -R node:node /home/node && chmod -R 770 /home/node
RUN apt-get update && apt-get install -y jq curl
WORKDIR /home/node/app
# client build
FROM base AS builder-client
ARG BACKEND_URL
ENV BACKEND_URL $BACKEND_URL
RUN echo "BACKEND_URL: $BACKEND_URL"
WORKDIR /home/node/app
COPY --chown=node:node . ./
COPY ./set_proxy.sh .
RUN chmod +x set_proxy.sh && \
cat set_proxy.sh | tr -d '\r' > set_proxy_unix.sh && \
chmod +x set_proxy_unix.sh && \
./set_proxy_unix.sh
USER node
RUN npm install --loglevel warn
CMD ["npm", "run", "dev:docker"]

View file

@ -197,7 +197,8 @@ export default function FormModal({
const isSecureProtocol =
window.location.protocol === "https:" || window.location.port === "443";
const webSocketProtocol = isSecureProtocol ? "wss" : "ws";
const host = isDevelopment ? "localhost:7860" : window.location.host;
// const host = isDevelopment ? "localhost:7860" : window.location.host;
const host = window.location.host;
const chatEndpoint = `/api/v1/chat/${chatId}`;
return `${