File size: 3,611 Bytes
d8f71c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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