Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker fixes #120

Merged
merged 25 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading