From f10319d96bba650ce4c2d4747d09b95fa7044450 Mon Sep 17 00:00:00 2001 From: msumshk Date: Thu, 5 Feb 2026 21:31:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Gitea=20Actions=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=83=A8=E7=BD=B2=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 54 ++++++++++++++++++++++++ src/Api/TakeoutSaaS.TenantApi/Dockerfile | 8 +--- 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 .gitea/workflows/deploy.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..ff2bbf7 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,54 @@ +name: Build and Deploy TenantApi + +on: + push: + branches: + - dev + +jobs: + build-and-deploy: + runs-on: host + steps: + - name: Checkout code + run: | + cd /opt/deploy/tenantapi || mkdir -p /opt/deploy/tenantapi + cd /opt/deploy/tenantapi + + # 如果已有仓库就 pull,否则 clone + if [ -d ".git" ]; then + git fetch origin dev + git reset --hard origin/dev + git submodule update --init --recursive + else + git clone --branch dev ssh://git@git.laosankeji.com:2222/msumshk/TakeoutSaaS.TenantApi.git . + git submodule init + git config submodule.TakeoutSaaS.BuildingBlocks.url ssh://git@git.laosankeji.com:2222/msumshk/TakeoutSaaS.BuildingBlocks.git + git config submodule.TakeoutSaaS.Docs.url ssh://git@git.laosankeji.com:2222/msumshk/TakeoutSaaS.Docs.git + git submodule update + fi + + - name: Build on host + run: | + cd /opt/deploy/tenantapi + dotnet restore src/Api/TakeoutSaaS.TenantApi/TakeoutSaaS.TenantApi.csproj + dotnet publish src/Api/TakeoutSaaS.TenantApi/TakeoutSaaS.TenantApi.csproj -c Release -o /opt/deploy/tenantapi/publish --no-restore + + - name: Build Docker image + run: | + cd /opt/deploy/tenantapi + docker build -t takeoutsaas-tenantapi:latest -f src/Api/TakeoutSaaS.TenantApi/Dockerfile . + + - name: Deploy container + run: | + docker stop tenantapi || true + docker rm tenantapi || true + docker run -d \ + --name tenantapi \ + --restart unless-stopped \ + -p 7903:7903 \ + -e ASPNETCORE_ENVIRONMENT=Development \ + takeoutsaas-tenantapi:latest + + - name: Clean up old images + run: | + docker image prune -f diff --git a/src/Api/TakeoutSaaS.TenantApi/Dockerfile b/src/Api/TakeoutSaaS.TenantApi/Dockerfile index 3fc8c2e..0a65a63 100644 --- a/src/Api/TakeoutSaaS.TenantApi/Dockerfile +++ b/src/Api/TakeoutSaaS.TenantApi/Dockerfile @@ -1,12 +1,6 @@ -FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build -WORKDIR /src -COPY . . -RUN dotnet restore src/Api/TakeoutSaaS.TenantApi/TakeoutSaaS.TenantApi.csproj -RUN dotnet publish src/Api/TakeoutSaaS.TenantApi/TakeoutSaaS.TenantApi.csproj -c Release -o /app/publish - FROM mcr.microsoft.com/dotnet/aspnet:10.0 WORKDIR /app -COPY --from=build /app/publish . +COPY publish/ . EXPOSE 7903 ENV ASPNETCORE_URLS=http://+:7903 ENTRYPOINT ["dotnet", "TakeoutSaaS.TenantApi.dll"]