wwforonce commited on
Commit
81c3c4e
·
1 Parent(s): 30586c3

init docker

Browse files
Files changed (5) hide show
  1. .gitignore +2 -0
  2. Caddyfile +8 -0
  3. Dockerfile +17 -0
  4. add_bash_util.sh +109 -0
  5. run.sh +41 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .*
2
+ !.gitignore
Caddyfile ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ :7860 {
2
+ handle_path /8085/* {
3
+ reverse_proxy localhost:8085
4
+ }
5
+ # Serve your API, stripping the /api prefix
6
+ reverse_proxy localhost:3000
7
+
8
+ }
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:22
2
+
3
+ # Install packages
4
+ RUN apt-get update && apt-get install -y git curl wget jq
5
+
6
+
7
+ COPY ./run.sh /run.sh
8
+ COPY ./add_bash_util.sh /add_bash_util.sh
9
+ COPY ./Caddyfile /Caddyfile
10
+ # Expose ports
11
+
12
+ EXPOSE 7860
13
+
14
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s \
15
+ CMD curl -f http://localhost:7860/ || exit 1
16
+ ENTRYPOINT ["/bin/bash", "/run.sh"]
17
+ # CMD ["/run.sh"]
add_bash_util.sh ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # gh_install vi/websocat websocat.x86_64-unknown-linux-musl
3
+ gh_install() {
4
+ echo "Number of arguments: $#"
5
+ echo "All arguments as separate words: $@"
6
+ echo "All arguments as a single string: $*"
7
+
8
+ if [[ $# -ne 3 ]]; then
9
+ echo "Please set repo, arch, and filename"
10
+ return 1
11
+ fi
12
+
13
+ local repo="$1"
14
+ local arch="$2"
15
+ local filename="$3"
16
+
17
+ echo "Set repo: $repo, arch: $arch, filename: $filename"
18
+
19
+ local url
20
+ local count=0
21
+
22
+ while [[ -z "$url" && $count -lt 5 ]]; do
23
+ content=$(curl -s -L -H "Accept: application/vnd.github+json" "https://api.github.com/repos/$repo/releases")
24
+ url=$(echo "$content" | jq -r --arg arch "$arch" '.[0] | .assets[] | .browser_download_url | select(endswith($arch))')
25
+ count=$((count + 1))
26
+ done
27
+
28
+ if [[ -z "$url" ]]; then
29
+ echo "Failed to find a valid download URL after $count attempts."
30
+ return 1
31
+ fi
32
+
33
+ echo "Download URL: $url"
34
+ wget -q "$url" -O "$filename" && echo "Downloaded $filename successfully." || echo "Failed to download $filename."
35
+ }
36
+
37
+ check_installed() {
38
+ if [ "$#" -ne 1 ]; then
39
+ echo "Usage: check_installed <program_name>"
40
+ return 1
41
+ fi
42
+ if which "$1" &>/dev/null; then
43
+ >&2 echo "$1 is installed"
44
+ >&1 echo 0
45
+ else
46
+ >&2 echo "$1 is not installed"
47
+ >&1 echo 1
48
+ fi
49
+ }
50
+ # check_installed docker 1>/dev/null
51
+ # check_installed docker 2>/dev/null
52
+ # check_installed docker &>/dev/null
53
+
54
+
55
+ # Utility functions for managing processes
56
+ ps_kill() {
57
+ echo "Number of arguments: $#"
58
+ echo "All arguments as separate words: $@"
59
+ echo "All arguments as a single string: $*"
60
+
61
+ if [[ $# -ne 1 ]]; then
62
+ echo "Please set program"
63
+ return 1
64
+ fi
65
+ program="$1"
66
+
67
+ ps -A -o tid,cmd | grep -v grep | grep "$program" | awk '{print $1}' | xargs -I {} /bin/bash -c 'sudo kill -9 {} '
68
+ }
69
+
70
+ install_docker() {
71
+ if ! which docker &>/dev/null; then
72
+ echo "Docker is not installed. Installing..."
73
+ curl -fsSL https://get.docker.com | sh
74
+ sudo systemctl --now enable docker
75
+ echo "Docker installed successfully."
76
+ else
77
+ echo "Docker is already installed."
78
+ fi
79
+ }
80
+
81
+ create_user() {
82
+ if [ "$#" -ne 1 ]; then
83
+ echo "Usage: create_user <username>"
84
+ return 1
85
+ fi
86
+ export USERNAME="$1"
87
+ export MUID=$(id -u)
88
+ export MGID=$(id -g)
89
+
90
+ # add user without password
91
+
92
+ sudo groupadd $USERNAME
93
+ # same uid with host user
94
+ # sudo useradd -u $MUID -g $MGID -m -s /bin/bash $USERNAME
95
+ sudo useradd -g $MGID -m -s /bin/bash $USERNAME
96
+ sudo passwd -d $USERNAME
97
+ sudo usermod -a -G sudo $USERNAME
98
+ sudo usermod -a -G $USERNAME $USERNAME
99
+
100
+ install_docker
101
+ sudo usermod -a -G docker $USERNAME
102
+
103
+
104
+ echo "User $USERNAME created and added to sudo and docker groups."
105
+ }
106
+
107
+ # reset cursor
108
+ # https://unix.stackexchange.com/questions/6890/what-is-making-my-cursor-randomly-disappear-when-using-gnome-teminal
109
+ tput cnorm
run.sh ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ source /add_bash_util.sh
3
+
4
+ gh_install caddyserver/caddy linux_amd64.tar.gz /tmp/caddy.tar.gz
5
+ mkdir -p /tmp/caddy
6
+ tar -xzf /tmp/caddy.tar.gz -C /tmp/caddy
7
+
8
+
9
+ # Start the Node.js application
10
+ git clone https://github.com/waxz/Gemini-CLI-2-API.git /tmp/Gemini-CLI-2-API
11
+ cat << EOF | tee /tmp/Gemini-CLI-2-API/config.json
12
+ {
13
+ "REQUIRED_API_KEY": "${REQUIRED_API_KEY:-}",
14
+ "SERVER_PORT": 3000,
15
+ "HOST": "localhost",
16
+ "MODEL_PROVIDER": "gemini-cli-oauth",
17
+ "OPENAI_API_KEY": "${OPENAI_API_KEY:-}",
18
+ "OPENAI_BASE_URL": "https://api.openai.com/v1",
19
+ "CLAUDE_API_KEY": "${CLAUDE_API_KEY:-}",
20
+ "CLAUDE_BASE_URL": "https://api.anthropic.com/v1",
21
+ "PROJECT_ID": "${PROJECT_ID:-}",
22
+ "PROMPT_LOG_MODE": "console",
23
+ "GEMINI_OAUTH_CREDS_FILE_PATH":"/tmp/gemini_oauth_creds.json"
24
+ }
25
+ EOF
26
+ cat << EOF | tee /tmp/gemini_oauth_creds.json
27
+ {
28
+ "access_token": "${GEMINI_OAUTH_ACCESS_TOKEN:-}",
29
+ "refresh_token": "${GEMINI_OAUTH_REFRESH_TOKEN:-}",
30
+ "scope": "https://www.googleapis.com/auth/cloud-platform",
31
+ "token_type": "Bearer",
32
+ "expiry_date": 1753880406425
33
+ }
34
+ EOF
35
+ cd /tmp/Gemini-CLI-2-API && npm install && npm run start&
36
+ /tmp/caddy/caddy run --config /Caddyfile &
37
+ MAIN_PID=$!
38
+
39
+ # Wait for caddy process
40
+ wait $MAIN_PID
41
+