File size: 3,253 Bytes
7d78419
5c3ba51
f154923
7d78419
2e3b47f
f154923
094830a
 
 
 
 
 
f154923
 
7d78419
094830a
5c3ba51
f154923
094830a
 
 
 
 
 
 
 
 
 
 
 
 
 
5c3ba51
 
094830a
 
 
 
 
5c3ba51
 
094830a
f154923
5c3ba51
094830a
f154923
 
 
 
 
8e095ab
094830a
8e095ab
f154923
 
2e3b47f
7d78419
2e3b47f
 
094830a
f154923
 
 
094830a
f154923
 
 
 
 
 
094830a
f154923
 
 
 
 
 
 
094830a
7d78419
f154923
5c3ba51
7d78419
5c3ba51
094830a
 
 
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
FROM ubuntu:22.04

# 1. Environment Variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PUB_CACHE=/home/user/.pub-cache
ENV ANDROID_SDK_ROOT=/opt/android-sdk

# Browser environment variables
ENV CHROME_BIN=/usr/bin/chromium-browser
ENV CHROMIUM_FLAGS="--no-sandbox --disable-dev-shm-usage --disable-gpu --headless"
ENV DISPLAY=:99

# Merged PATH for Flutter, Dart, and Android Tools
ENV PATH="/opt/flutter/bin:/opt/flutter/bin/cache/dart-sdk/bin:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin:${ANDROID_SDK_ROOT}/platform-tools:${PATH}"

# 2. Install System Dependencies + Chromium + Virtual Display
RUN apt-get update && apt-get install -y \
    curl git unzip xz-utils zip libglu1-mesa python3 python3-pip wget openjdk-17-jdk \
    # Chromium browser
    chromium-browser \
    # Virtual display (needed for non-headless fallback)
    xvfb \
    # Chromium runtime dependencies
    libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 \
    libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
    libxrandr2 libgbm1 libasound2 libpango-1.0-0 libpangocairo-1.0-0 \
    libgtk-3-0 libx11-xcb1 \
    # Python headless browser tools
    && pip3 install --no-cache-dir \
        selenium \
        playwright \
        pyppeteer \
    && rm -rf /var/lib/apt/lists/*

# 3. Install Playwright browsers (Chromium via Playwright)
RUN python3 -m playwright install chromium \
    && python3 -m playwright install-deps chromium

# 4. Install code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh

# 5. Install Flutter SDK
RUN git clone https://github.com/flutter/flutter.git /opt/flutter

# 6. Install Android SDK Command Line Tools
RUN mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools && \
    wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O /tmp/tools.zip && \
    unzip /tmp/tools.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools && \
    mv ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools ${ANDROID_SDK_ROOT}/cmdline-tools/latest && \
    rm /tmp/tools.zip

# 7. Setup User and Permissions
RUN useradd -m -u 1000 user && \
    chown -R user:user /opt/flutter && \
    chown -R user:user ${ANDROID_SDK_ROOT}

USER user
WORKDIR /home/user

# 8. Configure Android SDK & Licenses
RUN yes | sdkmanager --licenses && \
    sdkmanager "platform-tools" "platforms;android-34" "build-tools;34.0.0"

# 9. Activate Flutter and Extensions
RUN flutter config --android-sdk ${ANDROID_SDK_ROOT} && \
    flutter precache && \
    flutter doctor && \
    code-server --install-extension dart-code.flutter && \
    code-server --install-extension dart-code.dart-code

# 10. Optional: Pre-configure VS Code Settings
RUN mkdir -p /home/user/.local/share/code-server/User && \
    echo '{ \
    "dart.flutterSdkPath": "/opt/flutter", \
    "dart.sdkPath": "/opt/flutter/bin/cache/dart-sdk", \
    "python.defaultInterpreterPath": "/usr/bin/python3" \
    }' > /home/user/.local/share/code-server/User/settings.json

# 11. Final Setup
COPY --chown=user requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt || echo "No requirements.txt found, skipping..."

EXPOSE 7860

# Start Xvfb virtual display + code-server
CMD Xvfb :99 -screen 0 1280x720x24 -ac & \
    code-server --bind-addr 0.0.0.0:7860 --auth none .