-
Notifications
You must be signed in to change notification settings - Fork 17
/
stack
executable file
·155 lines (124 loc) · 3.84 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
#!/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 exec api bash' C-m
tmux send-keys -t 1 'go run . serve' C-m
tmux send-keys -t 2 './stack compose exec llamaindex bash' C-m
tmux send-keys -t 2 'python3 src/main.py' 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 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
}
eval "$@"