Skip to content

Commit

Permalink
Docker fixes (#120)
Browse files Browse the repository at this point in the history
* more fixes

* on any branch

* a

* poetry shell

* fix

* app mode for container

* update

* using alpine instead

* fix for alpine

* oops

* back to slim

* hm

* hm 2

* activate virtual environment

* change sorting

* test

* changes

* additional logging

* fix?

* fix

* more logging

* cleanup

* cleanup logging

* Revert "cleanup logging"

This reverts commit eed549b.

* more logging
  • Loading branch information
howardt12345 authored Sep 17, 2024
1 parent 71c49e9 commit 7878d3b
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 125 deletions.
1 change: 0 additions & 1 deletion .github/workflows/docker-build.publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Docker Build and Publish

on:
push:
branches: [ "main" ]
paths:
- 'Dockerfile'
- 'entrypoint.sh'
Expand Down
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Use an official Python runtime as a parent image
FROM python:3.12-slim
FROM python:3.11-slim

# Install git and curl
RUN apt-get update && apt-get install -y git curl
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*

# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

# Add Poetry to PATH
ENV PATH="${PATH}:/root/.local/bin"

# Check poetry version
RUN poetry --version

# Set the working directory in the container
WORKDIR /app

Expand All @@ -23,8 +25,11 @@ RUN chmod +x /entrypoint.sh
# Clone the repository (replace with your repository URL)
ENV REPO_URL=https://github.com/placeTW/discord-bot.git

# Set an environment variable for the mode (default to 'dev')
ENV APP_MODE=dev

# Set the entrypoint
ENTRYPOINT ["/entrypoint.sh"]

# Run the script when the container launches
CMD ["python", "main.py", "prod"]
CMD ["/bin/bash", "-c", "python main.py $APP_MODE"]
13 changes: 11 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ else
git pull
fi

# Configure Poetry to create the virtual environment in the project directory
poetry config virtualenvs.in-project true
# Verify Python version
python --version

# Verify Poetry version
poetry --version

# Configure Poetry to create virtual environments inside the project directory
poetry config virtualenvs.in-project true --local

# Create/update the virtual environment and install dependencies
echo "Installing dependencies..."
poetry install --no-interaction --no-ansi

# Activate the virtual environment
echo "Activating virtual environment..."
source $(poetry env info --path)/bin/activate

# Run the command passed to docker run
echo "Running command..."
exec "$@"
32 changes: 18 additions & 14 deletions modules/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,26 @@ async def log_event(
color: discord.Color = None,
log_to_channel=True,
):
supabaseClient.table("event_logs").insert(
{
"message_id": message.id if message.id else None,
"event": data["event"] if "event" in data else None,
"created_at": str(message.created_at),
"content": content if content else message.content if hasattr(message, 'content') else None,
"author_id": data["author_id"] if "author_id" in data else message.author.id,
"mentioned_id": data["mentioned_id"] if "mentioned_id" in data else None,
"channel_id": message.channel.id if message.channel else None,
"guild_id": message.guild.id if message.guild else None,
"generated_id": data["generated_id"] if "generated_id" in data else None,
"metadata": data["metadata"] if "metadata" in data else None,
}
).execute()
data = (
supabaseClient.table("event_logs")
.insert(
{
"message_id": message.id if message.id else None,
"event": data["event"] if "event" in data else None,
"created_at": str(message.created_at),
"content": content if content else message.content if hasattr(message, 'content') else None,
"author_id": data["author_id"] if "author_id" in data else message.author.id,
"mentioned_id": data["mentioned_id"] if "mentioned_id" in data else None,
"channel_id": message.channel.id if message.channel else None,
"guild_id": message.guild.id if message.guild else None,
"generated_id": data["generated_id"] if "generated_id" in data else None,
"metadata": data["metadata"] if "metadata" in data else None,
}
).execute()
)
if log_to_channel:
await logging.log_to_channel(data, color)
print(data)


async def log_message_event(message: discord.Message, events: list[str]):
Expand Down
Loading

0 comments on commit 7878d3b

Please sign in to comment.