Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomlam committed Jun 7, 2024
1 parent 50775d1 commit 931dcf2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions 05-assistive-chatbot/chatbot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 931dcf2

Please sign in to comment.