From 931dcf2f4fac7db1d1500a7b1bceecd482eb9852 Mon Sep 17 00:00:00 2001 From: Yoom Lam Date: Fri, 7 Jun 2024 08:19:05 -0500 Subject: [PATCH] WIP --- .github/workflows/push-image.yml | 12 ++++++++++++ 05-assistive-chatbot/chatbot_api.py | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 63b60c4..f696dfa 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -88,6 +88,7 @@ jobs: echo "SECRET_NAME=$SECRET_NAME" >> $GITHUB_ENV - name: "Populate .env file" + if: false run: | # The ENV_FILE_CONTENTS contains API keys, like LITERAL_API_KEY and OPENAI_API_KEY # As such, make sure the built image is not publicly accessible @@ -164,4 +165,15 @@ jobs: sleep 10 ./.github/workflows/waitForLightsail.sh deployment + + - name: "Initialize app" + if: inputs.deploy_image + run: | + # The ENV_FILE_CONTENTS contains API keys, like LITERAL_API_KEY and OPENAI_API_KEY + # As such, make sure the built image is not publicly accessible + echo "${{ secrets[env.SECRET_NAME] }}" > .env + + SVC_URL=$(aws lightsail get-container-services --service-name "$SERVICE_NAME" | jq -r '.containerServices[0].url') + curl -X POST "SVC_URL/initenvs" --data-binary '@.env' + # TODO: warm up vector DB on startup diff --git a/05-assistive-chatbot/chatbot_api.py b/05-assistive-chatbot/chatbot_api.py index 6601557..f06dc69 100755 --- a/05-assistive-chatbot/chatbot_api.py +++ b/05-assistive-chatbot/chatbot_api.py @@ -70,18 +70,17 @@ def healthcheck(request: Request): @app.post("/initenvs") def initenvs(env_file_contents: str = Body()): - print(f"{type(env_file_contents)}: {env_file_contents}") env_values = dotenv.dotenv_values(stream=StringIO(env_file_contents)) - values_changed = [] + vars_updated = [] for name, value in env_values.items(): if name.endswith("_API_KEY") or name.endswith("_API_TOKEN") or name in ALLOWED_ENV_VARS: logger.info("Setting environment variable %s", name) os.environ[name] = value or "" - values_changed.append(name) + vars_updated.append(name) else: logger.warning("Setting environment variable %s is not allowed!", name) chatbot.reset() - return str(values_changed) + return str(vars_updated) if __name__ == "__main__":