This commit is contained in:
@@ -13,10 +13,10 @@ jobs:
|
||||
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: https://github.com/actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
@@ -31,18 +31,18 @@ jobs:
|
||||
echo "IMAGE_TAG=${REGISTRY_URL}/${IMAGE_NAME}:${SHA}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
uses: https://github.com/docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to registry
|
||||
if: ${{ secrets.REGISTRY_USERNAME && secrets.REGISTRY_PASSWORD }}
|
||||
uses: docker/login-action@v3
|
||||
uses: https://github.com/docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.REGISTRY_URL }}
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
uses: https://github.com/docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
@@ -50,7 +50,7 @@ jobs:
|
||||
tags: ${{ steps.vars.outputs.IMAGE_TAG }}
|
||||
|
||||
- name: Deploy to target host
|
||||
uses: appleboy/ssh-action@v0.1.5
|
||||
uses: https://github.com/appleboy/ssh-action@v0.1.5
|
||||
with:
|
||||
host: ${{ secrets.DEPLOY_HOST }}
|
||||
port: ${{ secrets.DEPLOY_PORT }}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
- Java 17 + Maven(用于构建)。
|
||||
- Docker CLI + `docker buildx` (用于构建、推送镜像)。
|
||||
- Git 和网络访问(拉取仓库、推送镜像、SSH 连接目标服务器)。
|
||||
2. **Secrets 配置**:在 Gitea 仓库的 “Settings → Secrets” 下新增:
|
||||
2. **Secrets 配置**:在 Gitea 仓库的 “Settings → Secrets” 下新增(若希望整个组织复用,可在组织层级配置,仓库内可以覆盖同名 Key):
|
||||
- `REGISTRY_URL`:镜像仓库域名,例如 `registry.example.com`。
|
||||
- `REGISTRY_USERNAME` / `REGISTRY_PASSWORD`:镜像仓库凭据;若 Registry 允许匿名访问,可留空,本 workflow 会自动跳过登录步骤。
|
||||
- `IMAGE_NAME`:镜像名称,默认为 `jt808-server`。
|
||||
@@ -30,16 +30,18 @@ on:
|
||||
- main
|
||||
```
|
||||
|
||||
> Gitea Actions 使用 `uses: https://github.com/...` 语法来引用 GitHub 上已有的 Action,因此 workflow 中的 Action 即使不是 Gitea 官方的也能被 Runner 下载与执行。
|
||||
|
||||
- **构建阶段**:
|
||||
- `actions/checkout@v4` 拉取代码。
|
||||
- `actions/setup-java@v4` 配置 Temurin JDK 17。
|
||||
- `https://github.com/actions/checkout@v4` 拉取代码。
|
||||
- `https://github.com/actions/setup-java@v4` 配置 Temurin JDK 17。
|
||||
- 使用 `mvn -B clean package -DskipTests` 生成可执行 Jar。
|
||||
- **镜像阶段**:
|
||||
- `docker/setup-buildx-action@v3` 准备多平台构建环境。
|
||||
- `docker/login-action@v3` 登陆私有仓库。
|
||||
- `docker/build-push-action@v5` 构建 Docker 镜像并推送:标签格式 `${REGISTRY_URL}/${IMAGE_NAME}:${short-commit}`,通过 `git rev-parse --short HEAD` 动态生成。
|
||||
- `https://github.com/docker/setup-buildx-action@v3` 准备多平台构建环境。
|
||||
- `https://github.com/docker/login-action@v3` 登陆私有仓库(如配置了 `REGISTRY_USERNAME/PASSWORD`)。
|
||||
- `https://github.com/docker/build-push-action@v5` 构建 Docker 镜像并推送:标签格式 `${REGISTRY_URL}/${IMAGE_NAME}:${short-commit}`,通过 `git rev-parse --short HEAD` 动态生成。
|
||||
- **部署阶段**:
|
||||
- `appleboy/ssh-action@v0.1.5` 登录目标主机,执行 `docker pull`、`docker stop`、`docker rm`、`docker run` 的操作,始终以 `jt808-server` 名称运行容器并暴露 `8080`/`20048`。
|
||||
- `https://github.com/appleboy/ssh-action@v0.1.5` 登录目标主机,执行 `docker pull`、`docker stop`、`docker rm`、`docker run` 的操作,始终以 `jt808-server` 名称运行容器并暴露 `8080`/`20048`。
|
||||
|
||||
## 目标服务器要求
|
||||
|
||||
|
||||
Reference in New Issue
Block a user