diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..d03857f86a --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,80 @@ +FROM ubuntu:latest + +ENV GBP_USER ${GBP_USER:-gbp} +ENV GBP_USER_ID ${GBP_USER_ID:-1000} + +WORKDIR /app + +USER root + +RUN apt-get update && apt-get install -y --no-install-recommends curl wget gnupg2 ca-certificates supervisor + +# Install xcfb +RUN apt-get install -y --no-install-recommends xvfb xauth pulseaudio + +# Install locales +RUN apt-get install -y --no-install-recommends language-pack-en tzdata locales && \ + locale-gen en_US.UTF-8 + +# Install fluxbox +RUN apt-get install -y --no-install-recommends fluxbox eterm hsetroot feh + +# Install Edge +RUN wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg >/dev/null \ + && echo "deb https://packages.microsoft.com/repos/edge stable main" >> /etc/apt/sources.list.d/microsoft-edge.list \ + && apt-get update -qqy \ + && apt-get -qqy --no-install-recommends install microsoft-edge-stable +COPY wrap_edge_binary /opt/bin/wrap_edge_binary +RUN /opt/bin/wrap_edge_binary + +RUN curl -L https://github.com/Harry-zklcdc/go-proxy-bingai/releases/latest/download/go-proxy-bingai-linux-amd64.tar.gz -o go-proxy-bingai-linux-amd64.tar.gz && \ + tar -zxvf go-proxy-bingai-linux-amd64.tar.gz && \ + chmod +x go-proxy-bingai + +RUN curl -L https://github.com/Harry-zklcdc/go-bingai-pass/releases/latest/download/go-bingai-pass-linux-amd64.tar.gz -o go-bingai-pass-linux-amd64.tar.gz && \ + tar -zxvf go-bingai-pass-linux-amd64.tar.gz && \ + chmod +x go-bingai-pass + +RUN curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o cloudflared && \ + chmod +x cloudflared + +RUN apt-get remove -y curl && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + rm go-proxy-bingai-linux-amd64.tar.gz && \ + rm go-bingai-pass-linux-amd64.tar.gz + +COPY start-xvfb.sh /opt/bin/start-xvfb.sh +COPY supervisor.conf /etc/supervisor/conf.d/supervisor.conf + +RUN groupadd -g $GBP_USER_ID $GBP_USER +RUN useradd -rm -G sudo -u $GBP_USER_ID -g $GBP_USER_ID $GBP_USER + +RUN mkdir -p /tmp/edge /var/run/supervisor /var/log/supervisor +RUN chown "${GBP_USER_ID}:${GBP_USER_ID}" /var/run/supervisor /var/log/supervisor +RUN chown -R "${GBP_USER_ID}:${GBP_USER_ID}" /app /tmp/edge +RUN chmod 777 /tmp + +USER $GBP_USER + +ENV SCREEN_WIDTH=1360 +ENV SCREEN_HEIGHT=1020 +ENV SCREEN_DEPTH=24 +ENV SCREEN_DPI=96 +ENV SE_START_XVFB=true +ENV DISPLAY=:99.0 +ENV DISPLAY_NUM=99 + +ENV HEADLESS=false +ENV BROWSER_BINARY=/usr/bin/microsoft-edge +# ENV PASS_TIMEOUT=10 +# ENV CHROME_PATH=/opt/google/chrome +ENV XDG_CONFIG_HOME=/tmp/edge +ENV XDG_CACHE_HOME=/tmp/edge + +ENV PORT=7860 +ENV BYPASS_SERVER=http://localhost:8080 + +EXPOSE 7860 + +CMD /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisor.conf \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..2ca0aba87f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,4 @@ +{ + "dockerComposeFile": "docker-compose.yml", + "service": "go-proxy-bingai", +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000000..1cb89e15e7 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,10 @@ +services: + go-proxy-bingai: + build: + context: . + dockerfile: Dockerfile + environment: + - HEADLESS=false + - PASS_TIMEOUT=5 + ports: + - 7860:7860 \ No newline at end of file diff --git a/.devcontainer/start-xvfb.sh b/.devcontainer/start-xvfb.sh new file mode 100755 index 0000000000..270af04560 --- /dev/null +++ b/.devcontainer/start-xvfb.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then + export GEOMETRY="${SCREEN_WIDTH}""x""${SCREEN_HEIGHT}""x""${SCREEN_DEPTH}" + + rm -f /tmp/.X*lock + + # Command reference + # http://manpages.ubuntu.com/manpages/focal/man1/xvfb-run.1.html + # http://manpages.ubuntu.com/manpages/focal/man1/Xvfb.1.html + # http://manpages.ubuntu.com/manpages/focal/man1/Xserver.1.html + /usr/bin/xvfb-run --server-num=${DISPLAY_NUM} \ + --listen-tcp \ + --server-args="-screen 0 ${GEOMETRY} -fbdir /var/tmp -dpi ${SCREEN_DPI} -listen tcp -noreset -ac +extension RANDR" \ + /usr/bin/fluxbox -display ${DISPLAY} +else + echo "Xvfb and Fluxbox won't start. Chrome/Firefox/Edge can only run in headless mode. Remember to set the 'headless' flag in your test." +fi \ No newline at end of file diff --git a/.devcontainer/supervisor.conf b/.devcontainer/supervisor.conf new file mode 100644 index 0000000000..fc7c2c1240 --- /dev/null +++ b/.devcontainer/supervisor.conf @@ -0,0 +1,69 @@ +[supervisord] +logfile=/var/log/supervisor/supervisord.log +logfile_maxbytes=10MB +logfile_backups=10 +loglevel=info +pidfile=/var/run/supervisor/supervisord.pid +nodaemon=true +childlogdir=/var/log/supervisor + +[inet_http_server] +port=127.0.0.1:9005 + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl=http://127.0.0.1:9005 + +[program:xvfb] +priority=0 +environment=START_XVFB=true +command=/opt/bin/start-xvfb.sh +autostart=true +autorestart=true + +;Logs +redirect_stderr=false +stdout_logfile=/var/log/supervisor/xvfb-stdout.log +stderr_logfile=/var/log/supervisor/xvfb-stderr.log +stdout_logfile_maxbytes=50MB +stderr_logfile_maxbytes=50MB +stdout_logfile_backups=5 +stderr_logfile_backups=5 +stdout_capture_maxbytes=50MB +stderr_capture_maxbytes=50MB + +[program:go-bingai-pass] +command=/app/go-bingai-pass +environment=PORT=8080 +directory=/app +stdout_logfile=/dev/stdout +stderr_logfile=/dev/stderr +autostart=true +autorestart=true +startsecs=5 +stopwaitsecs = 5 +killasgroup=true + +[program:go-proxy-bingai] +command=/app/go-proxy-bingai +directory=/app +stdout_logfile=/dev/stdout +stderr_logfile=/dev/stderr +autostart=true +autorestart=true +startsecs=5 +stopwaitsecs = 5 +killasgroup=true + +[program:cloudflared] +command=/app/cloudflared tunnel --no-autoupdate run --token %(ENV_CF_ZERO_TRUST_TOKEN)s +directory=/app +stdout_logfile=/dev/stdout +stderr_logfile=/dev/stderr +autostart=true +autorestart=true +startsecs=5 +stopwaitsecs = 5 +killasgroup=true \ No newline at end of file diff --git a/.devcontainer/wrap_edge_binary b/.devcontainer/wrap_edge_binary new file mode 100755 index 0000000000..aea41c8db2 --- /dev/null +++ b/.devcontainer/wrap_edge_binary @@ -0,0 +1,27 @@ +#!/bin/bash + +WRAPPER_PATH=$(readlink -f /usr/bin/microsoft-edge) +BASE_PATH="$WRAPPER_PATH-base" +mv "$WRAPPER_PATH" "$BASE_PATH" + +cat > "$WRAPPER_PATH" <<_EOF +#!/bin/bash + +# umask 002 ensures default permissions of files are 664 (rw-rw-r--) and directories are 775 (rwxrwxr-x). +umask 002 + +# Debian/Ubuntu seems to not respect --lang, it instead needs to be a LANGUAGE environment var +# See: https://stackoverflow.com/a/41893197/359999 +for var in "\$@"; do + if [[ \$var == --lang=* ]]; then + LANGUAGE=\${var//--lang=} + fi +done + +# Set language environment variable +export LANGUAGE="\$LANGUAGE" + +# Note: exec -a below is a bashism. +exec -a "\$0" "$BASE_PATH" --no-sandbox "\$@" +_EOF +chmod +x "$WRAPPER_PATH" \ No newline at end of file