135 lines
4.0 KiB
YAML
135 lines
4.0 KiB
YAML
# ASP.NET
|
|
# Build and test ASP.NET projects.
|
|
# Add steps that publish symbols, save build artifacts, deploy, and more:
|
|
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
|
|
|
|
trigger:
|
|
- master
|
|
|
|
variables:
|
|
solution: '**/*.sln'
|
|
buildPlatform: 'Any CPU'
|
|
buildConfiguration: 'Release'
|
|
projectName: 'Shogi'
|
|
# Database variables - Set these as pipeline variables in Azure DevOps
|
|
DatabaseServer: 'your-sql-server-address'
|
|
DatabaseName: 'ShogiDb'
|
|
DatabaseUser: 'your-db-user'
|
|
DatabasePassword: 'your-db-password' # Mark as secret in Azure DevOps
|
|
|
|
jobs:
|
|
- job: Build
|
|
displayName: "Build and Deploy"
|
|
pool:
|
|
vmImage: 'windows-latest'
|
|
steps:
|
|
|
|
- task: NuGetToolInstaller@1
|
|
|
|
- task: UseDotNet@2
|
|
inputs:
|
|
packageType: sdk
|
|
version: 10.x
|
|
installationPath: $(Agent.ToolsDirectory)/dotnet
|
|
|
|
- task: NuGetCommand@2
|
|
inputs:
|
|
restoreSolution: '$(solution)'
|
|
|
|
- task: FileTransform@1
|
|
inputs:
|
|
folderPath: '$(System.DefaultWorkingDirectory)\$(projectName)'
|
|
fileType: 'json'
|
|
targetFiles: 'appsettings.json'
|
|
|
|
- task: DotNetCoreCLI@2
|
|
inputs:
|
|
command: 'publish'
|
|
publishWebProjects: false
|
|
projects: '$(projectName)/$(projectName).csproj'
|
|
arguments: '-c Release -o $(Build.ArtifactStagingDirectory)'
|
|
zipAfterPublish: false
|
|
|
|
- task: VSBuild@1
|
|
displayName: "Build Database Project"
|
|
inputs:
|
|
solution: '**/*.sqlproj'
|
|
platform: '$(buildPlatform)'
|
|
configuration: '$(buildConfiguration)'
|
|
msbuildArgs: '/p:OutputPath=$(Build.ArtifactStagingDirectory)'
|
|
|
|
- task: PowerShell@2
|
|
displayName: "Generate EF Core migration bundle"
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
cd $(projectName)
|
|
dotnet tool restore
|
|
dotnet ef migrations bundle --self-contained -r linux-x64 --configuration Release --project $(projectName).csproj --output $(Build.ArtifactStagingDirectory)/efbundle
|
|
workingDirectory: '$(System.DefaultWorkingDirectory)'
|
|
|
|
- task: PowerShell@2
|
|
displayName: "Generate deployment script"
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
$script = @"
|
|
#!/bin/bash
|
|
set -e
|
|
export PATH="`$PATH:`$HOME/.dotnet/tools"
|
|
cd /var/www/apps/$(projectName)/migrations
|
|
|
|
echo "Applying EF Migrations..."
|
|
chmod +x ./efbundle
|
|
./efbundle --connection '$(ConnectionStrings.ShogiDatabase)'
|
|
|
|
echo "Applying DACPAC..."
|
|
dotnet tool install -g Microsoft.SqlPackage 2>/dev/null || true
|
|
# Use a glob or specific name for the dacpac
|
|
DACPAC_FILE=`$(ls *.dacpac | head -n 1)
|
|
sqlpackage /Action:Publish /SourceFile:"`$DACPAC_FILE" /TargetConnectionString:'$(ConnectionStrings.ShogiDatabase)'
|
|
"@
|
|
# Ensure LF line endings for Linux
|
|
$script = $script -replace "`r`n", "`n"
|
|
[System.IO.File]::WriteAllText("$(Build.ArtifactStagingDirectory)/deploy_db.sh", $script)
|
|
|
|
- task: CopyFilesOverSSH@0
|
|
displayName: "Copy database files"
|
|
inputs:
|
|
sshEndpoint: 'LucaServer'
|
|
sourceFolder: '$(Build.ArtifactStagingDirectory)'
|
|
contents: |
|
|
efbundle
|
|
*.dacpac
|
|
deploy_db.sh
|
|
targetFolder: '/var/www/apps/$(projectName)/migrations'
|
|
readyTimeout: '20000'
|
|
|
|
- task: SSH@0
|
|
displayName: "Apply database migrations"
|
|
inputs:
|
|
sshEndpoint: 'LucaServer'
|
|
runOptions: 'commands'
|
|
commands: |
|
|
target="/var/www/apps/$(projectName)/migrations/deploy_db.sh"
|
|
chmod +x "$target"
|
|
sed -i 's/\r$//' "$target"
|
|
bash "$target"
|
|
readyTimeout: '20000'
|
|
|
|
- task: CopyFilesOverSSH@0
|
|
displayName: "Copy application files"
|
|
inputs:
|
|
sshEndpoint: 'LucaServer'
|
|
sourceFolder: '$(Build.ArtifactStagingDirectory)'
|
|
contents: '**'
|
|
targetFolder: '/var/www/apps/$(projectName)'
|
|
readyTimeout: '20000'
|
|
|
|
- task: SSH@0
|
|
displayName: "Restart Kestrel"
|
|
inputs:
|
|
sshEndpoint: 'LucaServer'
|
|
runOptions: 'commands'
|
|
commands: 'sudo systemctl restart kestrel-Shogi.service'
|
|
readyTimeout: '20000' |