Skip to content

Commit

Permalink
Fix docker volume mounts (Significant-Gravitas#3710)
Browse files Browse the repository at this point in the history
Co-authored-by: Reinier van der Leer <[email protected]>
Co-authored-by: Nicholas Tindle <[email protected]>
  • Loading branch information
3 people authored and jaimevalero committed May 7, 2023
1 parent c3ada80 commit 299c259
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ RUN sed -i '/Items below this point will not be included in the Docker Image/,$d
pip install --no-cache-dir -r requirements.txt
WORKDIR /app
ONBUILD COPY autogpt/ ./autogpt
ONBUILD COPY scripts/ ./scripts


FROM autogpt-${BUILD_TYPE} AS auto-gpt
8 changes: 5 additions & 3 deletions autogpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ def get_current_git_branch() -> str:


def get_latest_bulletin() -> tuple[str, bool]:
exists = os.path.exists("CURRENT_BULLETIN.md")
exists = os.path.exists("data/CURRENT_BULLETIN.md")
current_bulletin = ""
if exists:
current_bulletin = open("CURRENT_BULLETIN.md", "r", encoding="utf-8").read()
current_bulletin = open(
"data/CURRENT_BULLETIN.md", "r", encoding="utf-8"
).read()
new_bulletin = get_bulletin_from_web()
is_new_news = new_bulletin != "" and new_bulletin != current_bulletin

Expand All @@ -125,7 +127,7 @@ def get_latest_bulletin() -> tuple[str, bool]:
)

if new_bulletin and is_new_news:
open("CURRENT_BULLETIN.md", "w", encoding="utf-8").write(new_bulletin)
open("data/CURRENT_BULLETIN.md", "w", encoding="utf-8").write(new_bulletin)
current_bulletin = f"{Fore.RED}::NEW BULLETIN::{Fore.RESET}\n\n{new_bulletin}"

return f"{news_header}\n{current_bulletin}", is_new_news
Expand Down
Empty file added data/.keep
Empty file.
10 changes: 8 additions & 2 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ Get your OpenAI API key from: [https://platform.openai.com/account/api-keys](htt
environment:
MEMORY_BACKEND: ${MEMORY_BACKEND:-redis}
REDIS_HOST: ${REDIS_HOST:-redis}
volumes:
- ./:/app
profiles: ["exclude-from-up"]
volumes:
- ./auto_gpt_workspace:/app/auto_gpt_workspace
- ./data:/app/data
## allow auto-gpt to write logs to disk
- ./logs:/app/logs
## uncomment following lines if you have / want to make use of these files
#- ./azure.yaml:/app/azure.yaml
#- ./ai_settings.yaml:/app/ai_settings.yaml
redis:
image: "redis/redis-stack-server:latest"

Expand Down
16 changes: 8 additions & 8 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,28 @@ def test_get_bulletin_from_web_exception(mock_get):


def test_get_latest_bulletin_no_file():
if os.path.exists("CURRENT_BULLETIN.md"):
os.remove("CURRENT_BULLETIN.md")
if os.path.exists("data/CURRENT_BULLETIN.md"):
os.remove("data/CURRENT_BULLETIN.md")

bulletin, is_new = get_latest_bulletin()
assert is_new


def test_get_latest_bulletin_with_file():
expected_content = "Test bulletin"
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
with open("data/CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write(expected_content)

with patch("autogpt.utils.get_bulletin_from_web", return_value=""):
bulletin, is_new = get_latest_bulletin()
assert expected_content in bulletin
assert is_new == False

os.remove("CURRENT_BULLETIN.md")
os.remove("data/CURRENT_BULLETIN.md")


def test_get_latest_bulletin_with_new_bulletin():
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
with open("data/CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write("Old bulletin")

expected_content = "New bulletin from web"
Expand All @@ -116,20 +116,20 @@ def test_get_latest_bulletin_with_new_bulletin():
assert expected_content in bulletin
assert is_new

os.remove("CURRENT_BULLETIN.md")
os.remove("data/CURRENT_BULLETIN.md")


def test_get_latest_bulletin_new_bulletin_same_as_old_bulletin():
expected_content = "Current bulletin"
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
with open("data/CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write(expected_content)

with patch("autogpt.utils.get_bulletin_from_web", return_value=expected_content):
bulletin, is_new = get_latest_bulletin()
assert expected_content in bulletin
assert is_new == False

os.remove("CURRENT_BULLETIN.md")
os.remove("data/CURRENT_BULLETIN.md")


@skip_in_ci
Expand Down

0 comments on commit 299c259

Please sign in to comment.