@@ -0,0 +1,153 @@ | |||||
pipeline{ | |||||
agent any | |||||
parameters { | |||||
choice( | |||||
description: 'pztjwebi:开发环境1', | |||||
name: 'environment', | |||||
choices: ['pztj'] | |||||
) | |||||
choice( | |||||
description: '前端or后端', | |||||
name: 'projectqh', | |||||
choices: ['backend','frontend'] | |||||
) | |||||
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') | |||||
{ | |||||
if(params.projectqh=='backend') | |||||
{ | |||||
sh "docker build -f backend/dockerfile -t 10.2.1.24:10242/bpa/pztjapi:${build_tag} ." | |||||
} | |||||
else if(params.projectqh=='frontend') | |||||
{ | |||||
sh "docker build -f frontend/dockerfile -t 10.2.1.24:10242/bpa/pztjweb:${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') | |||||
{ | |||||
if(params.projectqh=='backend') | |||||
{ | |||||
sh "docker push 10.2.1.24:10242/bpa/pztjapi:${build_tag}" | |||||
} | |||||
else if(params.projectqh=='frontend') | |||||
{ | |||||
sh "docker push 10.2.1.24:10242/bpa/pztjweb:${build_tag}" | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
stage('Deploy') { | |||||
steps { | |||||
script{ | |||||
echo "5. Deploy Stage" | |||||
// if(params.environment=='test') | |||||
// { | |||||
// input "确认要部署线上环境吗?" | |||||
// } | |||||
if(params.projectqh=='backend') | |||||
{ | |||||
sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s_pztjweb.yaml" | |||||
sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_pztjweb.yaml" | |||||
sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_pztjweb.yaml" | |||||
sh "kubectl apply -f k8s_pztjwebi.yaml --record" | |||||
} | |||||
else if(params.projectqh=='frontend') | |||||
{ | |||||
sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s_pztjweb.yaml" | |||||
sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_pztjweb.yaml" | |||||
sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_pztjweb.yaml" | |||||
sh "kubectl apply -f k8s_pztjweb.yaml --record" | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -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 |
@@ -6,9 +6,16 @@ | |||||
<ImplicitUsings>enable</ImplicitUsings> | <ImplicitUsings>enable</ImplicitUsings> | ||||
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages> | <SatelliteResourceLanguages>en-US</SatelliteResourceLanguages> | ||||
<PublishReadyToRunComposite>true</PublishReadyToRunComposite> | <PublishReadyToRunComposite>true</PublishReadyToRunComposite> | ||||
<UserSecretsId>2cf25418-ba37-42f6-94c4-df8b11a33318</UserSecretsId> | |||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | |||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPA.MES.Base.Web.Core\BPA.MES.Base.Web.Core.csproj" /> | <ProjectReference Include="..\BPA.MES.Base.Web.Core\BPA.MES.Base.Web.Core.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -4,6 +4,6 @@ | |||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> | <DebuggerFlavor>ProjectDebugger</DebuggerFlavor> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup> | <PropertyGroup> | ||||
<ActiveDebugProfile>BPA.MES.Base.Web.Entry</ActiveDebugProfile> | |||||
<ActiveDebugProfile>Docker</ActiveDebugProfile> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
</Project> | </Project> |
@@ -0,0 +1,25 @@ | |||||
#See https://aka.ms/containerfastmode to understand 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.MES.Base.Web.Entry/BPA.MES.Base.Web.Entry.csproj", "BPA.MES.Base.Web.Entry/"] | |||||
COPY ["BPA.MES.Base.Web.Core/BPA.MES.Base.Web.Core.csproj", "BPA.MES.Base.Web.Core/"] | |||||
COPY ["BPA.MES.Base.Application/BPA.MES.Base.Application.csproj", "BPA.MES.Base.Application/"] | |||||
COPY ["BPA.MES.Base.Core/BPA.MES.Base.Core.csproj", "BPA.MES.Base.Core/"] | |||||
RUN dotnet restore "BPA.MES.Base.Web.Entry/BPA.MES.Base.Web.Entry.csproj" | |||||
COPY . . | |||||
WORKDIR "/src/BPA.MES.Base.Web.Entry" | |||||
RUN dotnet build "BPA.MES.Base.Web.Entry.csproj" -c Release -o /app/build | |||||
FROM build AS publish | |||||
RUN dotnet publish "BPA.MES.Base.Web.Entry.csproj" -c Release -o /app/publish | |||||
FROM base AS final | |||||
WORKDIR /app | |||||
COPY --from=publish /app/publish . | |||||
ENTRYPOINT ["dotnet", "BPA.MES.Base.Web.Entry.dll"] |
@@ -1,4 +1,4 @@ | |||||
{ | |||||
{ | |||||
"$schema": "http://json.schemastore.org/launchsettings.json", | "$schema": "http://json.schemastore.org/launchsettings.json", | ||||
"iisSettings": { | "iisSettings": { | ||||
"windowsAuthentication": false, | "windowsAuthentication": false, | ||||
@@ -12,20 +12,25 @@ | |||||
"IIS Express": { | "IIS Express": { | ||||
"commandName": "IISExpress", | "commandName": "IISExpress", | ||||
"launchBrowser": true, | "launchBrowser": true, | ||||
"launchUrl": "", | |||||
"environmentVariables": { | "environmentVariables": { | ||||
"ASPNETCORE_ENVIRONMENT": "Development" | "ASPNETCORE_ENVIRONMENT": "Development" | ||||
} | } | ||||
}, | }, | ||||
"BPA.MES.Base.Web.Entry": { | "BPA.MES.Base.Web.Entry": { | ||||
"commandName": "Project", | "commandName": "Project", | ||||
"dotnetRunMessages": true, | |||||
"launchBrowser": true, | "launchBrowser": true, | ||||
"launchUrl": "", | |||||
"applicationUrl": "http://192.168.1.243:5002", | |||||
"environmentVariables": { | "environmentVariables": { | ||||
"ASPNETCORE_ENVIRONMENT": "Development" | "ASPNETCORE_ENVIRONMENT": "Development" | ||||
} | |||||
}, | |||||
"applicationUrl": "http://192.168.1.243:5002", | |||||
"dotnetRunMessages": true | |||||
}, | |||||
"Docker": { | |||||
"commandName": "Docker", | |||||
"launchBrowser": true, | |||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", | |||||
"publishAllPorts": true, | |||||
"useSSL": true | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -0,0 +1,7 @@ | |||||
<?xml version="1.0" encoding="utf-8"?> | |||||
<configuration> | |||||
<packageSources> | |||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json"/> | |||||
<add key="bpa" value="http://10.2.1.25:10243/repository/bpa/index.json"/> | |||||
</packageSources> | |||||
</configuration> |
@@ -0,0 +1,26 @@ | |||||
#See https://aka.ms/containerfastmode to understand 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 ["NuGet.config", "."] | |||||
COPY ["BPA.MES.Base.Web.Entry/BPA.MES.Base.Web.Entry.csproj", "BPA.MES.Base.Web.Entry/"] | |||||
COPY ["BPA.MES.Base.Web.Core/BPA.MES.Base.Web.Core.csproj", "BPA.MES.Base.Web.Core/"] | |||||
COPY ["BPA.MES.Base.Application/BPA.MES.Base.Application.csproj", "BPA.MES.Base.Application/"] | |||||
COPY ["BPA.MES.Base.Core/BPA.MES.Base.Core.csproj", "BPA.MES.Base.Core/"] | |||||
RUN dotnet restore "BPA.MES.Base.Web.Entry/BPA.MES.Base.Web.Entry.csproj" --configfile "NuGet.config" | |||||
COPY . . | |||||
WORKDIR "/src/BPA.MES.Base.Web.Entry" | |||||
RUN dotnet build "BPA.MES.Base.Web.Entry.csproj" -c Release -o /app/build | |||||
FROM build AS publish | |||||
RUN dotnet publish "BPA.MES.Base.Web.Entry.csproj" -c Release -o /app/publish | |||||
FROM base AS final | |||||
WORKDIR /app | |||||
COPY --from=publish /app/publish . | |||||
ENTRYPOINT ["dotnet", "BPA.MES.Base.Web.Entry.dll"] |
@@ -0,0 +1,13 @@ | |||||
server { | |||||
listen 80; | |||||
server_name localhost; | |||||
location / { | |||||
root /usr/share/nginx/html; | |||||
index index.html index.htm; | |||||
try_files $uri $uri/ /index.html; | |||||
} | |||||
} | |||||
@@ -0,0 +1,4 @@ | |||||
FROM nginx:latest | |||||
COPY ./frontend/public /usr/share/nginx/html/ | |||||
COPY ./frontend/default.conf /etc/nginx/conf.d/ | |||||
EXPOSE 80 |
@@ -0,0 +1,64 @@ | |||||
apiVersion: apps/v1 | |||||
kind: Deployment | |||||
metadata: | |||||
name: wfzapi | |||||
namespace: kube-<NAMESPACES> | |||||
spec: | |||||
selector: | |||||
matchLabels: | |||||
app: wfzapi | |||||
replicas: 1 | |||||
template: | |||||
metadata: | |||||
labels: | |||||
app: wfzapi | |||||
spec: | |||||
containers: | |||||
- image: 10.2.1.24:10242/bpa/wfzapi:<BUILD_TAG> | |||||
imagePullPolicy: IfNotPresent | |||||
name: wfzapi | |||||
env: | |||||
- name: branch | |||||
value: <BRANCH_NAME> | |||||
- name: TZ | |||||
value: Asia/Shanghai | |||||
ports: | |||||
- containerPort: 80 | |||||
protocol: TCP | |||||
volumeMounts: | |||||
- mountPath: "/app/appsettings.json" | |||||
name: wfzapi-config | |||||
readOnly: true | |||||
subPath: appsettings | |||||
- mountPath: "/etc/localtime" | |||||
name: timezone | |||||
resources: | |||||
requests: | |||||
cpu: "100m" | |||||
memory: "112Mi" | |||||
limits: | |||||
cpu: "500m" | |||||
memory: "512Mi" | |||||
volumes: | |||||
- name: wfzapi-config | |||||
configMap: | |||||
name: wfzapi-config | |||||
- name: timezone | |||||
hostPath: | |||||
path: /usr/share/zoneinfo/Asia/Shanghai | |||||
--- | |||||
kind: Service | |||||
apiVersion: v1 | |||||
metadata: | |||||
labels: | |||||
app: wfzapi | |||||
name: wfzapi | |||||
namespace: kube-<NAMESPACES> | |||||
spec: | |||||
type: ClusterIP | |||||
ports: | |||||
- port: 80 | |||||
name: http | |||||
selector: | |||||
app: wfzapi |
@@ -0,0 +1,64 @@ | |||||
apiVersion: apps/v1 | |||||
kind: Deployment | |||||
metadata: | |||||
name: wfzweb | |||||
namespace: kube-<NAMESPACES> | |||||
spec: | |||||
selector: | |||||
matchLabels: | |||||
app: wfzweb | |||||
replicas: 1 | |||||
template: | |||||
metadata: | |||||
labels: | |||||
app: wfzweb | |||||
spec: | |||||
containers: | |||||
- image: 10.2.1.24:10242/bpa/wfzweb:<BUILD_TAG> | |||||
imagePullPolicy: IfNotPresent | |||||
name: wfzweb | |||||
env: | |||||
- name: branch | |||||
value: <BRANCH_NAME> | |||||
- name: TZ | |||||
value: Asia/Shanghai | |||||
ports: | |||||
- containerPort: 80 | |||||
protocol: TCP | |||||
volumeMounts: | |||||
- mountPath: "/app/appsettings.json" | |||||
name: wfzweb-config | |||||
readOnly: true | |||||
subPath: appsettings | |||||
- mountPath: "/etc/localtime" | |||||
name: timezone | |||||
resources: | |||||
requests: | |||||
cpu: "100m" | |||||
memory: "112Mi" | |||||
limits: | |||||
cpu: "500m" | |||||
memory: "512Mi" | |||||
volumes: | |||||
- name: wfzweb-config | |||||
configMap: | |||||
name: wfzweb-config | |||||
- name: timezone | |||||
hostPath: | |||||
path: /usr/share/zoneinfo/Asia/Shanghai | |||||
--- | |||||
kind: Service | |||||
apiVersion: v1 | |||||
metadata: | |||||
labels: | |||||
app: wfzweb | |||||
name: wfzweb | |||||
namespace: kube-<NAMESPACES> | |||||
spec: | |||||
type: ClusterIP | |||||
ports: | |||||
- port: 80 | |||||
name: http | |||||
selector: | |||||
app: wfzweb |