Skip to content

Commit

Permalink
Create data directory inside Dockerfile instead of creating it via Py…
Browse files Browse the repository at this point in the history
…thon

This could be a fix for #110 (comment)
  • Loading branch information
TheLovinator1 committed Jul 16, 2023
1 parent 83b0c5b commit faef532
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ RUN pip install --no-cache-dir --disable-pip-version-check -r requirements.txt
# Copy source code
COPY discord_twitter_webhooks /app/discord_twitter_webhooks/

# Expose the port that Uvicorn will listen on
EXPOSE 8000
# Create the directory for the database
RUN mkdir -p /home/botuser/.local/share/discord_twitter_webhooks

# Create a volume for the database
VOLUME /home/botuser/.local/share/discord_twitter_webhooks

# Expose the port that Uvicorn will listen on
EXPOSE 8000

# Start Uvicorn
CMD [ "uvicorn", "discord_twitter_webhooks.main:app", "--host", "0.0.0.0", "--port", "8000" ]
18 changes: 16 additions & 2 deletions discord_twitter_webhooks/reader_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,22 @@ def get_reader(db_location: Path | None = None) -> Reader:
db_location = get_data_location() if db_location is None else db_location
db_file: Path = db_location / "discord_twitter_webhooks.db"

# Create db_location if it doesn't exist
db_location.mkdir(parents=True, exist_ok=True)
# Check if directory exists
if not db_location.exists():
msg: str = f"Directory {db_location} does not exist"
raise FileNotFoundError(msg)

# Check if the user has write access to the database directory
if not os.access(db_location, os.W_OK):
msg: str = f"Write access denied to {db_location}"
raise PermissionError(msg)

if os.name == "posix":
logger.debug(
"Data directory is owned by {uid}:{gid}",
uid=Path.owner(db_location),
gid=Path.group(db_location),
)

reader: Reader = make_reader(url=str(db_file))
if reader is None:
Expand Down

0 comments on commit faef532

Please sign in to comment.