Jenkins ~ Works with Docker and dotnetCore to flexibly deploy production and test environments. jenkinsdocker

Source: Internet
Author: User

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!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.