diff --git a/.env.example b/.env.example index ebfae2b..a285ec8 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,10 @@ -# Warn: 全ての値は必須です。指定しないで動くかは知りません。 +# Warn: 全ての値は必須です。 -# uwuzuサーバーへの接続(必須) +# uwuzuサーバーへの接続 UWUZU_HOST=uwuzu.example.com # uwuzuサーバーのホスト名+":"+ポート(:ポートは任意)です。originではないのでHTTPSが必須になっています。stringです。 UWUZU_TOKEN=APITOKEN # uwuzuサーバーのアカウントで使えるAPIトークンです。全権限を与えることが推奨されているらしいです。stringです。 -# Botの挙動(任意) +# Botの挙動 TWEET_ENABLED=true # 3分から3時間での間隔でランダムなつぶやきをユーズとして投稿するかどうかを指定できます。booleanです。 CHECK_INTERVAL=300 # メンション/返信を確認する間隔です。number(second)です。 THINK_OUTPUT_ENABLED=false # 人工無能の脳内をconsole.log()するかどうかを指定できます。量が多いため非推奨らしいです。booleanです。 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index af024a6..f0503f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,6 @@ # Load Node.js FROM --platform=$BUILDPLATFORM node:24.12.0-bullseye-slim -# Set required/default env -ENV UWUZU_HOST=${UWUZU_HOST} -ENV UWUZU_TOKEN=${UWUZU_TOKEN} -ENV TWEET_ENABLED=${TWEET_ENABLED:-true} -ENV CHECK_INTERVAL=${CHECK_INTERVAL:-300} -ENV THINK_OUTPUT_ENABLED=${THINK_OUTPUT_ENABLED:-false} - # Set working directory WORKDIR /app @@ -40,8 +33,13 @@ RUN cat < /app/config.json } EOF +# Copy entrypoint +COPY ./entrypoint.sh /app/docker-entrypoint.sh +RUN chmod +x /app/docker-entrypoint.sh + # Change line break -RUN find /app -type f -exec sed -i 's/\r$//' {} \; +RUN sed -i 's/\r$//' /entrypoint.sh \ + && find /app -type f -exec sed -i 's/\r$//' {} \; # Run -CMD [ "npm", "start" ] \ No newline at end of file +ENTRYPOINT ["/app/docker-entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index c51e2e2..7ca6015 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,4 @@ docker run -d --restart=always -v ./memory.db:/app/memory.db -e UWUZU_HOST=uwuzu > **WARNING** >環境変数への値は`.env.example`を確認してください。 -UWUZU_*の環境変数は必須です。指定しないで動くかは知りません。 \ No newline at end of file +全ての環境変数は必須です。 \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..345360e --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +# Check required env +if [ -z "$UWUZU_HOST" ] || [ -z "$UWUZU_TOKEN" ] || + [ -z "$TWEET_ENABLED" ] || [ -z "$CHECK_INTERVAL" ] || [ -z "$THINK_OUTPUT_ENABLED" ]; then + echo "Error: The environment variable is not set" + exit 1 +fi + +# Create config.json +cat < /app/config.json +{ + "host": "${UWUZU_HOST}", + "api_token": "${UWUZU_TOKEN}", + "random_ueuse": ${TWEET_ENABLED}, + "check_interval": ${CHECK_INTERVAL}, + "rana_core_log": ${THINK_OUTPUT_ENABLED} +} +EOF + +# Run +exec npm start