NitinBot001 commited on
Commit
10d245e
·
verified ·
1 Parent(s): 165536f

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +122 -0
Dockerfile ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Ubuntu as base image for better Docker-in-Docker support
2
+ FROM ubuntu:22.04
3
+
4
+ # Avoid prompts from apt
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y \
9
+ curl \
10
+ git \
11
+ sudo \
12
+ ca-certificates \
13
+ gnupg \
14
+ lsb-release \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ # Install Docker
18
+ RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
19
+ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
20
+ && apt-get update \
21
+ && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin \
22
+ && rm -rf /var/lib/apt/lists/*
23
+
24
+ # Create non-root user
25
+ RUN useradd -m -s /bin/bash -u 1001 firecrawl \
26
+ && usermod -aG docker firecrawl \
27
+ && echo 'firecrawl ALL=(ALL) NOPASSWD: /usr/bin/dockerd' >> /etc/sudoers
28
+
29
+ # Set working directory
30
+ WORKDIR /home/firecrawl
31
+
32
+ # Switch to non-root user for cloning
33
+ USER firecrawl
34
+
35
+ # Clone Firecrawl repository
36
+ RUN git clone https://github.com/mendableai/firecrawl.git /home/firecrawl/firecrawl
37
+
38
+ # Set working directory to firecrawl
39
+ WORKDIR /home/firecrawl/firecrawl
40
+
41
+ # Copy .env.example to .env in the API directory
42
+ RUN if [ -f apps/api/.env.example ]; then \
43
+ cp apps/api/.env.example apps/api/.env; \
44
+ fi
45
+
46
+ # Create startup script
47
+ USER root
48
+ RUN cat > /start-firecrawl.sh << 'EOF'
49
+ #!/bin/bash
50
+ set -e
51
+
52
+ echo "🔥 Starting Firecrawl Self-Host Setup 🔥"
53
+ echo "==========================================="
54
+
55
+ # Start Docker daemon in background if not running
56
+ if ! pgrep dockerd > /dev/null; then
57
+ echo "Starting Docker daemon..."
58
+ sudo dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2376 &
59
+ sleep 5
60
+ fi
61
+
62
+ # Wait for Docker to be ready
63
+ echo "Waiting for Docker to be ready..."
64
+ timeout=30
65
+ while [ $timeout -gt 0 ]; do
66
+ if docker info > /dev/null 2>&1; then
67
+ echo "Docker is ready!"
68
+ break
69
+ fi
70
+ sleep 1
71
+ timeout=$((timeout-1))
72
+ done
73
+
74
+ if [ $timeout -eq 0 ]; then
75
+ echo "Error: Docker failed to start within 30 seconds"
76
+ exit 1
77
+ fi
78
+
79
+ cd /home/firecrawl/firecrawl
80
+
81
+ echo "Prerequisites check:"
82
+ echo "✓ Docker and Docker Compose are installed"
83
+ echo "✓ Repository cloned to /home/firecrawl/firecrawl"
84
+
85
+ if [ -f apps/api/.env ]; then
86
+ echo "✓ Environment file exists at apps/api/.env"
87
+ else
88
+ echo "⚠ No .env file found, using defaults"
89
+ fi
90
+
91
+ echo ""
92
+ echo "Building Firecrawl services..."
93
+ echo "Running: docker compose build"
94
+ docker compose build
95
+
96
+ echo ""
97
+ echo "Starting Firecrawl services..."
98
+ echo "Running: docker compose up"
99
+ echo ""
100
+
101
+ # Run docker compose
102
+ exec docker compose up "$@"
103
+ EOF
104
+
105
+ RUN chmod +x /start-firecrawl.sh \
106
+ && chown firecrawl:firecrawl /start-firecrawl.sh
107
+
108
+ # Switch back to non-root user
109
+ USER firecrawl
110
+
111
+ # Expose common ports used by Firecrawl
112
+ EXPOSE 3002 8080 6379 5432
113
+
114
+ # Health check
115
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
116
+ CMD docker compose ps -q | xargs docker inspect --format='{{.State.Health.Status}}' | grep -v healthy && exit 1 || exit 0
117
+
118
+ # Set entrypoint
119
+ ENTRYPOINT ["/start-firecrawl.sh"]
120
+
121
+ # Default command (can be overridden)
122
+ CMD []