guipenedo HF Staff commited on
Commit
1acf3b6
·
unverified ·
1 Parent(s): a00a9a1

add server

Browse files
Files changed (3) hide show
  1. Dockerfile +17 -9
  2. nginx.conf +36 -0
  3. start.sh +46 -0
Dockerfile CHANGED
@@ -1,28 +1,36 @@
1
  FROM python:3.9
2
 
 
3
  RUN useradd -m -u 1000 aim_user
4
 
5
- # Switch to the "aim_user" user
 
 
 
 
 
 
6
  USER aim_user
7
 
8
- # Set home to the user's home directory
9
  ENV HOME=/home/aim_user \
10
  PATH=/home/aim_user/.local/bin:$PATH
11
 
12
- # Set the working directory to the user's home directory
13
  WORKDIR $HOME
14
 
15
- # install the `aim` package on the latest version
16
- RUN pip install aim
17
 
18
  ENTRYPOINT ["/bin/sh", "-c"]
19
 
20
  COPY aim_repo.tar.gz .
21
  RUN tar xvzf aim_repo.tar.gz
 
22
  # have to run `aim init` in the directory that stores aim data for
23
  # otherwise `aim up` will prompt for confirmation to create the directory itself.
24
- # We run aim listening on 0.0.0.0 to expose all ports. Also, we run
25
- # using `--dev` to print verbose logs. Port 43800 is the default port of
26
- # `aim up` but explicit is better than implicit.
27
- CMD ["aim up --host 0.0.0.0 --port 7860 --workers 2"]
28
 
 
 
 
1
  FROM python:3.9
2
 
3
+ # Create user first
4
  RUN useradd -m -u 1000 aim_user
5
 
6
+ # Perform root operations: Install packages, copy system configs
7
+ RUN apt-get update && apt-get install -y nginx procps && rm -rf /var/lib/apt/lists/*
8
+ COPY nginx.conf /etc/nginx/nginx.conf
9
+ COPY start.sh /start.sh
10
+ RUN chmod +x /start.sh
11
+
12
+ # Now switch to the final user
13
  USER aim_user
14
 
15
+ # Set home and path
16
  ENV HOME=/home/aim_user \
17
  PATH=/home/aim_user/.local/bin:$PATH
18
 
19
+ # Set the working directory
20
  WORKDIR $HOME
21
 
22
+ # install aim (as aim_user)
23
+ RUN pip install aim --no-cache-dir
24
 
25
  ENTRYPOINT ["/bin/sh", "-c"]
26
 
27
  COPY aim_repo.tar.gz .
28
  RUN tar xvzf aim_repo.tar.gz
29
+
30
  # have to run `aim init` in the directory that stores aim data for
31
  # otherwise `aim up` will prompt for confirmation to create the directory itself.
32
+ # We run aim listening on 0.0.0.0 to expose all ports.
33
+ # Port 43800 for UI, 53800 for Server. Nginx listens on 7860.
 
 
34
 
35
+ # Run the startup script as aim_user
36
+ CMD ["/start.sh"]
nginx.conf ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ worker_processes 1;
2
+ pid /home/aim_user/nginx_run/nginx.pid; # Needs a path writable by aim_user
3
+ error_log /home/aim_user/nginx_logs/error.log warn; # Needs a path writable by aim_user
4
+
5
+ events {
6
+ worker_connections 1024;
7
+ }
8
+
9
+ http {
10
+ access_log /home/aim_user/nginx_logs/access.log; # Needs a path writable by aim_user
11
+
12
+ server {
13
+ listen 7860;
14
+ server_name localhost;
15
+
16
+ location / {
17
+ proxy_pass http://127.0.0.1:43800;
18
+ proxy_set_header Host $host;
19
+ proxy_set_header X-Real-IP $remote_addr;
20
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
21
+ proxy_set_header X-Forwarded-Proto $scheme;
22
+ # Add WebSocket support for Aim UI
23
+ proxy_http_version 1.1;
24
+ proxy_set_header Upgrade $http_upgrade;
25
+ proxy_set_header Connection "upgrade";
26
+ }
27
+
28
+ location /api/ {
29
+ proxy_pass http://127.0.0.1:53800/api/; # Pass requests to aim server API
30
+ proxy_set_header Host $host;
31
+ proxy_set_header X-Real-IP $remote_addr;
32
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
33
+ proxy_set_header X-Forwarded-Proto $scheme;
34
+ }
35
+ }
36
+ }
start.sh ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Create directories for nginx logs and pid file within $HOME
4
+ mkdir -p $HOME/nginx_run $HOME/nginx_logs
5
+
6
+ # Start Aim UI in the background
7
+ echo "Starting Aim UI on port 43800..."
8
+ # Run directly as aim_user
9
+ aim up --host 0.0.0.0 --port 43800 --repo $HOME &
10
+ AIM_UP_PID=$!
11
+
12
+ # Start Aim Server in the background
13
+ echo "Starting Aim Server on port 53800..."
14
+ # Run directly as aim_user
15
+ aim server --host 0.0.0.0 --port 53800 --repo $HOME &
16
+ AIM_SERVER_PID=$!
17
+
18
+ # Wait a few seconds for services to potentially start
19
+ sleep 5
20
+
21
+ # Check if aim processes are still running
22
+ if ! ps -p $AIM_UP_PID > /dev/null; then
23
+ echo "Aim UI failed to start." >&2
24
+ # exit 1 # Optional: exit if a service fails
25
+ fi
26
+
27
+ if ! ps -p $AIM_SERVER_PID > /dev/null; then
28
+ echo "Aim Server failed to start." >&2
29
+ # exit 1 # Optional: exit if a service fails
30
+ fi
31
+
32
+ echo "Aim services seem to be starting..."
33
+
34
+ # Start nginx in the foreground using the system config file
35
+ # Run directly as aim_user (no sudo needed)
36
+ echo "Starting nginx..."
37
+ nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
38
+
39
+ # If nginx exits, stop the background aim processes
40
+ echo "Nginx exited. Stopping Aim services..."
41
+ # Use kill without sudo, as processes are owned by aim_user
42
+ kill $AIM_UP_PID $AIM_SERVER_PID
43
+ # Wait for processes to ensure they are terminated
44
+ wait $AIM_UP_PID $AIM_SERVER_PID
45
+
46
+ echo "Exiting."