feat: 添加 Gitea Actions 自动部署工作流
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 40s
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 40s
This commit is contained in:
54
.gitea/workflows/deploy.yml
Normal file
54
.gitea/workflows/deploy.yml
Normal file
@@ -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
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user