Skip to content

Commit

Permalink
add functions to bind database volume to server (#82)
Browse files Browse the repository at this point in the history
Signed-off-by: cbh778899 <[email protected]>
  • Loading branch information
cbh778899 authored Sep 3, 2024
1 parent 1b2207f commit 28009d3
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ volumes
docker-compose*
Makefile
setup
generate_production_env.html
generate_production_env.html
landedb
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ APP_PORT=8000
APP_EXPOSE_PORT=8000
ENG_ACCESS_PORT=8080
MODEL_SAVE_PATH=volumes/models
DATABASE_BIND_PATH=./lancedb
INFERENCE_ENG=llamacpp
INFERENCE_ENG_PORT=8080
INFERENCE_ENG_VERSION=server--b1-27d4b7c
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
.git
volumes
__pycache__
setup/setup
setup/setup
lancedb
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ENV_FILE:=.env

ENG_ACCESS_PORT:=8080
MODEL_SAVE_PATH:=volumes/models
DATABASE_BIND_PATH:=./lancedb

INFERENCE_ENG:=llamacpp
INFERENCE_ENG_PORT:=8080
Expand Down Expand Up @@ -40,6 +41,7 @@ env:
@echo "APP_EXPOSE_PORT=$(APP_EXPOSE_PORT)">> $(ENV_FILE)
@echo "ENG_ACCESS_PORT=$(ENG_ACCESS_PORT)">> $(ENV_FILE)
@echo "MODEL_SAVE_PATH=$(MODEL_SAVE_PATH)">> $(ENV_FILE)
@echo "DATABASE_BIND_PATH=$(DATABASE_BIND_PATH)">> $(ENV_FILE)
@echo "INFERENCE_ENG=$(INFERENCE_ENG)">> $(ENV_FILE)
@echo "INFERENCE_ENG_PORT=$(INFERENCE_ENG_PORT)">> $(ENV_FILE)
@echo "INFERENCE_ENG_VERSION=$(INFERENCE_ENG_VERSION)">> $(ENV_FILE)
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-adv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ services:
build:
dockerfile: setup/Dockerfile
context: .
volumes:
- ${DATABASE_BIND_PATH}:/tmp/lancedb
expose:
- ${APP_EXPOSE_PORT}
ports:
Expand Down
1 change: 1 addition & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
context: .
volumes:
- .:/app
- ${DATABASE_BIND_PATH}:/tmp/lancedb
expose:
- ${APP_PORT}
ports:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ services:
build:
dockerfile: Dockerfile
context: .
volumes:
- ${DATABASE_BIND_PATH}:/tmp/lancedb
expose:
- ${APP_PORT}
ports:
Expand Down
2 changes: 2 additions & 0 deletions setup/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@

#define DEV_MODE_ENABLED 0

#define DATABASE_BIND_PATH "./lancedb"

#endif
2 changes: 2 additions & 0 deletions setup/default_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@

#define DEFAULT_DEV_MODE_ENABLED 0

#define DEFAULT_DATABASE_BIND_PATH "./lancedb"

#endif
23 changes: 16 additions & 7 deletions setup/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ int api_version_enabled = API_VERSION_ENABLED;

int dev_mode_enabled = DEV_MODE_ENABLED;

char* database_bind_path = DATABASE_BIND_PATH;

// ===============================FUNCTION DECLARATION===============================

void logMenu(char*);
Expand Down Expand Up @@ -128,14 +130,21 @@ void handleMenuSelection() {
defaultDatasetSettings();
break;
case 'h': case 'H':
staticAPIKeySettings();
setStringFields(
DATABSE_PATH_MENU,
"Set Database Path Success",
"Database path: ",
&database_bind_path
);
break;
case 'i': case 'I':
apiSettings();
staticAPIKeySettings();
break;
case 'j': case 'J':
setYesNoFields(DEV_MODE_MENU, &dev_mode_enabled); break;
apiSettings();
case 'k': case 'K':
setYesNoFields(DEV_MODE_MENU, &dev_mode_enabled); break;
case 'l': case 'L':
buildSettings(); break;
case 'q': case 'Q': case ESC:
puts("Exit.");
Expand Down Expand Up @@ -591,14 +600,16 @@ void saveSettings(int show_message) {
api_embedding_calc_enabled,
api_embedding_ds_enabled,
api_version_enabled,
dev_mode_enabled
dev_mode_enabled,
database_bind_path
);
fclose(f);

// ENV
f = fopen(".env", "w");
fprintf(f, ENV_FILE,
app_expose_port,
database_bind_path,
inference_cpu_cores,
inference_thread_counts,
embedding_cpu_cores,
Expand Down Expand Up @@ -671,8 +682,6 @@ void saveSettings(int show_message) {
https_cert_path_host, https_ca_name, https_cert_path_container, https_ca_name
);
}
// check if should bind any volume to host machine
int volume_bind_check = dev_mode_enabled || secret_bind_check;

int static_api_key_availibility =
static_api_key_enabled &&
Expand All @@ -683,7 +692,6 @@ void saveSettings(int show_message) {

fprintf(f, DOCKER_COMPOSE_FILE,
static_api_key_availibility ? static_api_key_str : "",
volume_bind_check ? COMPOSE_FILE_VOLUME_SECTION : "",
dev_mode_enabled ? COMPOSE_FILE_DEV_MODE : "",
secret_bind_check ? docker_compose_ssl_str : ""
);
Expand Down Expand Up @@ -755,5 +763,6 @@ void saveDefaultSettings() {
api_embedding_ds_enabled = DEFAULT_API_EMBEDDING_DS_ENABLED;
api_version_enabled = DEFAULT_API_VERSION_ENABLED;
dev_mode_enabled = DEFAULT_DEV_MODE_ENABLED;
database_bind_path = DEFAULT_DATABASE_BIND_PATH;
saveSettings(1);
}
29 changes: 23 additions & 6 deletions setup/setup_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
"e. Set Plugin Availability\n"\
"f. Set System Instruction\n"\
"g. Set Default Dataset Features\n"\
"h. Set Static API-Key Features\n"\
"i. Set APIs Availability\n"\
"j. Toggle Developer Mode\n"\
"k. Save & Build\n"\
"h. Set Database Path on Server\n"\
"i. Set Static API-Key Features\n"\
"j. Set APIs Availability\n"\
"k. Toggle Developer Mode\n"\
"l. Save & Build\n"\
"q. Quit\n"\
"\n"\
"Please enter your selection: "
Expand Down Expand Up @@ -437,6 +438,18 @@
"Enter 'q' to go back\n\n"\
"Do you want to enable developer mode? (Y/N): "

// ===============================DEV MODE===============================
#define DATABSE_PATH_MENU \
"================================\n"\
"\n"\
" Database Path on Server\n"\
"\n"\
"================================\n"\
"\n"\
"Please set your database path on server, so you won't lost your data when you restart your server.\n"\
"Enter 'q' to go back\n\n"\
"Path of database: "

// ===============================CONFIGS===============================
#define SAVE_CONFIG_SUCCESS "Successfully Saved Config"

Expand Down Expand Up @@ -501,6 +514,8 @@
"\n"\
"#define DEV_MODE_ENABLED %d\n"\
"\n"\
"#define DATABASE_BIND_PATH \"%s\"\n"\
"\n"\
"#endif"

#define DOCKER_COMPOSE_FILE \
Expand Down Expand Up @@ -544,7 +559,9 @@
" dockerfile: setup/Dockerfile\n"\
" context: .\n"\
"%s"\
"%s%s%s"\
" volumes:\n"\
" - ${DATABASE_BIND_PATH}:/tmp/lancedb\n"\
"%s%s"\
" expose:\n"\
" - ${APP_EXPOSE_PORT}\n"\
" ports:\n"\
Expand All @@ -553,7 +570,6 @@
" - llamacpp\n"\
" - embedding_eng\n"\

#define COMPOSE_FILE_VOLUME_SECTION " volumes:\n"
#define COMPOSE_FILE_DEV_MODE " - .:/app\n"
#define COMPOSE_FILE_STATIC_API_KEY \
" environment:\n"\
Expand All @@ -569,6 +585,7 @@
"APP_EXPOSE_PORT=%s\n"\
"ENG_ACCESS_PORT=8080\n"\
"MODEL_SAVE_PATH=volumes/models\n"\
"DATABASE_BIND_PATH=%s\n"\
"INFERENCE_ENG=llamacpp\n"\
"INFERENCE_ENG_PORT=8080\n"\
"INFERENCE_ENG_VERSION=server--b1-27d4b7c\n"\
Expand Down

0 comments on commit 28009d3

Please sign in to comment.