Jenkins ~ Works with Docker and dotnetCore to flexibly deploy production and test environments. jenkinsdocker
First of all, it is clear that this article describes how to deploy the dotnetcore project in the production and testing environments. In the past, in the frameworks project, we can set the web. environment Variables of config, and then specify specific variables when releasing to release the production environment and test environment. After the release, each environment has its own configuration file, frameworks updates the web environment. in the dotnetcore project, this method is not applicable, so we need to summarize it here.
Environment Description: deploy jenkins and call the sh script to add environment parameters.
#!/bin/shset -xecd ${WORKSPACE}/deploy//bin/bash publish.sh/bin/bash build.sh "Production"
The build. sh script adds input parameters describing the environment
#! /Bin/shset-exexport IMAGE_NAME = svt/smsexport Registry_Url = "ciregistry.i-counting.cn: 8443" # input parameter source, docker build -- no-cache -- pull-t $ IMAGE_NAME -- build-arg source = $1. /docker tag $ IMAGE_NAME $ Registry_Url/$ IMAGE_NAMEdocker push $ Registry_Url/$ IMAGE_NAME
Added the code for setting environment variables in Dockerfile.
FROM microsoft/aspnetcore:2.0ARG sourcerun echo $sourceCOPY sources.list /etc/apt/sources.listRUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezoneRUN apt-get update && apt-get -y install libgdiplus && apt-get cleanENV ASPNETCORE_ENVIRONMENT=$sourceWORKDIR /appEXPOSE 80COPY obj/Docker/publish .ENTRYPOINT ["dotnet", "Validate.dll"]
The deployment ettings. json configuration of the Development and Production configurations is added to the aspnetcore project. The final step is to add environment parameters when the Code obtains the configuration.
config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(file, optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .Build();
Well, today we mainly implement a more practical way to deploy projects by environment!
I hope this article will help you!