# Docker image
# Build a Docker image to deploy, run, or push to a container registry.
# Add steps that use Docker Compose, tag images, push to a registry, run an image, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

pool:
  vmImage: 'ubuntu-latest'


variables:
  tagName: '$(Build.BuildNumber)'
  repoName: 'sparktodo-api'
  stableImageName: '$(dockerId)/$(repoName):stable'
  latestImageName: '$(dockerId)/$(repoName):latest'
  branchImageName: '$(dockerId)/$(repoName):$(Build.SourceBranchName)'
  imageName: '$(dockerId)/$(repoName):$(tagName)'

steps:
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: sdk
    version: 6.0.x
    includePreviewVersions: true # Required for preview versions

- script: dotnet build -c Release
  displayName: 'dotnet build'

- script: docker build -f Dockerfile -t $(imageName) -t $(latestImageName) .
  displayName: 'Docker build Script'

- script: |
    docker login -u $(dockerId) -p $(pswd)
    docker push $(imageName)
    docker push $(latestImageName)
  displayName: 'Push docker image'

- task: SSH@0
  displayName: 'Run shell inline on remote machine'
  inputs:
    sshEndpoint: 'weihanli-vm'
    runOptions: inline

    inline: |
      kubectl set image deployment/sparktodo-api sparktodo-api=$(imageName) --record=true
# Docker image
# Build a Docker image to deploy, run, or push to a container registry.
# Add steps that use Docker Compose, tag images, push to a registry, run an image, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

pool:
  vmImage: 'ubuntu-latest'


variables:
  tagName: '$(Build.BuildNumber)'
  repoName: 'sparktodo-api'
  stableImageName: '$(dockerId)/$(repoName):stable'
  latestImageName: '$(dockerId)/$(repoName):latest'
  branchImageName: '$(dockerId)/$(repoName):$(Build.SourceBranchName)'
  imageName: '$(dockerId)/$(repoName):$(tagName)'

steps:
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: sdk
    version: 6.0.x
    includePreviewVersions: true # Required for preview versions

- script: dotnet build -c Release
  displayName: 'dotnet build'

- script: docker build -f Dockerfile -t $(imageName) -t $(latestImageName) .
  displayName: 'Docker build Script'

- script: |
    docker login -u $(dockerId) -p $(pswd)
    docker push $(imageName)
    docker push $(latestImageName)
  displayName: 'Push docker image'

- task: SSH@0
  displayName: 'Run shell inline on remote machine'
  inputs:
    sshEndpoint: 'weihanli-vm'
    runOptions: inline

    inline: |
      kubectl set image deployment/sparktodo-api sparktodo-api=$(imageName)

Remove record flag from kubectl command
Remove record flag from kubectl command
