I want to run my .net 5 app on a Linux app service that has specific libraries (for example ibnss3-dev).
I have pipeline for build:
trigger:
- main
pool:
vmImage: ubuntu-20.04
variables:
buildConfiguration: 'Release'
wwwrootDir: 'Web/wwwroot'
dotnetSdkVersion: '5.0.x'
- script: |
sudo apt-get update
sudo apt-get install -y libnss3-dev
displayName: 'Dep install'
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core SDK $(dotnetSdkVersion)'
inputs:
version: '$(dotnetSdkVersion)'
- script: 'echo "$(Build.DefinitionName), $(Build.BuildId), $(Build.BuildNumber)" > buildinfo.txt'
displayName: 'Write build info'
workingDirectory: $(wwwrootDir)
- task: DotNetCoreCLI#2
displayName: 'Restore project dependencies'
inputs:
command: 'restore'
projects: '**/Web.csproj'
- task: DotNetCoreCLI#2
displayName: 'Build the project - $(buildConfiguration)'
inputs:
command: 'build'
arguments: '--no-restore --configuration $(buildConfiguration)'
projects: '**/Web.csproj'
- task: DotNetCoreCLI#2
displayName: 'Publish the project - $(buildConfiguration)'
inputs:
command: 'publish'
projects: '**/Web.csproj'
publishWebProjects: false
arguments: '--no-build --configuration Release --output $(Build.ArtifactStagingDirectory)/Release'
zipAfterPublish: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
condition: succeeded()
And a release with Azure App Service deploy (Task Version 4)
How should I do it? I tried the following solutions, but non of them works:
Release Post Deployment Action with sudo (kuduPostDeploymentScript.sh: sudo: not found)
Release Post Deployment Action without sudo ([error]E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied))
Add script step in the pipeline
I can run install command manually via ssh but I'm looking for an automated method.
apt-get update
apt-get install -y libnss3-dev
Please check this question. As you already discovered you should replace your command "dotnet web.dll" with sh script where you first install dependencies and then run your web.dll with dotnet CLI.
Related
My azure function app(python) is throwing an exception: module typing has no attribute '_classVar'. A fix for this would be to uninstall the dataclasses package. How do I uninstall this package on a python azure function using pip?
If I run pip uninstall dataclasses, will this reflect on deployment?
If you are using python version 3.7 or greater you need to uninstall the dataclass library using the same pip uninstall dataclasses.
As The dataclasses package is a backport of the Python 3.7 dataclass functionality.
Or, if still you want to exist dataclasses you can downgrade your python version to 3.6.
For more information please refer the below links:
Blog|AttributeError: module ‘typing’ has no attribute ‘_ClassVar’ with Tune
Similar GitHub Issue
I was also having a lot of trouble trying to deploy azure functions from an Azure Devops pipeline with a Python 3.7 environment, so I decided to place this here as it might help someone else with the same problem.
You need to prepare the following yaml file with your respective variables.
trigger:
- {{ branch }}
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: '{{ azureRmConnection.Id }}'
# Function app name
functionAppName: '{{ functionAppName }}'
# Agent VM image name
vmImageName: 'ubuntu-latest'
# Working Directory
workingDirectory: '{{ workingDirectory }}'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion#0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6 # Functions V2 supports Python 3.6 as of today
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
rm -rf ./.python_packages/lib/site-packages/dataclasses-0.6*
rm ./.python_packages/lib/site-packages/dataclasses.py
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp#1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionAppLinux
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
These are the key lines after installing the requirements.txt. These will remove the package from the site-packages folder.
rm -rf ./.python_packages/lib/site-packages/dataclasses-0.6*
rm ./.python_packages/lib/site-packages/dataclasses.py
pip uninstall dataclasses will not work because you are not in the right folder.
Hope this helps!
so I´m trying to create a python environment in az pipelines and publish as an artifact in order to use it across jobs. I can publish the artifact, also it is downloaded in next job, problem I have is that seems that "environment/bin/activate" doesn´t work, what am I doing wrong? is there another way to achieve that?
build and publish artifact
jobs:
- job: BuildPythonArtifact
workspace:
clean: all
pool:
vmImage: $(UBUNTU_DEFAULT_VERSION)
steps:
- task: UsePythonVersion#0
inputs:
versionSpec: "3.9"
displayName: "Use Python 3.9"
- script: |
python -m venv env
source env/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
workingDirectory: $(Build.SourcesDirectory)
displayName: "Install requirements"
- task: PublishPipelineArtifact#1
inputs:
targetPath: $(Build.SourcesDirectory)/env
artifactName: pythonenv
download artifact
steps:
- task: UsePythonVersion#0
inputs:
versionSpec: "3.9"
displayName: "Use Python 3.9"
- task: DownloadPipelineArtifact#2
inputs:
artifact: pythonenv
- script: |
source $(Pipeline.Workspace)/bin/activate
files are there, bit seems that it ignores the env activate
What I expect is to can activate or reuse python env to avoid installing requirements in every job
I am trying to deploy a WebApp in Azure DevOps and I am getting this error:
[warning]Failed to update App Service configuration details. Error: Error: Failed to update App service 'webapp' configuration. Error: BadRequest - Required parameter AccessKey is missing.
I can't figure out why this is happening, it was working originally and the error came about the other day. Nothing has changed with the WebApp code, no new settings were added. The artifact goes into place and the website works but I get this error, then on another run, the pipeline will fail, so I only have one successful run, then I have to go and delete the web app to have another successful run.
Here is my YAML Code:
trigger:
branches:
include:
- master
pr: none
pool:
vmImage: windows-latest
resources:
repositories:
- repository: Website
name: VALUE/Website
path:
- include: /Website
type: git
ref: VALUE
variables:
System.Debug: false
azureSubscription: VALUE
RG: rg_example
Location: UK South
containername: private
appconnectionname: VALUE
stages:
- stage: build_website_files
displayName: Building Main Website Files
jobs:
- job: job1
displayName: Create And Publish Artifact
steps:
- checkout: Website
- task: CmdLine#2
inputs:
script: 'mkdir Website'
workingDirectory: $(Build.ArtifactStagingDirectory)
- task: CmdLine#2
inputs:
script: 'echo $(Build.ArtifactStagingDirectory)/Website'
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
projects: Website.csproj
- task: NodeTool#0
displayName: Install Node .js
inputs:
versionSpec: 14.17.3
force32bit: false
checkLatest: false
- script: |
npm install -g #angular/cli#12.1.3
npm install
ng build --prod
displayName: npm install and build
- task: DotNetCoreCLI#2
displayName: dotnet build
inputs:
projects: Website.csproj
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
displayName: dotnet restore unit tests
inputs:
command: restore
projects: UnitTests/UnitTests.csproj
- task: DotNetCoreCLI#2
displayName: dotnet Test
inputs:
command: test
projects: UnitTests/UnitTests.csproj
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
displayName: dotnet publish
inputs:
command: publish
projects: Website.csproj
arguments: --configuration Release --output $(Build.ArtifactStagingDirectory)/Website
zipAfterPublish: true
modifyOutputPath: false
- task: PublishPipelineArtifact#1
displayName: Publish Pipeline Artifact
inputs:
targetPath: $(Build.ArtifactStagingDirectory)/Website
artifact: Website
publishLocation: pipeline
- stage: put_website_files_into_place
displayName: website_files_into_place
dependsOn: build_website_files
jobs:
- job: job2
displayName: Create Web App
#dependsOn: job1
steps:
- download: none
- task: DownloadPipelineArtifact#2
displayName: Download Build Artifacts
inputs:
patterns: '**/*.zip'
path: $(Build.ArtifactStagingDirectory)/Website/
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy: value'
inputs:
package: $(Build.ArtifactStagingDirectory)/**/*.zip
azureSubscription: $(azureSubscription)
ConnectedServiceName: $(appconnectionname)
appName: value
ResourceGroupName: $(RG)
I have a YAML pipeline which doesnt always obey the project build order
- job: Job_1
displayName: Agent job 1
pool:
vmImage: windows-2019
steps:
- task: UseDotNet#2
displayName: '.NET Core 3.1.404'
inputs:
version: '3.1.404'
packageType: sdk
- task: DotNetCoreCLI#2
enabled: true
displayName: dotnet test
continueOnError: falsefo
inputs:
command: test
projects: '**/*test/*.csproj'
arguments: --configuration $(buildConfiguration)
publishTestResults: true
This means that for some executions of the pipeline I get the error
Unable to find package NETStandard.Library with version (>= 2.0.3)
This occurs on a project that is not first to build in Visual Studio
Is there anyway of enforcing the build order? Or getting this package?
Paul
Unable to find package NETStandard.Library with version (>= 2.0.3). Is
there anyway of enforcing the build order? Or getting this package?
The problem is that the NETStandard.Library package was not found. I think it has nothing to do with the build order of the projects. NETStandard.Library is a nuget package, you can try to add a nuget restore task to the pipeline.
- task: NuGetCommand#2
inputs:
command: 'restore'
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
Is there anyway of enforcing the build order? Or getting this package?
You could build/test the specify project at first:
- task: DotNetCoreCLI#2
enabled: true
displayName: dotnet test
continueOnError: falsefo
inputs:
command: test
projects: '**/*test/TheSpecifyProject.csproj'
arguments: --configuration $(buildConfiguration)
publishTestResults: true
Then build/test other projects:
- task: DotNetCoreCLI#2
enabled: true
displayName: dotnet test
continueOnError: falsefo
inputs:
command: test
projects: '**/*test/*.csproj'
arguments: --configuration $(buildConfiguration)
publishTestResults: true
Or
- task: DotNetCoreCLI#2
enabled: true
displayName: dotnet test
continueOnError: falsefo
inputs:
command: test
projects: |
**/*test/*.csproj
!**/*test/TheSpecifyProject.csproj
arguments: --configuration $(buildConfiguration)
publishTestResults: true
I have an app targetting ASP.NET Core 3.0.
I have it built using Azure DevOps and also released from there directly to Azure Web App for Container.
This YAML was used to generate the image:
# Docker
# Build a Docker image
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
BuildConfiguration: Release
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
name: 'Azure Pool inside Network Linux'
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet#2
displayName: Install .Net Core 3.0
inputs:
packageType: 'sdk'
version: '3.0.x'
includePreviewVersions: false
- task: DotNetCoreCLI#2
displayName: Restore packages
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'select'
vstsFeed: '8187f5c9-e9c1-419f-8a5c-98285cf7633c'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: 'build'
arguments: '--configuration $(BuildConfiguration)'
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/NetCoreBoilerplate.WebApi.csproj'
arguments: '--configuration $(BuildConfiguration)'
zipAfterPublish: false
modifyOutputPath: false
- task: Docker#2
displayName: Build an image
inputs:
command: buildAndPush
containerRegistry: 'ContainerRegistry'
repository: 'NetBoilerPlate'
buildContext: '$(Build.SourcesDirectory)/src/NetCoreBoilerplate.WebApi/bin/$(BuildConfiguration)/netcoreapp3.0/'
dockerfile: '$(Build.SourcesDirectory)/tools/docker/Dockerfile'
tags: |
$(tag)
And this Dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
RUN useradd --create-home -s /bin/bash user
WORKDIR /home/user
USER user
ENV APP_HOME /home/user/app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ENV ASPNETCORE_URLS http://+:5000
EXPOSE 5000
COPY publish .
ENTRYPOINT ["dotnet", "NetCoreBoilerplate.WebApi.dll"]
Locally the application works but when I deploy it to Azure I find this error in the logs.
2019-10-02T14:20:43.177686408Z It was not possible to find any compatible framework version
2019-10-02T14:20:43.178398914Z The specified framework 'Microsoft.AspNetCore.App', version '3.0.0' was not found.
2019-10-02T14:20:43.178667416Z - The following frameworks were found:
2019-10-02T14:20:43.178867518Z 3.0.0-preview8.19405.7 at [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2019-10-02T14:20:43.178936019Z
2019-10-02T14:20:43.179157321Z You can resolve the problem by installing the specified framework and/or SDK.
2019-10-02T14:20:43.179240321Z
2019-10-02T14:20:43.179425023Z The .NET Core frameworks can be found at:
2019-10-02T14:20:43.179548024Z - https://aka.ms/dotnet-download
Any idea what could be wrong?
Yes, I've finally resolved it with changing of the origin image in dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base