Spaces:
Paused
Paused
| FROM ubuntu:22.04 | |
| # Install necessary tools | |
| RUN apt-get update && apt-get install -y \ | |
| tar \ | |
| gzip \ | |
| file \ | |
| jq \ | |
| curl \ | |
| sed \ | |
| aria2 \ | |
| unzip \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up a new user named "user" with user ID 1000 | |
| RUN useradd -m -u 1000 user | |
| # Switch to the "user" user | |
| USER user | |
| # Set home to the user's home directory | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Set the working directory to the user's home directory | |
| WORKDIR $HOME/chatbox | |
| RUN mkdir -p $HOME/chatbox/data | |
| COPY --chown=user . $HOME/chatbox | |
| #use auto gen cfg file start | |
| RUN --mount=type=secret,id=MYSQL_HOST,mode=0444,required=true \ | |
| --mount=type=secret,id=MYSQL_PORT,mode=0444,required=true \ | |
| --mount=type=secret,id=MYSQL_USER,mode=0444,required=true \ | |
| --mount=type=secret,id=MYSQL_PASSWORD,mode=0444,required=true \ | |
| --mount=type=secret,id=MYSQL_DATABASE,mode=0444,required=true \ | |
| ENV_MYSQL_HOST=$(cat /run/secrets/MYSQL_HOST) && \ | |
| ENV_MYSQL_PORT=$(cat /run/secrets/MYSQL_PORT) && \ | |
| ENV_MYSQL_USER=$(cat /run/secrets/MYSQL_USER) && \ | |
| ENV_MYSQL_PASSWORD=$(cat /run/secrets/MYSQL_PASSWORD) && \ | |
| ENV_MYSQL_DATABASE=$(cat /run/secrets/MYSQL_DATABASE) && \ | |
| echo "{\n\ | |
| \"force\": false,\n\ | |
| \"address\": \"0.0.0.0\",\n\ | |
| \"port\": 10086,\n\ | |
| \"scheme\": {\n\ | |
| \"https\": false,\n\ | |
| \"cert_file\": \"\",\n\ | |
| \"key_file\": \"\",\n\ | |
| \"http_port\": 10086\n\ | |
| },\n\ | |
| \"cache\": {\n\ | |
| \"expiration\": 60,\n\ | |
| \"cleanup_interval\": 120\n\ | |
| },\n\ | |
| \"database\": {\n\ | |
| \"type\": \"mysql\",\n\ | |
| \"host\": \"$ENV_MYSQL_HOST\",\n\ | |
| \"port\": $ENV_MYSQL_PORT,\n\ | |
| \"user\": \"$ENV_MYSQL_USER\",\n\ | |
| \"password\": \"$ENV_MYSQL_PASSWORD\",\n\ | |
| \"name\": \"$ENV_MYSQL_DATABASE\"\n\ | |
| }\n\ | |
| }" > $HOME/chatbox/test.json | |
| #RUN --mount=type=secret,id=MYSQL_HOST,mode=0444,required=true \ | |
| # --mount=type=secret,id=MYSQL_PORT,mode=0444,required=true \ | |
| # --mount=type=secret,id=MYSQL_USER,mode=0444,required=true \ | |
| # --mount=type=secret,id=MYSQL_PASSWORD,mode=0444,required=true \ | |
| # --mount=type=secret,id=MYSQL_DATABASE,mode=0444,required=true \ | |
| # ENV_MYSQL_HOST=$(cat /run/secrets/MYSQL_HOST) && \ | |
| # ENV_MYSQL_PORT=$(cat /run/secrets/MYSQL_PORT) && \ | |
| # ENV_MYSQL_USER=$(cat /run/secrets/MYSQL_USER) && \ | |
| # ENV_MYSQL_PASSWORD=$(cat /run/secrets/MYSQL_PASSWORD) && \ | |
| # ENV_MYSQL_DATABASE=$(cat /run/secrets/MYSQL_DATABASE) && \ | |
| # sed -i "s/MYSQL_HOST/${ENV_MYSQL_HOST:-localhost}/g" $HOME/chatbox/test.json && \ | |
| # sed -i "s/MYSQL_PORT/${ENV_MYSQL_PORT:-3306}/g" $HOME/chatbox/test.json && \ | |
| # sed -i "s/MYSQL_USER/${ENV_MYSQL_USER:-root}/g" $HOME/chatbox/test.json && \ | |
| # sed -i "s/MYSQL_PASSWORD/${ENV_MYSQL_PASSWORD:-password}/g" $HOME/chatbox/test.json && \ | |
| # sed -i "s/MYSQL_DATABASE/${ENV_MYSQL_PASSWORD:-chatbox}/g" $HOME/chatbox/test.json | |
| RUN cp -f $HOME/chatbox/test.json $HOME/chatbox/data/config.json | |
| RUN cat $HOME/chatbox/data/config.json | |
| #end | |
| RUN chmod +x $HOME/chatbox/chatbox | |
| # Create a startup script that runs chatbox and Aria2 | |
| RUN echo '#!/bin/bash\n\ | |
| aria2c --enable-rpc --rpc-listen-all --rpc-allow-origin-all --rpc-listen-port=6800 --daemon\n\ | |
| /home/user/chatbox/chatbox server --debug --data /home/user/chatbox/data/ --no-prefix' > $HOME/chatbox/start.sh && \ | |
| chmod +x $HOME/chatbox/start.sh | |
| # Set the command to run when the container starts | |
| CMD ["/bin/bash", "-c", "/home/user/chatbox/start.sh"] | |
| # Expose the default chatbox port | |
| EXPOSE 10086 6800 |