Skip to content

Commit

Permalink
Add document for the configuration of deployment
Browse files Browse the repository at this point in the history
This solved #19.
  • Loading branch information
Kaiser-Yang committed Aug 2, 2024
1 parent 1343df9 commit 760af5a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
29 changes: 29 additions & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# gcs-back-end
`git`中央仓库服务的后端实现。

# 部署设置说明
| 变量 | 类型 | 默认值 | 说明 |
| - | - | - | - |
| `deploy` | `bool` | `true` | 是否进行部署,当为`false`只进行打包操作。 |
| `debug` | `bool` | `false` | 是否启用调试模式。 |
| `skipTest` | `bool` | `true` | 是否跳过测试。 |
| `createGitUser` | `bool` | `true` | 是否创建`git`用户。 |
| `deployWithDocker` | `bool` | `true` | 是否使用`Docker`进行部署。 |
| `repositoryDirectory` | `string` | `"/home/git/repositories"` | `git`仓库存放目录。 |
| `postgresPassword` | `string` | `null` | `Postgres`数据库密码。 |
| `serviceEnable` | `bool` | `true` | 是否启用`systemd`服务。 |
| `serviceName` | `string` | `"gcs"` | `systemd`服务名称。 |
| `serviceSuffix` | `string` | `"service"` | `systemd`服务文件后缀。 |
| `serviceDescription` | `string` | `"Git server center back-end service"` | `systemd`服务描述。 |
| `servicePIDFile` | `string` | `"/var/run/gcs.pid"` | `systemd`服务`PID`文件。 |
| `serviceUser` | `string` | `gcs` | `systemd`服务运行用户。 |
| `serviceUserPassword` | `string` | `null` | `systemd`服务运行用户密码。 |
| `serviceWorkingDirectory` | `string` | `"/opt/gcs"` | `systemd`服务工作目录。 |
| `serviceRestartPolicy` | `string` | `"always"` | `systemd`服务重启策略。 |
| `serviceRestartDelaySeconds` | `int` | `5` | `systemd`服务重启延迟时间。 |
| `serviceStartJavaCommand` | `string` | `"/usr/bin/java"` | `systemd`服务启动`Java`命令。 |
| `serviceStartJavaArgs` | `list` | `["-jar"]` | `systemd`服务启动`Java`参数。 |
| `serviceStartJarFile` | `string` | `"/opt/gcs/gcs.jar"` | `systemd`服务启动`Jar`文件。脚本会将`maven`打包出来的文件拷贝到该位置。 |
| `serviceAfter` | `list` | `["network.target"]` | `systemd`服务会在这些服务启动后启动。 |
| `serviceWantedBy` | `list` | `"multi-user.target"` | `systemd`服务会被这些服务依赖。 |

2 changes: 1 addition & 1 deletion config_debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"deployWithDocker": false,
"repositoryDirectory": "~/.local/gcs/repository",
"debug": true,
"runTest": true
"skipTest": false
}
4 changes: 2 additions & 2 deletions config_default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"deploy": true,
"debug": false,
"runTest": false,
"skipTest": true,
"createGitUser": true,
"deployWithDocker": true,
"repositoryDirectory": "/home/git/repositories",
Expand All @@ -15,7 +15,7 @@
"serviceUserPassword": null,
"serviceWorkingDirectory": "/opt/gcs",
"serviceRestartPolicy": "always",
"serviceRestartDelaySecond": 5,
"serviceRestartDelaySeconds": 5,
"serviceStartJavaCommand": "/usr/bin/java",
"serviceStartJavaArgs": [
"-jar"
Expand Down
22 changes: 11 additions & 11 deletions script/deploy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_systemd_service(config):
User={config.serviceUser}
WorkingDirectory={config.serviceWorkingDirectory}
Restart={config.serviceRestartPolicy}
RestartSec={config.serviceRestartDelaySecond}
RestartSec={config.serviceRestartDelaySeconds}
ExecStart={exec_start}
[Install]
Expand All @@ -74,18 +74,18 @@ def deploy_on_ubuntu(config):
if config == None:
return -1
skip_test = ""
if not config.runTest:
if config.skipTest:
skip_test = "-Dmaven.test.skip=true"
if config.deploy:
res = subprocess.run('bash script/get_jar_position.sh', shell=True,
capture_output=True, text=True)
if res.returncode != 0:
return res.returncode
package_path = res.stdout.strip()
res = os.system(f'mvn package {skip_test}')
if res != 0:
return res
res = subprocess.run('bash script/get_jar_position.sh', shell=True,
capture_output=True, text=True)
if res.returncode != 0:
return res.returncode
package_path = res.stdout.strip()
res = os.system(f'mvn package {skip_test}')
if res != 0:
return res

if config.deploy:
if os.system(f"cat /etc/passwd | grep -w -E '^{config.serviceUser}'") != 0:
os.system(f'sudo useradd {config.serviceUser}')
if config.serviceUserPassword == None or config.serviceUserPassword == "":
Expand Down

0 comments on commit 760af5a

Please sign in to comment.