-
Notifications
You must be signed in to change notification settings - Fork 31
/
stack
executable file
·186 lines (149 loc) · 4.55 KB
/
stack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export TMUX_SESSION=${TMUX_SESSION:="helix"}
export WITH_RUNNER=${WITH_RUNNER:=""}
export WITH_DEMOS=${WITH_DEMOS:=""}
function mock-runner() {
go run . runner \
--mock-runner \
--server-port 8090 \
--api-host http://localhost:8080 \
--api-token oh-hallo-insecure-token \
--memory 24GB \
--runner-id mock \
--label gpu=4090 "$@"
}
function compose() {
docker compose -f docker-compose.dev.yaml "$@"
}
function build() {
compose build
}
function static-compile() {
export CGO_ENABLED=0
go build -ldflags '-extldflags "-static"' -o helix .
}
function start() {
if tmux has-session -t "$TMUX_SESSION" 2>/dev/null; then
echo "Session $TMUX_SESSION already exists. Attaching..."
sleep 1
tmux -2 attach -t $TMUX_SESSION
exit 0;
fi
export MANUALRUN=1
export LOG_LEVEL=debug
echo "Starting docker compose"
local COMPOSE_FLAGS=""
local COMPOSE_PROFILES=""
if [[ -n "$WITH_RUNNER" ]]; then
COMPOSE_FLAGS="--build"
COMPOSE_PROFILES="$COMPOSE_PROFILES --profile dev_gpu_runner"
fi
if [[ -n "$WITH_DEMOS" ]]; then
COMPOSE_PROFILES="$COMPOSE_PROFILES --profile demos"
fi
eval "docker compose -f docker-compose.dev.yaml $COMPOSE_PROFILES up $COMPOSE_FLAGS -d"
sleep 2
echo "Creating tmux session $TMUX_SESSION..."
# get the size of the window and create a session at that size
local screensize=$(stty size)
local width=$(echo -n "$screensize" | awk '{print $2}')
local height=$(echo -n "$screensize" | awk '{print $1}')
tmux -2 new-session -d -s $TMUX_SESSION -x "$width" -y "$(($height - 1))"
tmux split-window -v -d
tmux select-pane -t 1
tmux split-window -v -d
tmux select-pane -t 0
tmux split-window -v -d
tmux select-pane -t 1
tmux split-window -v -d
tmux select-pane -t 0
tmux split-window -v -d
tmux send-keys -t 0 './stack compose logs -f frontend' C-m
tmux send-keys -t 1 './stack compose logs -f api' C-m
tmux send-keys -t 2 './stack compose logs -f typesense' C-m
if [[ -n "$WITH_RUNNER" ]]; then
tmux send-keys -t 3 './stack compose --profile dev_gpu_runner -f docker-compose.dev.yaml exec dev_gpu_runner bash' C-m
tmux send-keys -t 3 'go run . runner --api-host http://172.17.0.1:8080 --api-token oh-hallo-insecure-token --memory 24GB --runner-id dev-runner' C-m
fi
if [[ -n "$WITH_DEMOS" ]]; then
tmux send-keys -t 4 'docker compose --profile demos -f docker-compose.dev.yaml exec demos bash' C-m
tmux send-keys -t 4 'go run .' C-m
fi
tmux -2 attach-session -t $TMUX_SESSION
}
function stop() {
echo "Removing docker containers"
./stack compose --profile dev_gpu_runner --profile demos down
echo "Stopping tmux session $TMUX_SESSION..."
tmux kill-session -t $TMUX_SESSION ||true
}
function up() {
docker compose -f docker-compose.dev.yaml up -d $@
}
function rebuild() {
docker compose -f docker-compose.dev.yaml up -d --build $@
}
function db() {
local subcommand="${1-cli}"
shift
local containername="${1-postgres}"
shift
if [[ "$subcommand" == "cli" ]]; then
./stack compose exec $containername psql --user postgres "$@"
elif [[ "$subcommand" == "pipe" ]]; then
./stack compose exec -T $containername psql --user postgres "$@"
fi
}
# Regenerate test mocks
function generate() {
go generate ./...
}
function psql() {
db cli postgres "$@"
}
function psql_pipe() {
db pipe postgres "$@"
}
function pgvector() {
db cli pgvector "$@"
}
function pgvector_pipe() {
db pipe pgvector "$@"
}
function install() {
go install ./api/..
}
function update_openapi() {
go install github.com/swaggo/swag/cmd/swag@latest && \
swag init -g api/pkg/server/swagger.go \
--parseDependency --parseInternal --parseDepth 3 \
-o api/pkg/server
}
function test() {
# Ingest env variables from .env file
set -a
source .env
set +a
# Check whether environment variables are set. If not, error
if [[ -z "$TOGETHER_API_KEY" ]]; then
echo "TOGETHER_API_KEY is not set"
exit 1
fi
if [[ -z "$TOGETHER_BASE_URL" ]]; then
echo "TOGETHER_BASE_URL is not set"
exit 1
fi
# Ensure postgres, tika, typesense and chrome are running
docker compose -f docker-compose.dev.yaml up -d postgres tika typesense chrome
# Database config (running in a sidecar)
export POSTGRES_HOST=localhost
export TYPESENSE_URL=http://localhost:8108
export TYPESENSE_API_KEY=typesense
export TEXT_EXTRACTION_TIKA_URL=http://localhost:9998
export RAG_CRAWLER_LAUNCHER_URL=http://localhost:7317
go test -v ./...
}
eval "$@"