fix yml
This commit is contained in:
@@ -6,41 +6,43 @@
|
|||||||
trigger:
|
trigger:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
pool:
|
|
||||||
vmImage: 'windows-latest'
|
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
solution: '**/*.sln'
|
solution: '**/*.sln'
|
||||||
buildPlatform: 'Any CPU'
|
buildPlatform: 'Any CPU'
|
||||||
buildConfiguration: 'Release'
|
buildConfiguration: 'Release'
|
||||||
projectName: 'Shogi'
|
projectName: 'Shogi'
|
||||||
# Database variables - Set these as pipeline variables in Azure DevOps
|
# Database variables - Set these as pipeline variables in Azure DevOps
|
||||||
# DatabaseServer: 'your-sql-server-address'
|
DatabaseServer: 'your-sql-server-address'
|
||||||
# DatabaseName: 'ShogiDb'
|
DatabaseName: 'ShogiDb'
|
||||||
# DatabaseUser: 'your-db-user'
|
DatabaseUser: 'your-db-user'
|
||||||
# DatabasePassword: 'your-db-password' # Mark as secret in Azure DevOps
|
DatabasePassword: 'your-db-password' # Mark as secret in Azure DevOps
|
||||||
|
|
||||||
steps:
|
jobs:
|
||||||
|
- job: Build
|
||||||
|
displayName: "Build and Deploy"
|
||||||
|
pool:
|
||||||
|
vmImage: 'windows-latest'
|
||||||
|
steps:
|
||||||
|
|
||||||
- task: NuGetToolInstaller@1
|
- task: NuGetToolInstaller@1
|
||||||
|
|
||||||
- task: UseDotNet@2
|
- task: UseDotNet@2
|
||||||
inputs:
|
inputs:
|
||||||
packageType: sdk
|
packageType: sdk
|
||||||
version: 10.x
|
version: 10.x
|
||||||
installationPath: $(Agent.ToolsDirectory)/dotnet
|
installationPath: $(Agent.ToolsDirectory)/dotnet
|
||||||
|
|
||||||
- task: NuGetCommand@2
|
- task: NuGetCommand@2
|
||||||
inputs:
|
inputs:
|
||||||
restoreSolution: '$(solution)'
|
restoreSolution: '$(solution)'
|
||||||
|
|
||||||
- task: FileTransform@1
|
- task: FileTransform@1
|
||||||
inputs:
|
inputs:
|
||||||
folderPath: '$(System.DefaultWorkingDirectory)\$(projectName)'
|
folderPath: '$(System.DefaultWorkingDirectory)\$(projectName)'
|
||||||
fileType: 'json'
|
fileType: 'json'
|
||||||
targetFiles: 'appsettings.json'
|
targetFiles: 'appsettings.json'
|
||||||
|
|
||||||
- task: DotNetCoreCLI@2
|
- task: DotNetCoreCLI@2
|
||||||
inputs:
|
inputs:
|
||||||
command: 'publish'
|
command: 'publish'
|
||||||
publishWebProjects: false
|
publishWebProjects: false
|
||||||
@@ -48,38 +50,74 @@ steps:
|
|||||||
arguments: '-c Release -o $(Build.ArtifactStagingDirectory)'
|
arguments: '-c Release -o $(Build.ArtifactStagingDirectory)'
|
||||||
zipAfterPublish: false
|
zipAfterPublish: false
|
||||||
|
|
||||||
- task: PowerShell@2
|
- task: VSBuild@1
|
||||||
displayName: "Generate EF Core migration script"
|
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:
|
inputs:
|
||||||
targetType: 'inline'
|
targetType: 'inline'
|
||||||
script: |
|
script: |
|
||||||
dotnet tool restore --tool-manifest $(projectName)/.config/dotnet-tools.json
|
cd $(projectName)
|
||||||
dotnet ef migrations script --idempotent --project $(projectName)/$(projectName).csproj --output $(Build.ArtifactStagingDirectory)/migrations.sql
|
dotnet tool restore
|
||||||
|
dotnet ef migrations bundle --self-contained -r linux-x64 --configuration Release --project $(projectName).csproj --output $(Build.ArtifactStagingDirectory)/efbundle
|
||||||
workingDirectory: '$(System.DefaultWorkingDirectory)'
|
workingDirectory: '$(System.DefaultWorkingDirectory)'
|
||||||
|
|
||||||
- task: CopyFilesOverSSH@0
|
- task: PowerShell@2
|
||||||
displayName: "Copy database migration script"
|
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:
|
inputs:
|
||||||
sshEndpoint: 'LucaServer'
|
sshEndpoint: 'LucaServer'
|
||||||
sourceFolder: '$(Build.ArtifactStagingDirectory)'
|
sourceFolder: '$(Build.ArtifactStagingDirectory)'
|
||||||
contents: 'migrations.sql'
|
contents: |
|
||||||
|
efbundle
|
||||||
|
*.dacpac
|
||||||
|
deploy_db.sh
|
||||||
targetFolder: '/var/www/apps/$(projectName)/migrations'
|
targetFolder: '/var/www/apps/$(projectName)/migrations'
|
||||||
readyTimeout: '20000'
|
readyTimeout: '20000'
|
||||||
|
|
||||||
- task: SSH@0
|
- task: SSH@0
|
||||||
displayName: "Apply database migrations"
|
displayName: "Apply database migrations"
|
||||||
inputs:
|
inputs:
|
||||||
sshEndpoint: 'LucaServer'
|
sshEndpoint: 'LucaServer'
|
||||||
runOptions: 'commands'
|
runOptions: 'commands'
|
||||||
commands: |
|
commands: |
|
||||||
# Install sqlcmd if not already installed (one-time setup)
|
target="/var/www/apps/$(projectName)/migrations/deploy_db.sh"
|
||||||
# which sqlcmd || curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc && curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list && sudo apt-get update && sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18 unixodbc-dev
|
chmod +x "$target"
|
||||||
|
sed -i 's/\r$//' "$target"
|
||||||
# Apply migrations (adjust connection string as needed)
|
bash "$target"
|
||||||
/opt/mssql-tools18/bin/sqlcmd -S $(DatabaseServer) -d $(DatabaseName) -U $(DatabaseUser) -P $(DatabasePassword) -i /var/www/apps/$(projectName)/migrations/migrations.sql -C
|
|
||||||
readyTimeout: '20000'
|
readyTimeout: '20000'
|
||||||
|
|
||||||
- task: CopyFilesOverSSH@0
|
- task: CopyFilesOverSSH@0
|
||||||
displayName: "Copy application files"
|
displayName: "Copy application files"
|
||||||
inputs:
|
inputs:
|
||||||
sshEndpoint: 'LucaServer'
|
sshEndpoint: 'LucaServer'
|
||||||
@@ -88,7 +126,7 @@ steps:
|
|||||||
targetFolder: '/var/www/apps/$(projectName)'
|
targetFolder: '/var/www/apps/$(projectName)'
|
||||||
readyTimeout: '20000'
|
readyTimeout: '20000'
|
||||||
|
|
||||||
- task: SSH@0
|
- task: SSH@0
|
||||||
displayName: "Restart Kestrel"
|
displayName: "Restart Kestrel"
|
||||||
inputs:
|
inputs:
|
||||||
sshEndpoint: 'LucaServer'
|
sshEndpoint: 'LucaServer'
|
||||||
|
|||||||
Reference in New Issue
Block a user