Azure deployment from GitLab is replacing App_Data folder - azure

I have an app service in Azure and I have connected it with my source control on GitLab, everything works fine except one thing. When I deploy from Visual Studio I can tell that App_Data should not be replaced and it works. However, deploying from GitLab (I used this tutorial https://christianliebel.com/2016/05/auto-deploying-to-azure-app-services-from-gitlab/) just replaces all the files with what I have in source control, effectively removing customers data from App_Data.
I presume that this is just simple FTP replace (as I have to run my migrations on App_Start), yet is there a way how to not replace App_Data folder on the app service when deploying from gitlab? Having synchronized App_Data with source control is not acceptable.
Thank you

I have resolved the issue by downloading deployment.zip from AppService's Kudu.
Then I edited downloaded deployment.cmd so that KuduSync ignores App_Data.
Then I inserted the modified deployment.cmd and .deployment file to the root of my git folder.

Related

Azure DevOps - Clean up old releases on on-premise server?

I have a pipeline that deploys code to an IIS folder on an on-premise server. I'm trying to figure out how to best delete old release folders. I'm not seeing anything obvious within DevOps.
Is there a native way of doing this? Or should I roll my own PowerShell script to delete old releases?
Is there a native way of doing this?
Yes, of course there is.
Open your deploy task, go Advanced Deployment Options and then enable the option Remove Additional Files at Destination
Noted: This "delete" operation I mentioned is not mean that clear all the files in local IIS folder. It just delete the files at the destination where there's no corresponding file in the package which is being deployed.
In one word, for some files which same with previous, it will be override as the latest files. And, for any left over files from a previous deployment that are no longer required, they will be deleted.
If you do not trust this option and want to clear the previous files completely, you can also add the Powershell task before IIS manage task and run delete script.
Here is the sample script to delete local files:
Remove-Item -Path "D:\Websites2\*"
You can replace "D:\Websites2\*" as your local website file path.

Azure function deployed from package updates not visible

I'm deploying an azure function app from package (using this guide - https://learn.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package) - this deploys correctly. Yet I can't seem to get an update deployed. Even after I upload a new package, changes are not picked up by azure function app. I tried stopping/starting the app to no avail.
How can I force it to pick up changes?
I ran into this issue with a newly deployed function using function v3, so this still seems to be an issue.
Short answer:
Remove the .zip in D:\home\data\SitePackages and then redeploy and your changes will get picked up.
Long answer
My setup is using ZIP deployment and WEBSITE_RUN_FROM_PACKAGE = 1.
It helps to know what happens when you use ZIP deployment:
The zip file is not written to wwwroot of your site, but instead to D:\home\data\SitePackages (source: https://learn.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package)
Then the contents of the zip file is mounted to D:\home\site\wwwroot and run from there.
For some reason, the .zip in D:\home\data\SitePackages was not being replaced, it was still the old version. To fix that, I used the Console of the App Service to delete the file before redeploying.
Navigate to your App Service function and open the Console (under Development tools section)
Run cd D:\home\data\SitePackages and then ls to see the files in the folder.
Run a rm command to remove both the zip and text file.
Redeploy your function, and you will see that changes are picked up.
We had a very weird problem using Azure Function App Deploy from Azure DevOps.
This worked perfectly until we one day made some code changes to the Azure Function that worked locally but not on our dev server. We started looking at the .zip file and the release pipeline but everything looked good here. We could also see that nothing had changed in our azure-pipelines.yml or release pipeline:
Git command: git log -p azure-pipelines.yml
For releases we used the Azure Functions task by Microsoft Corporation.
Looking at the release logs everything seemed good as well:
We then logged in to Kudu (Advanced Tools) and used powershell to look at the files deployed.
https://<your-function>.scm.azurewebsites.net/DebugConsole/?shell=powershell
Running the command dir D:\home\site\wwwroot we could see that the files had not been updated and when we looked at dir D:\home\data\SitePackages we could not see a new .zip file either.
Confirmed wrong .zip by running the command Get-Content D:\home\data\SitePackages\packagename.txt to see which .zip is being used.
Then wen't back to Azure DevOps and tried to create a new release but the files still did not update. Then I tried to clone the Azure Function App Deploy step that had previously worked and disabled the other one. Tried a new release and now everything worked.
I think this must be a Microsoft bug since we did not really change any values at all. Hope this can help someone else and that Microsoft fixes this.
If you replace old package using new one with the same package name(to leverage the same sas url), make sure the old one is overwritten. And you have to click the refresh button next to Function app to sync triggers along with the changes.
Update
I recommend using the publish command(func azure functionapp publish <functionAppName>) provided by Azure Function Core Tools(Cli). V2 Cli benefits from Run from package as well and automates the whole process for us(zip the folder, upload, create app setting, sync triggers).
The command get publishing info(username, password for deployment) first, then
Archives function project.
Uploads zip file(name is in the format of UTCTime-GUID.zip) to function-releases container in Storage account specified by AzureWebJobsStorage app setting.
Create an app setting WEBSITE_RUN_FROM_ZIP(original name of WEBSITE_RUN_FROM_PACKAGE, both work) with SAS Url.
Sync triggers to pick up changes.
After all efforts, the only thing I really determined was that you need to restart - and then wait. About 15-20 minutes after restart the changes were automagically there.
If you try to deploy with new JAR/ZIP to function-app , the changes will be reflected within 1-2 mins
* Make sure that you are using correct value for WEBSITE_RUN_FROM_PACKAGE
* Download the content from console and check whether its same or not
I had the same problem, after changing the deployment to use WEBSITE_RUN_FROM_PACKAGE. I think the problem is that it is using the cached deployment tool, so it's using the previous deployment script, not a new one when you change how you want it to deploy.
If you look at the deploy log in azure devops there is a link to the deploy log in the kudu interface:
I found this answer which explains how to fix it.

How do I get images to publish to Azure through VSTS (Azure DevOps) build pipelines

I've added several images to the wwroot/images folder for an asp.net core MVC project. They are included and displaying just fine locally, however when they are published through the AzureDevOps pipeline the images aren't appearing.
I've looked at the wwroot in Kudu and determined that the files aren't in the images directory in Azure, and I looked in the build command line results in AzureDevOps and I can see that the copy command for those images isn't being run during the MSBuild, but the original banner.svg images from the base project template are being copied.
I did a search files and saw that there was a file called project.assets.json which has include statements for the original images, but not the images I've added to the project. I suspect that the issue lies with the new images not being added to the project.assets.json file. This file appears to be auto generated though. I've verfieid that the new images have a build action of "Content" and I've even tried setting to copy always but to no avail. I'm thinking there is something else I need to do to get those files to be included in the project.assets.json on build.
Anyone know how to get new images to be added and recognized through the build script in Azure DevOps?
More than likely it’s your csproj file not having the right element to include those files in publish. Try doing a dot net publish locally and see if the files show up in the output directory . If they do then you only need to run that same.net publish command at the same commit. If they do not, then you need to update your CS project file to include those files , then retry dotnet publish locally to verify issue was resolved
I figured out that if you add the images to the wwroot folder, they are added to your local wwroot but never added to the wwroot folder that's in source control. I went and added the images that were missing to the wwroot/images folder in source control and check them in. Afterwards the publish went through without issue. I tried copy/pasting to the images folder and going right click > add > existing item and both did not recognize the add operation as a pending change in source. Not sure if this is a bug in VS or what.

Azure deploy missing XML doc files from deployment target

I have a solution. 2 projects within the solution produce XML documentation, that I need to copy to the bin folder web root when I deploy to azure.
Locally, I notice that when I build my solution, those 2 XML files get copied with the DLL into my web/bin folder. When I run my un-modified deploy.cmd file locally, I also notice that kudosync picks those up and hapilly puts them into my artifacts/wwwroot/bin folder.
But - when I deploy to azure by pushing to github, the local deployment temp folder on azure doesn't contain the XML files, and thus they don't get picked up. I added some post-build "DIR" commands to the deploy.cmd file to see what is going on, and the XML files just aren't there in the %DEPLOYMENT_TEMP%\bin\ folder.
Anyone know what's going on here?
Aha - it's because when you build from MSBUILD, it doesn't generate the XML docs for the related projects. I was getting them locally because I'd at some point built from VS, which generated them.

MVC Web Role Post Build Event

I'm trying to copy two files to the bin directory to a Windows Azure Cloud Services deployement, I added the below Post-Build event script to the MVCWebRoleCore project properties:
copy /Y "$(ProjectDir)lib\SqlServerSpatial.dll" "$(TargetDir)SqlServerSpatial.dll"
copy /Y "$(ProjectDir)lib\SqlServerSpatial110.dll" "$(TargetDir)SqlServerSpatial110.dll"
Everything looks good locally and the two files are copied, but on Windows Azure the files are not there in the bin directory, (I checked the cloud deployment using RDC to make sure), What am I doing wrong?
Thanks
When you deploy, it doesn't care what files are in your BIN folder. It cares about what files your CSPROJ project file specifies as part of the project deployment. If these are dependencies in your References list, just make sure Copy Local is set to True and they'll be deployed.

Resources