diff --git a/README.md b/README.md index cabd2da..53c21e6 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,41 @@ -ASP.NET Core Deployment -======================= +ASP.NET Core Deployment on Linux +================================ -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 -``` +Set up Build Server +------------------- -More details: [WinRM Configuration](https://github.com/Saritasa/PSGallery/blob/master/docs/WinRMConfiguration.md) +Install .NET Core SDK, PowerShell Core, psake. -### Trust Server +You can do it with Ansible: -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 +```sh +ansible-galaxy install brentwg.powershell geerlingguy.jenkins geerlingguy.nginx ocha.dotnet-core +ansible-playbook -i inventory.yml --limit buildservers buildserver.yml -Kv ``` -### Configure Server +Set up Web Server +----------------- Edit `inventory.yml`. Set correct values: - hostname +- site_name +- service_name - deploy_username -- deploy_password +- deploy_key - ansible_username -- ansible_password + +Install Ansible modules: + +```sh +ansible-galaxy install brentwg.powershell geerlingguy.jenkins geerlingguy.nginx ocha.dotnet-core +``` Execute Ansible playbook: ```sh cd ansible -ansible-playbook -i inventory.yml web.yml -v +ansible-playbook -i inventory.yml --limit webservers web.yml -Kv ``` Scaffold Scripts @@ -80,19 +78,10 @@ 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/) - [.NET Core SDK 2.1](https://www.microsoft.com/net/download) -You can easily install most software with Chocolatey package manager. To do that run `PowerShell` as administrator and type commands: - -```powershell -PS> iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex -PS> choco install psake git gitversion.portable dotnetcore-sdk -``` - Build Project ------------- @@ -172,7 +161,18 @@ Create a credential with **secret file** type. Add credential parameter to job w } ``` +Create SSH credential with `deployuser` name. Use it in `sshagent` block: + +```groovy + script { + sshagent(['deployuser']) { + sh script: "psake publish-web" + } + } +``` + Articles -------- -[Config Transformations](docs/ConfigTransformations.md) +- [Config Transformations](docs/ConfigTransformations.md) +- [Psake on Linux](docs/PsakeOnLinux.md) diff --git a/docs/PsakeOnLinux.md b/docs/PsakeOnLinux.md new file mode 100644 index 0000000..c41d0e5 --- /dev/null +++ b/docs/PsakeOnLinux.md @@ -0,0 +1,59 @@ +Psake on Linux +============== + +Here's a small instruction how to use psake on Linux. + +- Install PowerShell Core + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6 + +- Clone psake repository + + ```sh + git clone https://github.com/psake/psake /opt/psake + ``` + +- Create wrapper + + ```sh + sudo sh -c 'echo "#!/bin/env sh\npwsh -Command \"& /opt/psake/src/psake.ps1 \$@; if (\\\$psake.build_success -eq \\\$false) { exit 1 } else { exit 0 }\"" > /usr/bin/psake' + sudo chmod +x /usr/bin/psake + ``` + + It will create following script: + + ```sh + #!/usr/bin/env sh + pwsh -Command "& /opt/psake/src/psake.ps1 $@; if (\$psake.build_success -eq \$false) { exit 1 } else { exit 0 }" + ``` + +You may use Ansible to do the actions above. Tested on Ubuntu Server 18.04. + +```yaml +- hosts: buildserver + + roles: + - brentwg.powershell + + vars: + ansible_become: true + + tasks: + - name: Clone psake repository + git: + repo: 'https://github.com/psake/psake' + dest: /opt/psake + - name: Create psake wrapper + copy: + content: | + #!/usr/bin/env sh + pwsh -Command "& /opt/psake/src/psake.ps1 $@; if (\$psake.build_success -eq \$false) { exit 1 } else { exit 0 }" + dest: /usr/bin/psake + mode: 0755 + + pre_tasks: + - name: Enable Universe repository + apt_repository: + repo: deb http://archive.ubuntu.com/ubuntu bionic universe + become: yes +```