Skip to content

Commit

Permalink
[Add] ⚙️ CodeSandbox Config
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-zklcdc committed Feb 7, 2024
1 parent 79555e0 commit 985beea
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dockerComposeFile": "docker-compose.yml",
"service": "go-proxy-bingai",
}
10 changes: 10 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
go-proxy-bingai:
build:
context: .
dockerfile: Dockerfile
environment:
- HEADLESS=false
- PASS_TIMEOUT=5
ports:
- 7860:7860
18 changes: 18 additions & 0 deletions .devcontainer/start-xvfb.sh
Original file line number Diff line number Diff line change
@@ -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
69 changes: 69 additions & 0 deletions .devcontainer/supervisor.conf
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .devcontainer/wrap_edge_binary
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 985beea

Please sign in to comment.