From 71d95e0432999f18e4aebe07e6b4905a6549731a Mon Sep 17 00:00:00 2001 From: bpa Date: Thu, 18 Jan 2024 13:15:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 25 ++++ .../BPA.KitChen.StoreManagementOrder.csproj | 6 + BPA.KitChen.GroupMealOrder/Dockerfile | 25 ++++ .../Properties/launchSettings.json | 35 +++-- Dockerfile | 25 ++++ Jenkinsfile | 126 ++++++++++++++++++ NuGet.config | 7 + k8s_storemanagementorder.yaml | 64 +++++++++ 8 files changed, 299 insertions(+), 14 deletions(-) create mode 100644 .dockerignore create mode 100644 BPA.KitChen.GroupMealOrder/Dockerfile create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 NuGet.config create mode 100644 k8s_storemanagementorder.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/BPA.KitChen.GroupMealOrder/BPA.KitChen.StoreManagementOrder.csproj b/BPA.KitChen.GroupMealOrder/BPA.KitChen.StoreManagementOrder.csproj index 3df7369..639909b 100644 --- a/BPA.KitChen.GroupMealOrder/BPA.KitChen.StoreManagementOrder.csproj +++ b/BPA.KitChen.GroupMealOrder/BPA.KitChen.StoreManagementOrder.csproj @@ -4,8 +4,14 @@ net6.0 enable enable + 2040c7ff-c388-467e-832b-d91b861f695a + Linux + + + + diff --git a/BPA.KitChen.GroupMealOrder/Dockerfile b/BPA.KitChen.GroupMealOrder/Dockerfile new file mode 100644 index 0000000..d125a77 --- /dev/null +++ b/BPA.KitChen.GroupMealOrder/Dockerfile @@ -0,0 +1,25 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["BPA.KitChen.GroupMealOrder/BPA.KitChen.StoreManagementOrder.csproj", "BPA.KitChen.GroupMealOrder/"] +COPY ["BPA.KitChen.GroupMealOrder.Application/BPA.KitChen.StoreManagementOrder.Application.csproj", "BPA.KitChen.GroupMealOrder.Application/"] +COPY ["BPA.KitChen.GroupMealOrder.Core/BPA.KitChen.StoreManagementOrder.Core.csproj", "BPA.KitChen.GroupMealOrder.Core/"] +COPY ["BPA.KitChen.GroupMealOrder.SqlSugar/BPA.KitChen.StoreManagementOrder.SqlSugar.csproj", "BPA.KitChen.GroupMealOrder.SqlSugar/"] +RUN dotnet restore "BPA.KitChen.GroupMealOrder/BPA.KitChen.StoreManagementOrder.csproj" +COPY . . +WORKDIR "/src/BPA.KitChen.GroupMealOrder" +RUN dotnet build "BPA.KitChen.StoreManagementOrder.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "BPA.KitChen.StoreManagementOrder.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "BPA.KitChen.StoreManagementOrder.dll"] \ No newline at end of file diff --git a/BPA.KitChen.GroupMealOrder/Properties/launchSettings.json b/BPA.KitChen.GroupMealOrder/Properties/launchSettings.json index b0ddde0..10abd9a 100644 --- a/BPA.KitChen.GroupMealOrder/Properties/launchSettings.json +++ b/BPA.KitChen.GroupMealOrder/Properties/launchSettings.json @@ -1,23 +1,14 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:41386", - "sslPort": 44336 - } - }, +{ "profiles": { "BPA.KitChen.StoreManagementOrder": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "api/index.html", - "applicationUrl": "http://localhost:5248", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5248" }, "IIS Express": { "commandName": "IISExpress", @@ -26,6 +17,22 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast", + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:41386", + "sslPort": 44336 } } -} +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d125a77 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["BPA.KitChen.GroupMealOrder/BPA.KitChen.StoreManagementOrder.csproj", "BPA.KitChen.GroupMealOrder/"] +COPY ["BPA.KitChen.GroupMealOrder.Application/BPA.KitChen.StoreManagementOrder.Application.csproj", "BPA.KitChen.GroupMealOrder.Application/"] +COPY ["BPA.KitChen.GroupMealOrder.Core/BPA.KitChen.StoreManagementOrder.Core.csproj", "BPA.KitChen.GroupMealOrder.Core/"] +COPY ["BPA.KitChen.GroupMealOrder.SqlSugar/BPA.KitChen.StoreManagementOrder.SqlSugar.csproj", "BPA.KitChen.GroupMealOrder.SqlSugar/"] +RUN dotnet restore "BPA.KitChen.GroupMealOrder/BPA.KitChen.StoreManagementOrder.csproj" +COPY . . +WORKDIR "/src/BPA.KitChen.GroupMealOrder" +RUN dotnet build "BPA.KitChen.StoreManagementOrder.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "BPA.KitChen.StoreManagementOrder.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "BPA.KitChen.StoreManagementOrder.dll"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..0b37954 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,126 @@ + +pipeline{ + agent any + parameters { + choice( + description: 'saasdev1:开发环境1 \n saastest1:测试环境2 \n dev3:生产环境', + name: 'environment', + choices: ['saasdev1', 'saastest1', 'dev3'] + ) + + choice( + description: '执行操作(发布|回滚)', + name: 'operation', + choices: ['develop', 'rollback'] + ) + + choice( + description: '分支名', + name: 'branchName', + choices: ['master'] + ) + + string( + name: 'tag', + defaultValue: '', + description: '版本tag' + ) + + } + + stages + { + stage('Prepare') { + steps { + script{ + echo "1.Prepare Stage" + echo "当前环境${params.environment}" + if(params.operation=='develop') + { + checkout scm + script { + build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim() + if (env.BRANCH_NAME != 'master') { + build_tag = "${env.BRANCH_NAME}-${build_tag}" + } + } + } + else{ + script { + if(params.branchName!= 'master') + { + build_tag = "${params.branchName}-${params.tag}" + } + else + { + build_tag="${params.tag}" + } + } + } + } + } + } + stage('Test') { + steps { + script{ + echo "2.Test Stage" + } + } + + } + stage('Build') { + steps { + script{ + echo "3.Build Docker Image Stage" + if(params.operation=='develop') + { + + sh "docker build -t 10.2.1.24:10242/bpa/storemanagementorder:${build_tag} ." + + } + } + } + } + + + stage('Push') { + steps { + script{ + echo "4.Push Docker Image Stage" + withCredentials([usernamePassword(credentialsId: 'harbor', passwordVariable: 'harborPassword', usernameVariable: 'harborUser')]) { + sh "docker login -u ${harborUser} -p ${harborPassword} 10.2.1.24:10242" + if(params.operation=='develop') + { + sh "docker push 10.2.1.24:10242/bpa/storemanagementorder:${build_tag}" + + } + } + } + } + + + + + } + stage('Deploy') { + + steps { + script{ + echo "5. Deploy Stage" + // if(params.environment=='test') + // { + // input "确认要部署线上环境吗?" + // } + +sh "sed -i 's//${build_tag}/' k8s_storemanagementorder.yaml" + sh "sed -i 's//${env.BRANCH_NAME}/' k8s_storemanagementorder.yaml" + sh "sed -i 's//${params.environment}/' k8s_storemanagementorder.yaml" + sh "kubectl apply -f k8s_storemanagementorder.yaml --record" + + + + } + } + } + } +} diff --git a/NuGet.config b/NuGet.config new file mode 100644 index 0000000..b149801 --- /dev/null +++ b/NuGet.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/k8s_storemanagementorder.yaml b/k8s_storemanagementorder.yaml new file mode 100644 index 0000000..3759778 --- /dev/null +++ b/k8s_storemanagementorder.yaml @@ -0,0 +1,64 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: storemanagementorder + namespace: kube- +spec: + + selector: + matchLabels: + app: storemanagementorder + replicas: 1 + template: + metadata: + labels: + app: storemanagementorder + spec: + containers: + - image: 10.2.1.24:10242/bpa/storemanagementorder: + imagePullPolicy: IfNotPresent + name: storemanagementorder + env: + - name: branch + value: + - name: TZ + value: Asia/Shanghai + ports: + - containerPort: 80 + protocol: TCP + volumeMounts: + - mountPath: "/app/appsettings.json" + name: storemanagementorder-config + readOnly: true + subPath: appsetting + - mountPath: "/etc/localtime" + name: timezone + resources: + requests: + cpu: "100m" + memory: "112Mi" + limits: + cpu: "500m" + memory: "512Mi" + volumes: + - name: storemanagementorder-config + configMap: + name: storemanagementorder-config + - name: timezone + hostPath: + path: /usr/share/zoneinfo/Asia/Shanghai +--- +kind: Service +apiVersion: v1 +metadata: + labels: + app: storemanagementorder + name: storemanagementorder + namespace: kube- +spec: + type: ClusterIP + ports: + - port: 80 + name: http + selector: + app: storemanagementorder