tanbushi commited on
Commit
0f2d026
·
1 Parent(s): a3c641f
Files changed (1) hide show
  1. Dockerfile +25 -27
Dockerfile CHANGED
@@ -1,49 +1,47 @@
1
  # Use Node.js 20 LTS as base image
2
  FROM node:20-alpine
3
 
4
- # Set environment variables
 
 
 
 
 
5
  ENV NODE_ENV=production
6
  ENV PORT=7860
7
 
8
  # Install git and other system dependencies
9
  RUN apk add --no-cache git curl
10
 
11
- # Create app directory
12
  WORKDIR /app
13
 
14
- # Install opencode globally and verify location
15
- RUN npm install -g opencode-ai@latest && \
16
- which opencode && \
17
- ls -la $(which opencode)
18
-
19
- # Create a non-root user
20
- RUN addgroup -g 1001 -S opencode && \
21
- adduser -S opencode -u 1001
22
 
23
- # Change ownership of the app directory and create workspace
 
24
  RUN chown -R opencode:opencode /app && \
25
- mkdir -p /home/opencode/workspace && \
26
- chown -R opencode:opencode /home/opencode/workspace
27
 
28
- # Switch to non-root user (after creating startup script)
29
  USER opencode
30
 
31
- # Expose the port that HuggingFace Spaces expects
32
- EXPOSE 7860
33
-
34
- # Set the working directory for the user
35
- WORKDIR /home/opencode
36
 
37
- # Set working directory to workspace
38
- WORKDIR /home/opencode/workspace
39
-
40
- # Create startup script for web server
41
  RUN echo '#!/bin/sh\n\
42
  echo "Starting OpenCode AI Web Server..."\n\
43
  echo "Server will be available at http://0.0.0.0:7860"\n\
44
  echo "OpenAPI documentation available at http://0.0.0.0:7860/doc"\n\
45
- exec opencode serve --hostname 0.0.0.0 --port 7860\n\
46
- ' > /home/opencode/start.sh && chmod +x /home/opencode/start.sh
 
 
 
 
47
 
48
- # Default command - start web server with npm
49
- CMD ["npm", "exec", "opencode", "serve", "--hostname", "0.0.0.0", "--port", "7860"]
 
1
  # Use Node.js 20 LTS as base image
2
  FROM node:20-alpine
3
 
4
+ # Create a non-root user first
5
+ RUN addgroup -g 1000 -S opencode && \
6
+ adduser -S opencode -u 1000
7
+
8
+ # Set environment variables for user
9
+ ENV PATH="/home/opencode/.local/bin:/usr/local/bin:$PATH"
10
  ENV NODE_ENV=production
11
  ENV PORT=7860
12
 
13
  # Install git and other system dependencies
14
  RUN apk add --no-cache git curl
15
 
16
+ # Create workspace directory
17
  WORKDIR /app
18
 
19
+ # Install opencode globally as root
20
+ USER root
21
+ RUN npm install -g opencode-ai@latest
 
 
 
 
 
22
 
23
+ # Copy files and set ownership
24
+ COPY --chown=opencode:opencode . /app
25
  RUN chown -R opencode:opencode /app && \
26
+ chown -R opencode:opencode /home/opencode
 
27
 
28
+ # Switch to non-root user
29
  USER opencode
30
 
31
+ # Create user's bin directory
32
+ RUN mkdir -p /home/opencode/.local/bin
 
 
 
33
 
34
+ # Create startup script
 
 
 
35
  RUN echo '#!/bin/sh\n\
36
  echo "Starting OpenCode AI Web Server..."\n\
37
  echo "Server will be available at http://0.0.0.0:7860"\n\
38
  echo "OpenAPI documentation available at http://0.0.0.0:7860/doc"\n\
39
+ export PATH="/usr/local/bin:$PATH"\n\
40
+ exec /usr/local/bin/opencode serve --hostname 0.0.0.0 --port 7860\n\
41
+ ' > /home/opencode/.local/bin/start.sh && chmod +x /home/opencode/.local/bin/start.sh
42
+
43
+ # Expose the port that HuggingFace Spaces expects
44
+ EXPOSE 7860
45
 
46
+ # Default command - start web server
47
+ CMD ["/home/opencode/.local/bin/start.sh"]