Skip to content

Commit

Permalink
Finish the script for deploying in docker
Browse files Browse the repository at this point in the history
In this commit, we finish the script for deploying in docker. We found
that `systemd` can not be used in docker, so we use `Sys V Init` to
start a service in docker.

This commit is related with #8.

Those below are not finished yet:
* Create database automatically.
  • Loading branch information
Kaiser-Yang committed Aug 10, 2024
1 parent 6ed74c4 commit 4ae8e63
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 113 deletions.
51 changes: 30 additions & 21 deletions README-zh.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
# gcs-back-end
`git`中央仓库服务的后端实现。
`git` 中央仓库服务的后端实现。

# 部署设置说明
| 变量 | 类型 | 默认值 | 说明 |
| - | - | - | - |
| `deploy` | `bool` | `true` | 是否进行部署,当为`false`只进行打包操作。 |
| `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`服务会被这些服务依赖。 |
| `createGitUser` | `bool` | `true` | 是否创建 `git` 用户。 |
| `deployWithDocker` | `bool` | `true` | 是否使用 `Docker` 进行部署。 |
| `dockerName` | `string` | `"gcs-backend"` | `Docker` 容器名称。 |
| `dockerImage` | `string` | `"ubuntu:latest"` | `Docker` 镜像。 |
| `dockerPortMapping` | `list` | `["8080:8080"]` | `Docker` 端口映射。 |
| `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` | 服务运行用户密码。 |
| `serviceStartJavaCommand` | `string` | `"/usr/bin/java"` | 服务启动的 `Java` 命令。 |
| `serviceStartJavaArgs` | `list` | `["-jar"]` | 服务启动的 `Java` 参数。 |
| `serviceStartJarFile` | `string` | `"/opt/gcs/gcs.jar"` | 服务启动的 `Jar` 文件。脚本会将 `maven` 打包出来的文件拷贝到该位置。 |
| `serviceSuffix` | `string` | `"service"` | `systemd` 服务文件后缀。 |
| `serviceWorkingDirectory` | `string` | `"/opt/gcs"` | `systemd` 服务工作目录。 |
| `serviceRestartPolicy` | `string` | `"always"` | `systemd` 服务重启策略。 |
| `serviceRestartDelaySeconds` | `int` | `5` | `systemd` 服务重启延迟时间。 |
| `serviceAfter` | `list` | `["network.target"]` | `systemd` 服务会在这些服务启动后启动。 |
| `serviceWantedBy` | `list` | `"multi-user.target"` | `systemd` 服务会被这些服务依赖。 |
| `serviceSystemdDirectory` | `string` | `"/etc/systemd/system"` | `systemd` 服务文件存放目录。 |
| `serviceSysVInitDirectory` | `string` | `"/etc/init.d"` | `Sys-Init-V` 服务文件存放目录。 |
| `serviceStartWithBoot` | `bool` | `true` | `Sys-Init-V` 服务是否随系统启动。 |
| `serviceLogFile` | `string` | `"/tmp/log/gcs.log"` | `Sys-Init-V` 服务日志文件。 |

6 changes: 6 additions & 0 deletions config_debug_docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"createGitUser": false,
"repositoryDirectory": "~/.local/gcs/repository",
"debug": true,
"skipTest": false
}
21 changes: 16 additions & 5 deletions config_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,38 @@
"skipTest": true,
"createGitUser": true,
"deployWithDocker": true,
"dockerName": "gcs-back-end",
"dockerImage": "ubuntu:20.04",
"dockerPortMapping": [
"8080:8080"
],
"dockerWithGpu": false,
"dockerSrcPath": "/opt/gcs-back-end-src",
"repositoryDirectory": "/home/git/repositories",
"postgresPassword": null,
"serviceEnable": true,
"serviceName": "gcs",
"serviceSuffix": "service",
"serviceDescription": "Git server center back-end service",
"servicePIDFile": "/var/run/gcs.pid",
"serviceUser": "gcs",
"serviceUserPassword": null,
"serviceWorkingDirectory": "/opt/gcs",
"serviceRestartPolicy": "always",
"serviceRestartDelaySeconds": 5,
"serviceStartJavaCommand": "/usr/bin/java",
"serviceStartJavaArgs": [
"-jar"
],
"serviceStartJarFile": "/opt/gcs/gcs.jar",
"serviceSuffix": "service",
"serviceWorkingDirectory": "/opt/gcs",
"serviceRestartPolicy": "always",
"serviceRestartDelaySeconds": 5,
"serviceAfter": [
"network.target"
],
"serviceWantedBy": [
"multi-user.target"
]
],
"serviceSystemdDirectory": "/etc/systemd/system",
"serviceSysVInitDirectory": "/etc/init.d",
"serviceStartWithBoot": true,
"serviceLogFile": "/tmp/log/gcs.log"
}
21 changes: 3 additions & 18 deletions deploy_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

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

echo "Config file: ${config_file}"

log_error () {
echo -e "\e[31m[ERROR]: $1\e[0m"
exit 1
Expand All @@ -13,6 +11,8 @@ log_info () {
echo "[INFO]: $1"
}

log_info "Config file: ${config_file}"

apt_updated=false
install_package() {
local sudo_cmd
Expand All @@ -25,22 +25,7 @@ install_package() {
}

# install essential packages
if ! command -v python || ! command -v python3; then
install_package python-is-python3
fi
if ! command -v psql; then
install_package postgresql
install_package postgresql-client
fi
if ! dpkg -l | grep jdk-17; then
install_package openjdk-17-jdk-headless
fi
if ! command -v mvn; then
install_package maven
fi
if ! command -v systemctl; then
install_package systemd
fi
install_package python-is-python3

log_info "Deploying..."
python script/deploy_helper.py \
Expand Down
Loading

0 comments on commit 4ae8e63

Please sign in to comment.