Skip to content

Commit

Permalink
Merge pull request #25 from CMIPT/kaiser-init
Browse files Browse the repository at this point in the history
Finish the deploy script for database.
  • Loading branch information
luckygalaxy666 authored Aug 16, 2024
2 parents 0d51a7b + 4b6fa41 commit 6f4cf95
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 62 deletions.
12 changes: 9 additions & 3 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
| 变量 | 类型 | 默认值 | 说明 |
| - | - | - | - |
| `deploy` | `bool` | `true` | 是否进行部署,当为 `false` 只进行打包操作。 |
| `debug` | `bool` | `false` | 是否启用调试模式。 |
| `profiles` | `list` | `["dev"]` | 启动的配置类型。 |
| `deployLogLevel` | `string` | `"info"` | 部署脚本的日志级别。 |
| `skipTest` | `bool` | `true` | 是否跳过测试。 |
| `createGitUser` | `bool` | `true` | 是否创建 `git` 用户。 |
| `deployWithDocker` | `bool` | `true` | 是否使用 `Docker` 进行部署。 |
Expand All @@ -15,13 +16,12 @@
| `dockerWithGpu` | `bool` | `false` | `Docker` 是否使用 `GPU`|
| `dockerSrcPath` | `string` | `"/opt/gcs-back-end-src"` | `Docker` 中源码路径。源码会被拷贝到该路径进行编译。 |
| `repositoryDirectory` | `string` | `"/home/git/repositories"` | `git` 仓库存放目录。 |
| `postgresPassword` | `string` | `null` | `Postgres` 数据库密码。 |
| `serviceEnable` | `bool` | `true` | 是否启用 `systemd` 服务。 |
| `serviceName` | `string` | `"gcs"` | 服务名称。 |
| `serviceDescription` | `string` | `"Git server center back-end service"` | 服务描述。 |
| `servicePIDFile` | `string` | `"/var/run/gcs.pid"` | 服务 `PID` 文件。 |
| `serviceUser` | `string` | `"gcs"` | 服务运行用户。 |
| `serviceUserPassword` | `string` | `null` | 服务运行用户密码。 |
| `serviceUserPassword` | `string` | `"gcs"` | 服务运行用户密码。 |
| `serviceStartJavaCommand` | `string` | `"/usr/bin/java"` | 服务启动的 `Java` 命令。 |
| `serviceStartJavaArgs` | `list` | `["-jar"]` | 服务启动的 `Java` 参数。 |
| `serviceStartJarFile` | `string` | `"/opt/gcs/gcs.jar"` | 服务启动的 `Jar` 文件。脚本会将 `maven` 打包出来的文件拷贝到该位置。 |
Expand All @@ -35,4 +35,10 @@
| `serviceSysVInitDirectory` | `string` | `"/etc/init.d"` | `Sys-Init-V` 服务文件存放目录。 |
| `serviceStartWithBoot` | `bool` | `true` | `Sys-Init-V` 服务是否随系统启动。 |
| `serviceLogFile` | `string` | `"/tmp/log/gcs.log"` | `Sys-Init-V` 服务日志文件。 |
| `postgresUserPassword` | `string` | `"postgres"` | `Linux``Postgres` 用户密码。 |
| `postgresqlUserName` | `string` | `"gcs"` | `Postgres` 用户名称。 |
| `postgresqlUserPassword` | `string` | `"postgres"` | `Postgres` 用户密码。 |
| `postgresqlDatabaseName` | `string` | `"gcs"` | `Postgres` 数据库名称。 |
| `postgresqlHost` | `string` | `"localhost"` | `Postgres` 主机地址。 |
| `postgresqlPort` | `int` | `5432` | `Postgres` 端口。 |

10 changes: 8 additions & 2 deletions config_debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"createGitUser": false,
"deployWithDocker": false,
"repositoryDirectory": "~/.local/gcs/repository",
"debug": true,
"skipTest": false
"skipTest": false,
"deployLogLevel": "debug",
"profiles": [
"dev"
],
"postgresUserPassword": "test",
"postgresqlUserName": "test",
"postgresqlUserPassword": "test"
}
7 changes: 5 additions & 2 deletions config_debug_docker.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"createGitUser": false,
"repositoryDirectory": "~/.local/gcs/repository",
"debug": true,
"skipTest": false
"skipTest": false,
"deployLogLevel": "debug",
"profiles": [
"dev"
]
}
16 changes: 12 additions & 4 deletions config_default.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"deploy": true,
"debug": false,
"profiles": [
"prod"
],
"deployLogLevel": "info",
"skipTest": true,
"createGitUser": true,
"deployWithDocker": true,
Expand All @@ -12,13 +15,12 @@
"dockerWithGpu": false,
"dockerSrcPath": "/opt/gcs-back-end-src",
"repositoryDirectory": "/home/git/repositories",
"postgresPassword": null,
"serviceEnable": true,
"serviceName": "gcs",
"serviceDescription": "Git server center back-end service",
"servicePIDFile": "/var/run/gcs.pid",
"serviceUser": "gcs",
"serviceUserPassword": null,
"serviceUserPassword": "gcs",
"serviceStartJavaCommand": "/usr/bin/java",
"serviceStartJavaArgs": [
"-jar"
Expand All @@ -37,5 +39,11 @@
"serviceSystemdDirectory": "/etc/systemd/system",
"serviceSysVInitDirectory": "/etc/init.d",
"serviceStartWithBoot": true,
"serviceLogFile": "/tmp/log/gcs.log"
"serviceLogFile": "/tmp/log/gcs.log",
"postgresUserPassword": "postgres",
"postgresqlUserName": "postgres",
"postgresqlUserPassword": "postgres",
"postgresqlDatabaseName": "gcs",
"postgresqlHost": "localhost",
"postgresqlPort": 5432
}
1 change: 1 addition & 0 deletions config_user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
26 changes: 7 additions & 19 deletions database/database_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,17 @@ log_info () {
}

# Set database connection information
DB_USER="test_deploy"
DB_NAME="database_test13"
DB_HOST="localhost"
DB_PORT="5432"
DB_PASSWORD="root"
DB_USER=$1
DB_NAME=$2
DB_HOST=$3
DB_PORT=$4
DB_PASSWORD=$5
# Set the root directory where the SQL files are located
ROOT_DIR="."
ROOT_DIR="database"
SUB_DIR_SEQUENCE=(sequence table constraint function trigger)

TEMP_SQL_FILE="temp_sql_script.sql"

# Check if the database exists; if not, create it
if ! PGPASSWORD="$DB_PASSWORD" psql -U $DB_USER -h $DB_HOST -p $DB_PORT -lqt | cut -d \| -f 1 | grep -qw $DB_NAME; then
log_info "Database $DB_NAME does not exist. Creating database..."
if PGPASSWORD="$DB_PASSWORD" createdb -U $DB_USER -h $DB_HOST -p $DB_PORT $DB_NAME; then
log_info "Database $DB_NAME created."
else
log_error "Error: Failed to create database $DB_NAME."
fi
else
log_info "Database $DB_NAME exists. Proceeding with script execution."
fi

rm -f $TEMP_SQL_FILE || log_error "Error: Failed to remove temporary SQL file."
touch $TEMP_SQL_FILE || log_error "Error: Failed to create temporary SQL file."

Expand All @@ -45,7 +33,7 @@ for dir in "${SUB_DIR_SEQUENCE[@]}"; do
done

# Execute the temporary SQL file in psql
if PGPASSWORD="$DB_PASSWORD" psql -U $DB_USER -d $DB_NAME -h $DB_HOST -p $DB_PORT -f $TEMP_SQL_FILE; then
if PGPASSWORD="$DB_PASSWORD" psql -U "$DB_USER" -d "$DB_NAME" -h "$DB_HOST" -p "$DB_PORT" -f $TEMP_SQL_FILE; then
log_info "SQL script executed successfully."
else
log_error "Error: Failed to execute SQL script."
Expand Down
2 changes: 0 additions & 2 deletions database/table/t_repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ CREATE TABLE public.t_repository (
gmt_deleted timestamp without time zone
);

ALTER TABLE public.t_repository OWNER TO postgres;

COMMENT ON TABLE public.t_repository IS 'Table for storing repository information.';

COMMENT ON COLUMN public.t_repository.pk_repository_id IS 'Primary key of the repository table.';
Expand Down
2 changes: 0 additions & 2 deletions database/table/t_user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ CREATE TABLE public.t_user (
gmt_deleted timestamp without time zone
);

ALTER TABLE public.t_user OWNER TO postgres;

COMMENT ON TABLE public.t_user IS 'Table for storing user information.';

COMMENT ON COLUMN public.t_user.pk_user_id IS 'Primary key of the user table.';
Expand Down
2 changes: 0 additions & 2 deletions database/table/t_user_repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ CREATE TABLE public.t_user_repository (
gmt_deleted timestamp without time zone
);

ALTER TABLE public.t_user_repository OWNER TO postgres;

COMMENT ON TABLE public.t_user_repository IS 'Table for storing relationships between users and repositories.';

COMMENT ON COLUMN public.t_user_repository.pk_user_repository_id IS 'Primary key of the user_repository table.';
Expand Down
2 changes: 1 addition & 1 deletion deploy_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

config_file=${1:-"config.json"}
config_file=${1:-"config_user.json"}

log_error () {
echo -e "\e[31m[ERROR]: $1\e[0m"
Expand Down
Loading

0 comments on commit 6f4cf95

Please sign in to comment.