Sachin5112 commited on
Commit
a5eee2e
·
verified ·
1 Parent(s): c3a0f5b

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile.txt +93 -0
  2. entrypoint.sh +36 -0
  3. run.sh +8 -0
  4. sync.conf.txt +6 -0
  5. sync.py +39 -0
Dockerfile.txt ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM dorowu/ubuntu-desktop-lxde-vnc:latest
2
+
3
+ ENV RESOLUTION=1600x720
4
+ WORKDIR /workspace
5
+
6
+ # 1. Fix Repos & Install Tools
7
+ RUN rm -f /etc/apt/sources.list.d/google-chrome.list && \
8
+ apt-get update && apt-get install -y python3-pip git-lfs && \
9
+ pip3 install huggingface_hub[hf_transfer]
10
+
11
+ # 2. Setup User & Ports
12
+ RUN sed -i 's/listen 80 default_server;/listen 7860 default_server;/' /etc/nginx/sites-enabled/default
13
+ RUN useradd -m -u 1000 user || echo "User exists"
14
+
15
+ # 3. Pre-create permanent subfolders
16
+ RUN mkdir -p /workspace/storage/Desktop \
17
+ /workspace/storage/Documents \
18
+ /workspace/storage/Downloads \
19
+ /var/log/supervisor
20
+
21
+ # 4. Link user folders to permanent storage
22
+ RUN rm -rf /home/user/Desktop /home/user/Documents /home/user/Downloads && \
23
+ ln -s /workspace/storage/Desktop /home/user/Desktop && \
24
+ ln -s /workspace/storage/Documents /home/user/Documents && \
25
+ ln -s /workspace/storage/Downloads /home/user/Downloads
26
+
27
+ # Link config folders for user
28
+ RUN mkdir -p /workspace/storage/.config /workspace/storage/.local && \
29
+ rm -rf /home/user/.config /home/user/.local && \
30
+ ln -s /workspace/storage/.config /home/user/.config && \
31
+ ln -s /workspace/storage/.local /home/user/.local
32
+
33
+ # Link config folders for root
34
+ RUN mkdir -p /workspace/storage/settings/.config /workspace/storage/settings/.local && \
35
+ rm -rf /root/.config /root/.local && \
36
+ ln -s /workspace/storage/settings/.config /root/.config && \
37
+ ln -s /workspace/storage/settings/.local /root/.local
38
+
39
+ # 5. Set Permissions
40
+ RUN chmod -R 777 /workspace /home/user /var/log/supervisor
41
+
42
+ # 6. Copy Configs
43
+ COPY sync.py /workspace/sync.py
44
+ COPY sync.conf /etc/supervisor/conf.d/sync.conf
45
+ RUN chmod +x /workspace/sync.py
46
+
47
+ # Copy entrypoint script
48
+ COPY entrypoint.sh /workspace/entrypoint.sh
49
+ RUN chmod +x /workspace/entrypoint.sh
50
+
51
+ # Add this to your Dockerfile to fix the Chrome command globally
52
+ RUN echo 'alias google-chrome="google-chrome --no-sandbox --disable-dev-shm-usage"' >> /root/.bashrc
53
+
54
+ # Add this to your Dockerfile to always get the latest Chrome
55
+ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
56
+ echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \
57
+ apt-get update && \
58
+ apt-get install -y google-chrome-stable
59
+
60
+ # This version includes the new safety bypass for WebGL
61
+ RUN mv /usr/bin/google-chrome-stable /usr/bin/google-chrome-original && \
62
+ echo '#!/bin/bash\n/usr/bin/google-chrome-original \
63
+ --no-sandbox \
64
+ --disable-dev-shm-usage \
65
+ --ignore-gpu-blocklist \
66
+ --enable-webgl \
67
+ --use-gl=angle \
68
+ --use-angle=swiftshader \
69
+ --enable-unsafe-swiftshader \
70
+ --enable-accelerated-2d-canvas \
71
+ "$@"' > /usr/bin/google-chrome-stable && \
72
+ chmod +x /usr/bin/google-chrome-stable
73
+
74
+ # 1. Add Mozilla PPA and Install Latest Firefox
75
+ RUN apt-get update && apt-get install -y software-properties-common && \
76
+ add-apt-repository -y ppa:mozillateam/ppa && \
77
+ echo 'Package: *\nPin: release o=LP-PPA-mozillateam\nPin-Priority: 1001' > /etc/apt/preferences.d/mozilla-firefox && \
78
+ apt-get update && apt-get install -y firefox
79
+
80
+ # 2. Create the Firefox WebGL Wrapper
81
+ # We force-enable WebGL so it works without a real Graphics Card
82
+ RUN mv /usr/bin/firefox /usr/bin/firefox-original && \
83
+ echo '#!/bin/bash\n\
84
+ export MOZ_GFX_SWR_AS_GPU=1\n\
85
+ export MOZ_WEBRENDER=0\n\
86
+ /usr/bin/firefox-original \
87
+ --new-instance \
88
+ --no-remote \
89
+ "$@"' > /usr/bin/firefox && \
90
+ chmod +x /usr/bin/firefox
91
+
92
+ # Final entrypoint
93
+ ENTRYPOINT ["/workspace/entrypoint.sh"]
entrypoint.sh ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # 1. Force an immediate pull of the dataset before anything else starts
4
+ echo "Pulling permanent storage..."
5
+ python3 -c "
6
+ import os
7
+ from huggingface_hub import snapshot_download
8
+ TOKEN = os.environ.get('HF_TOKEN')
9
+ REPO_ID = 'Sachin5112/Temp-storage'
10
+ snapshot_download(repo_id=REPO_ID, repo_type='dataset', local_dir='/workspace/storage', token=TOKEN)
11
+ "
12
+
13
+ # 2. Ensure the links are correct
14
+ mkdir -p /workspace/storage/settings/.config
15
+ rm -rf /root/.config
16
+ ln -s /workspace/storage/settings/.config /root/.config
17
+
18
+ # 3. Now start the background sync script
19
+ python3 -u /workspace/sync.py &
20
+
21
+ # Add this line to bypass sandbox for most Electron/Chrome apps
22
+ export ELECTRON_DISABLE_SANDBOX=1
23
+
24
+ # Create a desktop shortcut for Chrome
25
+ mkdir -p /workspace/storage/Desktop
26
+ echo "[Desktop Entry]
27
+ Type=Application
28
+ Name=Google Chrome
29
+ Exec=google-chrome-stable
30
+ Icon=google-chrome
31
+ Terminal=false" > /workspace/storage/Desktop/chrome.desktop
32
+
33
+ chmod +x /workspace/storage/Desktop/chrome.desktop
34
+
35
+ # 4. Finally, start the VNC Desktop
36
+ /startup.sh
run.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # 1. Start the sync script in the background
4
+ # -u makes sure logs show up immediately
5
+ python3 -u /workspace/sync.py &
6
+
7
+ # 2. Start the VNC desktop (the main process)
8
+ /startup.sh
sync.conf.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [program:sync]
2
+ command=python3 -u /workspace/sync.py
3
+ autostart=true
4
+ autorestart=true
5
+ stderr_logfile=/var/log/sync.err.log
6
+ stdout_logfile=/var/log/sync.out.log
sync.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ from huggingface_hub import HfApi, snapshot_download
4
+
5
+ # --- CONFIG ---
6
+ REPO_ID = "Sachin5112/Temp-storage"
7
+ LOCAL_DIR = "/workspace/storage" # STICK TO THIS
8
+ TOKEN = os.environ.get("HF_TOKEN")
9
+
10
+ api = HfApi(token=TOKEN)
11
+
12
+ def pull():
13
+ try:
14
+ if not os.path.exists(LOCAL_DIR):
15
+ os.makedirs(LOCAL_DIR)
16
+ print("Pulling data from HF...")
17
+ snapshot_download(repo_id=REPO_ID, repo_type="dataset", local_dir=LOCAL_DIR, token=TOKEN)
18
+ print("Pull Success.")
19
+ except Exception as e:
20
+ print(f"Pull Error: {e}")
21
+
22
+ def push():
23
+ try:
24
+ print("Checking for changes...")
25
+ api.upload_folder(
26
+ folder_path=LOCAL_DIR,
27
+ repo_id=REPO_ID,
28
+ repo_type="dataset",
29
+ delete_patterns="*", # This ensures deleted files on VNC are deleted on HF
30
+ )
31
+ print("Backup Success.")
32
+ except Exception as e:
33
+ print(f"Backup Error: {e}")
34
+
35
+ pull()
36
+
37
+ while True:
38
+ time.sleep(60) # 1 minute is much safer than 1 second
39
+ push()