Skip to content

Commit

Permalink
dockerfileのミス修正
Browse files Browse the repository at this point in the history
- poetryがうまく起動せず、エラーとなっていた(諦めてpipからインストール)
- fly.ioの場合、コメントアウトした部分trueにするとエラーになるので仮想環境で実行するよう指定
- ENABLE_SLASH_COMMAND_GUILD_IDがいまいちだった点も修正
  • Loading branch information
tetsuya-ki committed Oct 2, 2022
1 parent 19ec4d1 commit 357547c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
20 changes: 11 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
FROM python:3.8.6-slim

# ソースを置くディレクトリを変数として格納
ARG dir=/opt/app
ARG POETRY_VERSION=1.1.13
ARG POETRY_HOME=/opt/poetry
ARG dir=/opt/app \
home=/home
ENV POETRY_HOME=/opt/poetry \
# POETRY_VIRTUALENVS_CREATE=false \
# POETRY_VIRTUALENVS_IN_PROJECT=false \
POETRY_NO_INTERACTION=1 \
POETRY_VERSION=1.1.14
ENV PATH=$PATH:$POETRY_HOME/bin
# poetry導入
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=${POETRY_HOME} python3 - --version=${POETRY_VERSION}
ENV PATH ${PATH}:${POETRY_HOME}/bin
RUN pip install poetry


WORKDIR $dir
RUN groupadd -r bot && useradd -r -g bot bot
ADD entrypoint.sh $dir
ADD requirements.txt $dir

# requirements.txtに記載されたパッケージをインストール
RUN pip install -r requirements.txt

ADD . $dir
RUN chmod -R 755 $dir && chown -R bot:bot $dir
RUN chmod -R 755 $home && chown -R bot:bot $home
RUN rm -f $dir/cogs/modules/first_time

# user botで実行
Expand All @@ -45,6 +46,7 @@ APPLICATION_ID=\
USE_IF_AVAILABLE_FILE=True

WORKDIR $dir
RUN poetry update && poetry install

# dockerコンテナが起動する際に実行されるコードファイル (`entrypoint.sh`)
ENTRYPOINT ["./entrypoint.sh"]
4 changes: 3 additions & 1 deletion assistantbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ async def setup_hook(self):
await self.load_extension(cog) # awaitが必要

# テスト中以外は環境変数で設定しないことを推奨(環境変数があれば、ギルドコマンドとして即時発行される)
if settings.ENABLE_SLASH_COMMAND_GUILD_ID:
if settings.ENABLE_SLASH_COMMAND_GUILD_ID is not None and len(settings.ENABLE_SLASH_COMMAND_GUILD_ID) > 0:
LOG.info(settings.ENABLE_SLASH_COMMAND_GUILD_ID)
for guild in settings.ENABLE_SLASH_COMMAND_GUILD_ID:
LOG.info(guild)
self.tree.copy_global_to(guild=guild)
await self.tree.sync(guild=guild)
else:
Expand Down
8 changes: 7 additions & 1 deletion cogs/modules/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ def num_env(param):
return int(param)

def split_guild_env(str):
guilds = [] if str is None else list(map(discord.Object, str.split(';')))
guilds = []
if str is None or str == '':
pass
elif not ';' in str:
guilds.append(discord.Object(str))
else:
guilds = list(map(discord.Object, str.split(';')))
return guilds

load_dotenv(verbose=True)
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
poetry init
poetry install
poetry run python assistantbot.py

0 comments on commit 357547c

Please sign in to comment.