Skip to content

Commit

Permalink
添加部署文件
Browse files Browse the repository at this point in the history
  • Loading branch information
yimogit committed Aug 27, 2023
1 parent d668495 commit c833b17
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "file:///e%3A/Coding/02Github/qccoding/Homely/Qc.Homely.Api/.github/workflows/deploy.yml"
}
}
55 changes: 55 additions & 0 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# deploy.yml
name: 后端测试环境直接部署
# 手动构建
#on: workflow_dispatch
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
# 拉取仓库文件
- name: 拉取master分支代码
uses: actions/checkout@v3
with:
# 默认当前分支
ref: "master"
# action命令,安装Dotnet7
- name: 安装 Dotnet7
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.400
# 执行打包命令
- run: dotnet --version && dotnet publish ./src/hosts/ZhonTai.Host -c Release -o ./publish_output --self-contained true --runtime linux-x64 --framework net7.0
# 将dist复制到docker目录中
- run: cp ./publish_output ./docker -rf
# 使用 ssh 将api-dist文件拷贝到 linux
- name: 使用ssh部署
uses: easingthemes/ssh-deploy@v4.1.8
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i --delete"
SOURCE: "docker"
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
TARGET: ${{ secrets.REMOTE_TARGET }}
EXCLUDE: "/node_modules/"
SCRIPT_BEFORE: |
mkdir ${{ secrets.REMOTE_TARGET }} -p
SCRIPT_AFTER: |
cd ${{ secrets.REMOTE_TARGET }}
cd docker
docker build --rm -f ./Dockerfile -t zhontai/apihost:latest .
# 检查容器是否存在
if docker container ls -a | grep -q "my-zhontai-apihost"; then
echo "容器已存在"
# 停止并移除容器
docker stop my-zhontai-apihost
docker rm my-zhontai-apihost
fi
# 容器挂载的路径
mkdir /app/zhontai/volumns/upload -p
docker run --name my-zhontai-apihost -d -p 9902:80 -e ASPNETCORE_ENVIRONMENT=Testing -v /app/zhontai/volumns/admindb.db:/app/admindb.db -v /app/zhontai/volumns/upload:/app/wwwroot/upload zhontai/apihost:latest
13 changes: 13 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 使用 ASP.NET Core 运行时镜像作为最终镜像
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS runtime

WORKDIR /app

# 复制构建好的应用程序文件
COPY ./publish_output /app

# 设置运行时环境变量
ENV ASPNETCORE_URLS=http://+:80

# 指定容器启动时要执行的命令
ENTRYPOINT ["dotnet", "ZhonTai.Host.dll"]

0 comments on commit c833b17

Please sign in to comment.