From 0cdd3c7af85aadf8f21d091932814a2534004629 Mon Sep 17 00:00:00 2001 From: Anton Zimin Date: Mon, 27 Aug 2018 21:30:01 +0700 Subject: [PATCH] Update ASP.NET docs #7 --- README.md | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e5df9c..c5ff7aa 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,173 @@ -# dotnet-deploy -Sample .NET projects and scripts to deploy them. +ASP.NET Deployment +================== + +Set up Server +------------- + +### Enable WinRM + +Enable WinRM over HTTPS on server, generate certificate, add firewall rule: + +```powershell +Install-PackageProvider NuGet -Force; Install-Module Saritasa.WinRM -Force; Install-WinrmHttps +``` + +More details: [WinRM Configuration](https://github.com/Saritasa/PSGallery/blob/master/docs/WinRMConfiguration.md) + +### Trust Server + +Add client to trusted certificate authorities list on build server or developer PC: + +```powershell +Install-Module Saritasa.Web -Force +Import-TrustedSslCertificate web.saritasa.local 5986 +``` + +### Configure Server + +Edit `inventory.yml`. Set correct values: + +- hostname +- deploy_username +- deploy_password +- ansible_username +- ansible_password + +Execute Ansible playbook: + +```sh +cd ansible +ansible-playbook -i inventory.yml web.yml -v +``` + +Scaffold Scripts +---------------- + +Install Yeoman. + +```powershell +npm i -g yo +``` + +Install generator. + +```powershell +npm i -g generator-psgallery +``` + +Go to project directory and run generator. + +```powershell +yo psgallery +``` + +Choose following options: + +``` +? Where are project source files located (relative to BuildTasks.ps1)? ..\src +? Select all used project types: Web +? Is .NET Core used? No +? Do you need GitFlow helper tasks? No +? Do you need to run NUnit or xUnit tests? No +? Do you need admin tasks, remote management capabilities? No +? Select services which you want to control from PowerShell: +``` + +Execute suggested commands to update `.gitignore` and add scripts to Git stage. Edit generated `BuildTasks.ps1`, `PublishTasks.ps1` scripts. + +Required Software +----------------- + +You need following software installed: + +- [Visual Studio 2017](https://www.visualstudio.com/downloads/) +- [psake](https://github.com/psake/psake) +- [Git](https://git-scm.com/) +- [GitVersion](https://gitversion.readthedocs.io/) +- [NuGet](https://www.nuget.org/) + +You can easily install most software with Chocolatey package manager. To do that run `PowerShell` as administrator and type commands: + +``` +PS> iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex +PS> choco install psake git gitversion.portable nuget.commandline +``` + +Build Project +------------- + +Make sure you have [psake](https://chocolatey.org/packages/psake) task runner installed. + +Copy `Config.Development.ps1.template` to `Config.Development.ps1`. Edit properties. Execute command in repository root: + +```powershell +psake build +``` + +Clean +----- + +Execute command to remove build artifacts and temporary files: + +```powershell +psake clean +``` + +Publish +------- + +### Development + +Edit properties in `Config.Development.ps1`. Execute command: + +```powershell +psake publish-web +``` + +### Staging + +Edit properties in `Config.Staging.ps1`. Execute command: + +```powershell +psake publish-web -properties "@{Environment='Staging'}" +``` + +### Production + +Edit properties in `Config.Production.ps1`. Execute command: + +```powershell +psake publish-web -properties "@{Environment='Production'}" +``` + +Add any additional properties. + +You may use environment variable also: + +```powershell +$env:Environment = 'Production' +psake publish-service +``` + +Use Secret Config +----------------- + +### Local Run + +Copy `SecretConfig.Production.ps1.template` somewhere. Edit properties. Execute command: + +```powershell +$env:Environment = 'Production' +$env:SecretConfigPath = 'C:\Path\To\SecretConfig.Production.ps1' +psake publish-web +``` + +### Jenkins + +Create a credential with **secret file** type. Add credential parameter to job with `SecretConfig` name. Add following code to pipeline: + +```groovy + environment { + SecretConfigPath = credentials("${env.SecretConfig}") + } +```