Cam commited on
Commit
4d69b87
·
1 Parent(s): 4c8d706

change approach to docker file

Browse files
Files changed (2) hide show
  1. Dockerfile +18 -10
  2. setup.sh +16 -18
Dockerfile CHANGED
@@ -6,24 +6,29 @@ WORKDIR /app
6
  # Copy your code
7
  COPY . /app
8
 
9
- # Install dependencies with --user flag
10
- RUN pip install --no-cache-dir --user -r requirements.txt
11
 
12
- # Ensure proper permissions
13
- RUN mkdir -p /app/.phoenix /tmp/.phoenix /app/.guardrails /usr/local/bin && \
14
- chmod -R 777 /app/.phoenix /tmp/.phoenix /app/.guardrails /usr/local/bin && \
15
- chmod -R 777 /usr/local/lib/python3.10/site-packages
16
 
17
- # Create fallback implementations (keep your existing code)
 
 
 
 
18
  RUN mkdir -p /app/guardrails_fallback
19
  RUN echo 'class DetectJailbreak:\n def __init__(self, *args, **kwargs):\n print("Using fallback DetectJailbreak implementation")\n pass\n\nclass ToxicLanguage:\n def __init__(self, *args, **kwargs):\n print("Using fallback ToxicLanguage implementation")\n pass' > /app/guardrails_fallback/__init__.py
20
 
 
 
 
21
  # Create a non-root user
22
  RUN useradd -m -u 1000 appuser
23
 
24
- # Make the setup script executable and modify it to use --user flag
25
- RUN chmod +x /app/setup.sh
26
- RUN sed -i 's/pip install/pip install --user/g' /app/setup.sh
27
 
28
  # Change ownership
29
  RUN chown -R appuser:appuser /app /home/appuser
@@ -36,5 +41,8 @@ ENV PATH="/home/appuser/.local/bin:${PATH}"
36
  # Switch to non-root user
37
  USER appuser
38
 
 
 
 
39
  # Launch the app
40
  CMD ["streamlit", "run", "/app/app.py", "--server.port", "7860", "--server.address", "0.0.0.0"]
 
6
  # Copy your code
7
  COPY . /app
8
 
9
+ # First install critical packages system-wide
10
+ RUN pip install --no-cache-dir streamlit guardrails-ai
11
 
12
+ # Set proper permissions for system directories where packages get installed
13
+ RUN mkdir -p /usr/local/bin && chmod -R 777 /usr/local/bin
14
+ RUN chmod -R 777 /usr/local/lib/python3.10/site-packages
 
15
 
16
+ # Create necessary directories with appropriate permissions
17
+ RUN mkdir -p /app/.phoenix /tmp/.phoenix /app/.guardrails && \
18
+ chmod -R 777 /app/.phoenix /tmp/.phoenix /app/.guardrails
19
+
20
+ # Create fallback implementations
21
  RUN mkdir -p /app/guardrails_fallback
22
  RUN echo 'class DetectJailbreak:\n def __init__(self, *args, **kwargs):\n print("Using fallback DetectJailbreak implementation")\n pass\n\nclass ToxicLanguage:\n def __init__(self, *args, **kwargs):\n print("Using fallback ToxicLanguage implementation")\n pass' > /app/guardrails_fallback/__init__.py
23
 
24
+ # Make the setup script executable
25
+ RUN chmod +x /app/setup.sh
26
+
27
  # Create a non-root user
28
  RUN useradd -m -u 1000 appuser
29
 
30
+ # Install remaining dependencies (can use system or user install)
31
+ RUN pip install --no-cache-dir -r requirements.txt
 
32
 
33
  # Change ownership
34
  RUN chown -R appuser:appuser /app /home/appuser
 
41
  # Switch to non-root user
42
  USER appuser
43
 
44
+ # Expose the port for Streamlit
45
+ EXPOSE 7860
46
+
47
  # Launch the app
48
  CMD ["streamlit", "run", "/app/app.py", "--server.port", "7860", "--server.address", "0.0.0.0"]
setup.sh CHANGED
@@ -1,23 +1,21 @@
1
  #!/bin/bash
2
- # setup.sh - Run once when the Streamlit app starts
3
 
4
- echo "Starting setup process..."
5
 
6
- # Check for Guardrails token
7
- if [ ! -z "$GUARDRAILS_TOKEN" ]; then
8
- echo "Configuring Guardrails with token..."
9
- # Clean the token and configure
10
- CLEAN_TOKEN=$(echo $GUARDRAILS_TOKEN | tr -d "\"' \n\t")
11
-
12
- # Configure guardrails
13
- guardrails configure --token "$CLEAN_TOKEN" --enable-metrics --enable-remote-inferencing
14
-
15
- # Install validators
16
- echo "Installing Guardrails validators..."
17
- guardrails hub install hub://guardrails/detect_jailbreak || echo "Failed to install detect_jailbreak validator"
18
- guardrails hub install hub://guardrails/toxic_language || echo "Failed to install toxic_language validator"
19
- else
20
- echo "No GUARDRAILS_TOKEN found. Skipping Guardrails setup."
21
- fi
22
 
23
  echo "Setup completed!"
 
1
  #!/bin/bash
 
2
 
3
+ echo "Setting up environment..."
4
 
5
+ # Configure guardrails with token
6
+ python -c "
7
+ import os
8
+ import guardrails as gd
9
+ try:
10
+ gd.configure(api_endpoint='https://api.guardrailsai.com', api_key=os.environ.get('GUARDRAILS_API_KEY', ''))
11
+ print('Guardrails configured successfully')
12
+ except Exception as e:
13
+ print(f'Warning: Could not configure guardrails: {e}')
14
+ "
15
+
16
+ # Try installing validators but don't fail if they don't work
17
+ echo "Installing Guardrails validators..."
18
+ guardrails hub install hub://guardrails/detect_jailbreak || echo "Warning: Could not install detect_jailbreak validator"
19
+ guardrails hub install hub://guardrails/toxic_language || echo "Warning: Could not install toxic_language validator"
 
20
 
21
  echo "Setup completed!"