mfoud444 commited on
Commit
3080785
1 Parent(s): abe4874
Files changed (2) hide show
  1. Dockerfile +137 -98
  2. app.py +20 -0
Dockerfile CHANGED
@@ -1,98 +1,137 @@
1
- FROM selenium/node-chrome
2
-
3
- ARG G4F_VERSION
4
- ARG G4F_USER=g4f
5
- ARG G4F_USER_ID=1000
6
- ARG G4F_NO_GUI
7
- ARG G4F_PASS=secret
8
-
9
- ENV G4F_VERSION $G4F_VERSION
10
- ENV G4F_USER $G4F_USER
11
- ENV G4F_USER_ID $G4F_USER_ID
12
- ENV G4F_NO_GUI $G4F_NO_GUI
13
-
14
- ENV SE_SCREEN_WIDTH 1850
15
- ENV PYTHONUNBUFFERED 1
16
- ENV G4F_DIR /app
17
- ENV G4F_LOGIN_URL http://localhost:7900/?autoconnect=1&resize=scale&password=$G4F_PASS
18
- ENV HOME /home/$G4F_USER
19
- ENV PATH $PATH:$HOME/.local/bin
20
- ENV SE_DOWNLOAD_DIR $HOME/Downloads
21
- ENV SEL_USER $G4F_USER
22
- ENV SEL_UID $G4F_USER_ID
23
- ENV SEL_GID $G4F_USER_ID
24
-
25
- USER root
26
-
27
- # If docker compose, install git
28
- RUN if [ "$G4F_VERSION" = "" ] ; then \
29
- apt-get -qqy update && \
30
- apt-get -qqy install git \
31
- ; fi
32
-
33
- # Python packages
34
- RUN apt-get -qqy update \
35
- && apt-get -qqy install \
36
- python3 \
37
- python-is-python3 \
38
- pip
39
-
40
- # Remove java
41
- RUN apt-get -qyy remove openjdk-11-jre-headless
42
-
43
- # Cleanup
44
- RUN rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
45
- && apt-get -qyy autoremove \
46
- && apt-get -qyy clean
47
-
48
- # Update entrypoint
49
- COPY docker/supervisor.conf /etc/supervisor/conf.d/selenium.conf
50
- COPY docker/supervisor-gui.conf /etc/supervisor/conf.d/gui.conf
51
-
52
- # If no gui
53
- RUN if [ "$G4F_NO_GUI" ] ; then \
54
- rm /etc/supervisor/conf.d/gui.conf \
55
- ; fi
56
-
57
- # Change background image
58
- COPY docker/background.png /usr/share/images/fluxbox/ubuntu-light.png
59
-
60
- # Add user
61
- RUN groupadd -g $G4F_USER_ID $G4F_USER \
62
- && useradd -rm -G sudo -u $G4F_USER_ID -g $G4F_USER_ID $G4F_USER \
63
- && echo "${G4F_USER}:${G4F_PASS}" | chpasswd
64
-
65
- # Fix permissions
66
- RUN mkdir "${SE_DOWNLOAD_DIR}"
67
- RUN chown "${G4F_USER_ID}:${G4F_USER_ID}" $SE_DOWNLOAD_DIR /var/run/supervisor /var/log/supervisor
68
- RUN chown "${G4F_USER_ID}:${G4F_USER_ID}" -R /opt/bin/ /usr/bin/chromedriver /opt/selenium/
69
-
70
- # Switch user
71
- USER $G4F_USER_ID
72
-
73
- # Set VNC password
74
- RUN mkdir -p ${HOME}/.vnc \
75
- && x11vnc -storepasswd ${G4F_PASS} ${HOME}/.vnc/passwd
76
-
77
- # Set the working directory in the container.
78
- WORKDIR $G4F_DIR
79
-
80
- # Copy the project's requirements file into the container.
81
- COPY requirements.txt $G4F_DIR
82
- COPY s.py $G4F_DIR
83
- # Upgrade pip for the latest features and install the project's Python dependencies.
84
- RUN pip install --upgrade pip && pip install -r requirements.txt
85
-
86
- # Copy the entire package into the container.
87
- ADD --chown=$G4F_USER:$G4F_USER g4f $G4F_DIR/g4f
88
- RUN ls
89
- RUN chromedriver --version
90
- RUN which chromedriver
91
- RUN ls
92
-
93
- RUN ls
94
-
95
- RUN python s.py
96
-
97
- # Expose ports
98
- EXPOSE 80 7860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FROM selenium/node-chrome
2
+
3
+ # ARG G4F_VERSION
4
+ # ARG G4F_USER=g4f
5
+ # ARG G4F_USER_ID=1000
6
+ # ARG G4F_NO_GUI
7
+ # ARG G4F_PASS=secret
8
+
9
+ # ENV G4F_VERSION $G4F_VERSION
10
+ # ENV G4F_USER $G4F_USER
11
+ # ENV G4F_USER_ID $G4F_USER_ID
12
+ # ENV G4F_NO_GUI $G4F_NO_GUI
13
+
14
+ # ENV SE_SCREEN_WIDTH 1850
15
+ # ENV PYTHONUNBUFFERED 1
16
+ # ENV G4F_DIR /app
17
+ # ENV G4F_LOGIN_URL http://localhost:7900/?autoconnect=1&resize=scale&password=$G4F_PASS
18
+ # ENV HOME /home/$G4F_USER
19
+ # ENV PATH $PATH:$HOME/.local/bin
20
+ # ENV SE_DOWNLOAD_DIR $HOME/Downloads
21
+ # ENV SEL_USER $G4F_USER
22
+ # ENV SEL_UID $G4F_USER_ID
23
+ # ENV SEL_GID $G4F_USER_ID
24
+
25
+ # USER root
26
+
27
+ # # If docker compose, install git
28
+ # RUN if [ "$G4F_VERSION" = "" ] ; then \
29
+ # apt-get -qqy update && \
30
+ # apt-get -qqy install git \
31
+ # ; fi
32
+
33
+ # # Python packages
34
+ # RUN apt-get -qqy update \
35
+ # && apt-get -qqy install \
36
+ # python3 \
37
+ # python-is-python3 \
38
+ # pip
39
+
40
+ # # Remove java
41
+ # RUN apt-get -qyy remove openjdk-11-jre-headless
42
+
43
+ # # Cleanup
44
+ # RUN rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
45
+ # && apt-get -qyy autoremove \
46
+ # && apt-get -qyy clean
47
+
48
+ # # Update entrypoint
49
+ # COPY docker/supervisor.conf /etc/supervisor/conf.d/selenium.conf
50
+ # COPY docker/supervisor-gui.conf /etc/supervisor/conf.d/gui.conf
51
+
52
+ # # If no gui
53
+ # RUN if [ "$G4F_NO_GUI" ] ; then \
54
+ # rm /etc/supervisor/conf.d/gui.conf \
55
+ # ; fi
56
+
57
+ # # Change background image
58
+ # COPY docker/background.png /usr/share/images/fluxbox/ubuntu-light.png
59
+
60
+ # # Add user
61
+ # RUN groupadd -g $G4F_USER_ID $G4F_USER \
62
+ # && useradd -rm -G sudo -u $G4F_USER_ID -g $G4F_USER_ID $G4F_USER \
63
+ # && echo "${G4F_USER}:${G4F_PASS}" | chpasswd
64
+
65
+ # # Fix permissions
66
+ # RUN mkdir "${SE_DOWNLOAD_DIR}"
67
+ # RUN chown "${G4F_USER_ID}:${G4F_USER_ID}" $SE_DOWNLOAD_DIR /var/run/supervisor /var/log/supervisor
68
+ # RUN chown "${G4F_USER_ID}:${G4F_USER_ID}" -R /opt/bin/ /usr/bin/chromedriver /opt/selenium/
69
+
70
+ # # Switch user
71
+ # USER $G4F_USER_ID
72
+
73
+ # # Set VNC password
74
+ # RUN mkdir -p ${HOME}/.vnc \
75
+ # && x11vnc -storepasswd ${G4F_PASS} ${HOME}/.vnc/passwd
76
+
77
+ # # Set the working directory in the container.
78
+ # WORKDIR $G4F_DIR
79
+
80
+ # # Copy the project's requirements file into the container.
81
+ # COPY requirements.txt $G4F_DIR
82
+ # COPY s.py $G4F_DIR
83
+ # # Upgrade pip for the latest features and install the project's Python dependencies.
84
+ # RUN pip install --upgrade pip && pip install -r requirements.txt
85
+
86
+ # # Copy the entire package into the container.
87
+ # ADD --chown=$G4F_USER:$G4F_USER g4f $G4F_DIR/g4f
88
+ # RUN ls
89
+ # RUN chromedriver --version
90
+ # RUN which chromedriver
91
+ # RUN ls
92
+
93
+ # RUN ls
94
+
95
+ # RUN python s.py
96
+
97
+ # # Expose ports
98
+ # EXPOSE 80 7860
99
+
100
+
101
+
102
+ FROM python:3.8
103
+
104
+ # Adding trusting keys to apt for repositories
105
+ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
106
+
107
+ # Adding Google Chrome to the repositories
108
+ RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
109
+
110
+ # Updating apt to see and install Google Chrome
111
+ RUN apt-get -y update
112
+
113
+ # Magic happens
114
+ RUN apt-get install -y google-chrome-stable
115
+
116
+ # Installing Unzip
117
+ RUN apt-get install -yqq unzip
118
+
119
+ # Download the Chrome Driver
120
+ RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`
121
+ curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE
122
+ `/chromedriver_linux64.zip
123
+
124
+ # Unzip the Chrome Driver into /usr/local/bin directory
125
+ RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
126
+
127
+ COPY . /app
128
+ WORKDIR /app
129
+
130
+ RUN pip install --upgrade pip
131
+
132
+ RUN pip install -r requirements.txt
133
+
134
+ CMD ["python", "./app.py"]
135
+
136
+ # Set display port as an environment variable
137
+ ENV DISPLAY=:99
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from selenium.webdriver.chrome.options import Options
2
+ from selenium import webdriver
3
+
4
+ def set_chrome_options() -> Options:
5
+ """Sets chrome options for Selenium.
6
+ Chrome options for headless browser is enabled.
7
+ """
8
+ chrome_options = Options()
9
+ chrome_options.add_argument("--headless")
10
+ chrome_options.add_argument("--no-sandbox")
11
+ chrome_options.add_argument("--disable-dev-shm-usage")
12
+ chrome_prefs = {}
13
+ chrome_options.experimental_options["prefs"] = chrome_prefs
14
+ chrome_prefs["profile.default_content_settings"] = {"images": 2}
15
+ return chrome_options
16
+
17
+ if __name__ == "__main__":
18
+ driver = webdriver.Chrome(options=set_chrome_options())
19
+ # Do stuff with your driver
20
+ driver.close()