Nevaehni commited on
Commit
b584cbf
·
1 Parent(s): 3bf305d
Files changed (2) hide show
  1. Dockerfile +12 -1
  2. app.py +6 -32
Dockerfile CHANGED
@@ -1,14 +1,25 @@
1
  FROM python:3.10
2
 
 
3
  RUN useradd -m -u 1000 user
 
 
4
  USER user
5
- ENV PATH="/home/user/.local/bin:$PATH"
 
 
 
 
 
 
6
 
7
  WORKDIR /app
8
 
9
  COPY --chown=user ./requirements.txt requirements.txt
10
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
 
 
 
12
  EXPOSE 7860
13
  EXPOSE 80
14
  ENV PYTHONUNBUFFERED=1 \
 
1
  FROM python:3.10
2
 
3
+ # Set up a new user named "user" with user ID 1000
4
  RUN useradd -m -u 1000 user
5
+
6
+ # Switch to the "user" user
7
  USER user
8
+
9
+ # Set home to the user's home directory
10
+ ENV HOME=/home/user \
11
+ PATH=/home/user/.local/bin:$PATH
12
+
13
+ # Set the working directory to the user's home directory
14
+ WORKDIR $HOME/app
15
 
16
  WORKDIR /app
17
 
18
  COPY --chown=user ./requirements.txt requirements.txt
19
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
20
 
21
+ COPY --chown=user . $HOME/app
22
+
23
  EXPOSE 7860
24
  EXPOSE 80
25
  ENV PYTHONUNBUFFERED=1 \
app.py CHANGED
@@ -11,8 +11,7 @@ import requests # Ensure 'requests' is installed
11
  from discord import Embed
12
  from discord.ext import commands
13
  from gradio_client import Client
14
- from gradio_client.exceptions import AppError
15
- from aiohttp import web # Import aiohttp for the web server
16
 
17
  # **Fetch Discord Bot Token from Environment Variable**
18
  DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')
@@ -242,47 +241,22 @@ async def on_command_error(ctx: commands.Context, error):
242
 
243
 
244
  async def handle_root(request):
245
- """
246
- Handler for the root URL. Responds with a simple text message.
247
-
248
- Args:
249
- request (aiohttp.web.Request): The incoming HTTP request.
250
-
251
- Returns:
252
- aiohttp.web.Response: The HTTP response.
253
- """
254
  return web.Response(text="DarkMuse GOES VROOOOM", status=200)
255
 
256
 
257
  async def start_web_server():
258
- """
259
- Initializes and starts the aiohttp web server on port 80.
260
- """
261
  app = web.Application()
262
  app.router.add_get('/', handle_root)
263
  runner = web.AppRunner(app)
264
  await runner.setup()
265
- site = web.TCPSite(runner, '0.0.0.0', 80) # Change to 80 for HTTP
266
  await site.start()
267
- logger.info("Web server started on port 80")
268
-
269
-
270
- async def main():
271
- """
272
- Main entry point to run both the Discord bot and the web server concurrently.
273
- """
274
- # Start the web server
275
- await start_web_server()
276
-
277
- # Start the Discord bot
278
- await bot.start(DISCORD_BOT_TOKEN)
279
 
280
 
281
- # Run the bot and the web server concurrently
282
  if __name__ == '__main__':
283
  try:
284
- asyncio.run(main())
285
- except KeyboardInterrupt:
286
- logger.info("Shutting down bot and web server...")
287
  except Exception as e:
288
- logger.exception(f"Failed to run the bot and web server: {e}")
 
11
  from discord import Embed
12
  from discord.ext import commands
13
  from gradio_client import Client
14
+ from gradio_client.exceptions import AppError # Updated import
 
15
 
16
  # **Fetch Discord Bot Token from Environment Variable**
17
  DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')
 
241
 
242
 
243
  async def handle_root(request):
 
 
 
 
 
 
 
 
 
244
  return web.Response(text="DarkMuse GOES VROOOOM", status=200)
245
 
246
 
247
  async def start_web_server():
 
 
 
248
  app = web.Application()
249
  app.router.add_get('/', handle_root)
250
  runner = web.AppRunner(app)
251
  await runner.setup()
252
+ site = web.TCPSite(runner, '0.0.0.0', 7860)
253
  await site.start()
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
 
256
+ # Run the bot
257
  if __name__ == '__main__':
258
  try:
259
+ bot.run(DISCORD_BOT_TOKEN)
260
+ bot.loop.create_task(start_web_server())
 
261
  except Exception as e:
262
+ logger.exception(f"Failed to run the bot: {e}")