How to run an Azure deployment PowerShell script from console - asp.net

I've downloaded a website publish profile form Azure Portal. After importing the publish profile in Visual Studio I can publish my website without providing credentials by clicking ProjectName > Publish.
Importing produced a series of files
xxxxx - FTP.pubxml
xxxxx - FTP.pubxml.user
xxxxx - FTP-publish.ps1
xxxxx - Web Deploy.pubxml
xxxxx - Web Deploy.pubxml.user
xxxxx - Web Deploy-publish.ps1
I'm wondering if I could use either of the powershell files in my simple deployment process.
When I tried to run xxxxx - Web Deploy-publish.ps1 i got an error:
ps1 : An error occurred during publish. Cannot bind argument to
parameter 'publishProperties' because it is null.
I guess I'm missing some parameters. Can somebody provide me with an example how to run it properly?

Here is a sample Powershell that you can use to deploy your Web App to Azure.
You need to set the Params and point to your publish settings to get the deploy password etc..
# How to run the script
# deploy-azure-website-devbox-webdeploy.ps1 -ProjectFile
# Define input parameters
Param(
[Parameter(Mandatory = $true)]
[String]$ProjectFile, # Point to the .csproj file of the project you want to deploy
[Switch]$Launch # Use this switch parameter if you want to launch a browser to show the website
)
# Begin - Actual script -----------------------------------------------------------------------------------------------------------------------------
# Set the output level to verbose and make the script stop on error
$VerbosePreference = "Continue"
$ErrorActionPreference = "Stop"
$scriptPath = Split-Path -parent $PSCommandPath
# Mark the start time of the script execution
$startTime = Get-Date
# Build and publish the project via web deploy package using msbuild.exe
Write-Verbose ("[Start] deploying to Windows Azure website {0}" -f $websiteName)
# Read from website-environment.xml to get the environment name
[Xml]$envXml = Get-Content ("{0}\website-environment.xml" -f $scriptPath)
$websiteName = $envXml.environment.name
# Read from the publish settings file to get the deploy password
$publishXmlFile = "{0}\{1}.pubxml" -f $scriptPath, $websiteName
[Xml]$xml = Get-Content ("{0}\{1}.publishsettings" -f $scriptPath, $websiteName)
$password = $xml.publishData.publishProfile.userPWD.get(0)
# Run MSBuild to publish the project
& "$env:windir\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" $ProjectFile `
/p:VisualStudioVersion=11.0 `
/p:DeployOnBuild=true `
/p:PublishProfile=$publishXmlFile `
/p:Password=$password
Write-Verbose ("[Finish] deploying to Windows Azure website {0}" -f $websiteName)
# Mark the finish time of the script execution
$finishTime = Get-Date
# Output the time consumed in seconds
Write-Output ("Total time used (seconds): {0}" -f ($finishTime - $startTime).TotalSeconds)
# Launch the browser to show the website
If ($Launch)
{
Show-AzureWebsite -Name $websiteName
}
# End - Actual script -------------------------------------------------------------------------------------------------------------------------------

Related

Error building webpage: RStudio + blogdown + Ezhil Theme

I am new to blogdown/hugo themes and want to build a webpage using the Ezhil theme with RStudio. I am following the instructions of blogdown.
In particular, after creating the project on RStudio, I am not able to build/serve the site. If I run serve_site(), I obtain
> blogdown::serve_site()
Launching the server via the command:
/Users/brunoconteleite/Library/Application Support/Hugo/0.84.2/hugo server --bind 127.0.0.1 -p 4321 --themesDir themes -t ezhil -D -F --navigateToChanged
Error: Error building site: logged 1 error(s)
Instead, if I run hugo_build(), I obtain
> blogdown::hugo_build()
Start building sites …
hugo v0.84.2-E0C67958+extended darwin/amd64 BuildDate=2021-06-28T10:59:21Z VendorInfo=gohugoio
ERROR 2021/06/29 13:20:37 instagram shortcode: Missing config value for services.instagram.accessToken. This can be set in config.toml, but it is recommended to configure this via the HUGO_SERVICES_INSTAGRAM_ACCESSTOKEN OS environment variable. If you are using a Client Access Token, remember that you must combine it with your App ID using a pipe symbol (<APPID>|<CLIENTTOKEN>) otherwise the request will fail.
If you feel that this should not be logged as an ERROR, you can ignore it by adding this to your site config:
ignoreErrors = ["error-missing-instagram-accesstoken"]
Total in 40 ms
Error: Error building site: logged 1 error(s)
I tried to add the suggested ignoreErrors = ["error-missing-instagram-accesstoken"] line of code to the config.yalm file but could not address this issue.
You need to turn the TOML code into YAML if your config file has yaml or yml extension.
So, rather than ignoreErrors = ["error-missing-instagram-accesstoken"], add ignoreErrors: "error-missing-instagram-accesstoken" line to your config.yaml file. It should work.

Publishing ASP .NET Core App through Windows Power Shell

How can I publish correctly ASP .NET Core App through Windows Power Shell?
Write-Host ==== START PUBLISHING APP ==== -ForegroundColor Red
$msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
$options = "/p:DeployOnBuild=true /p:PublishProfile='FolderProfile'"
$apiproj = $BackEndPath + "\DCMT.WebApi.csproj"
# Publish the WebApi to Server...
$build = $msbuild + " $apiproj " + $options
Invoke-Expression $build
Executing that command is giving me an error
error MSB4040: No target element in the project.
# Publish the WebApi to Server...
$pathToCompile = "C:\DCMT\DCMT-INTERNS-SOURCE\DCMT-BackEnd\DCMT.WebApi\DCMT.WebApi\DCMT.WebApi.csproj"
dotnet publish $pathToCompile /p:PublishDir="C:\DCMT\DCMT-INTERNS"
I have changed the command to look like this and it works! :D

DNX Webjob fails to resolve local project dependencies

We have a Solution created with VS2015.1 that has 3 projects, all of them DNX RC1.
| sln
|+---MVC6 Api
| project.json
| +---ClassLibrary
| Class.cs
| project.json
| \---Webjob
Program.cs
project.json
Both the API and Webjob reference the ClassLibrary in their project.json files.
"frameworks": {
"dnx451": {
"dependencies": {
"ClassLibrary": "1.0.0-*"
}
}
}
We created 2 WebApps, both tied with Continuos Integration to the Solution repo and each with a Project Application Setting that points to the API folder (in one) and the Webjob folder (in the other).
The API project gets deployed without problem, when it tries to resolve the local project dependency it works:
Using Project dependency ClassLibrary 1.0.0 for DNX,Version=v4.5.1
Copying source code from Project dependency ClassLibrary
Source D:\home\site\repository\ClassLibrary\project.json
Target D:\local\Temp\8d32044390806ef\approot\src\ClassLibrary
The Webjob on the other hand, fails, it tries to resolve it as a nuget remote package and fails:
[01/21/2016 19:47:45 > b597c3: INFO] GET https://api.nuget.org/v3-flatcontainer/ClassLibrary/index.json
[01/21/2016 19:47:46 > b597c3: INFO] NotFound https://api.nuget.org/v3-flatcontainer/ClassLibrary/index.json 507ms
[01/21/2016 19:47:46 > b597c3: ERR ] Unable to locate Dependency ClassLibrary >= 1.0.0-*
This last part I had to check it through Kudu, since it's done on the first run of the WebJob apparently and not during the deploy phase (like with the API).
Running the WebJob locally works without issues.
I tried the solution in publish dnx based WebJob with local dependencies but didn't work.
After talking with the Product Team, the 3 project scenario won't work right now by default.
The solution described on publish dnx based WebJob with local dependencies works for a 2 project scenario, but if you need to deploy a WebJob AND a Web App that depend on the same Class Library project and the 3 are on the same repo, you can't make the Webjob deploy from Continuous Integration.
The solution is to set Continuous Integration for your Web App (it will work by default) and manually deploy your WebJob as a zipped file.
Go into your WebJob folder and run dnu publish.
Go into bin/output/approot/src/YourWebJobFolder.
Edit the autogenerated CMD file.
Use this script by customizing line 4:
#ECHO OFF
:: 1. Prepare environment
SET DNX_CONSOLE_APP_PATH=Autocosmos.Trunk.Webjob
SET DNVM_CMD_PATH_FILE="%USERPROFILE%\.dnx\temp-set-envvars.cmd"
:: 2. Install DNX
CALL PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';$CmdPathFile='%DNVM_CMD_PATH_FILE%';& '%SCM_DNVM_PS_PATH%' " install latest
IF ERRORLEVEL 1 GOTO ERROR
:: 3. Put DNX on the path
IF EXIST %DNVM_CMD_PATH_FILE% (
CALL %DNVM_CMD_PATH_FILE%
DEL %DNVM_CMD_PATH_FILE%
)
call :ExecuteCmd dnx --project "%~dp0src\%DNX_CONSOLE_APP_PATH%" --configuration Release %DNX_CONSOLE_APP_PATH% run
goto end
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%
:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul
:exitSetErrorLevel
exit /b 1
:exitFromFunction
()
:end
endlocal
echo Finished successfully.
Then ZIP bin/output/approot and Upload it to Azure.

Unable to create OpenShift application using --from-code option

I am trying to create an OpenShift application using the --from-code option to grab the application code from GitHub. I've created two different OpenShift QuickStarts -- with one, the --from-code option works, and with the other, it doesn't work.
So clearly I'm doing something wrong in the QuickStart that isn't working. But I can't see what I'm doing wrong. I either get error 504 or an error occurred, neither of which tells me what the problem is, and there doesn't seem to be a verbose flag to get more details on the error.
Tests-Mac:~ testuser$ rhc app create sonr diy-0.1 http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart --from-code https://github.com/citrusbyte/SONR.git
The cartridge 'http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart' will be downloaded and installed
Application Options
-------------------
Domain: schof
Cartridges: diy-0.1, http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart
Source Code: https://github.com/citrusbyte/SONR.git
Gear Size: default
Scaling: no
Creating application 'sonr' ... Server returned an unexpected error code: 504
Tests-Mac:~ testuser$ rhc app create sonr diy-0.1 http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart --from-code https://github.com/citrusbyte/SONR.git
The cartridge 'http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart' will be downloaded and installed
Application Options
-------------------
Domain: schof
Cartridges: diy-0.1, http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart
Source Code: https://github.com/citrusbyte/SONR.git
Gear Size: default
Scaling: no
Creating application 'sonr' ...
An error occurred while communicating with the server. This problem may only be temporary. Check that you have correctly specified your
OpenShift server 'https://openshift.redhat.com/broker/rest/domain/schof/applications'.
Tests-Mac:~ testuser$
That's creating an application with --from-code using this repo: https://github.com/citrusbyte/SONR . If I use this repo it works flawlessly: https://github.com/citrusbyte/openshift-sinatra-redis
The code itself seems to be good, as I can create an empty new application, merge the SONR code in, and it works flawlessly.
What am I doing wrong?
UPDATE: I've worked around this issue by creating the app in two stages instead of doing it in one stage:
rhc app create APPNAME diy-0.1 http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart
cd APPNAME
git remote add github -f https://github.com/citrusbyte/SONR.git
git merge github/master -s recursive -X theirs
git push origin master
I'd still love to know why doing it in one step was failing, though.
#developercorey had the right idea.
I tried with a ridiculous timeout of 99999, and then got a different timeout error that I don't think I can change:
$ rhc app create APPNAME diy-0.1 http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart --from-code https://github.com/citrusbyte/SONR.git --timeout 99999
...
Creating application 'APPNAME' ...
The initial build for the application failed: Shell command '/sbin/runuser -s /bin/sh 5328a9385973ca70150002af -c "exec /usr/bin/runcon 'unconfined_u:system_r:openshift_t:s0:c5,c974' /bin/sh -c \"gear postreceive --init >> /tmp/initial-build.log 2>&1\""' exceeded timeout of 229
The fix I mentioned in my earlier update is working perfectly, and that's what I recommend anyone with a similar problem try -- I'm creating the app as empty without the --from-code option, and then merging in the code I wanted to use in a separate step:
rhc app create APPNAME diy-0.1 http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart
cd APPNAME
git remote add github -f https://github.com/citrusbyte/SONR.git
git merge github/master -s recursive -X theirs
git push origin master
It could be that the application takes to long to clone/setup, and the creation is timing out. Something you can try is to create the application without the --from-code, then clone it locally, and merge in your code from github, then do a git push. This operation has a much longer timeout period, and will also let you see what, if any, errors that you get since the application won't disappear if it doesn't succeed, unlike an app create.

How to use the console command DbAcl in CakePHP 2.0

I'm trying to do my first steps with CakePHP 2 console with Leopard and XAMPP but I get many problems which are not clear to me.
In the CakePHP 2.0 guide is written i need to setup correctly /app/Config/database.php to be sure it works, then I've tested it with an user registration and everything works.
Then I've read I can call the command via shell:
$ cake schema create DbAcl
This doesn't work because I must write the right path to the console app, then:
$ /Users/username/.../site.com/lib/Cake/Console/cake schema create DbAcl
After did that I get this error:
Welcome to CakePHP v2.0.4 Console
---------------------------------------------------------------
App : username
Path: /Users/username/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
/Users/username/Config/Schema/db_acl.php could not be loaded
iMac-Name:~ username$
My CakePHP installation is located in the folder site.com:
site.com/app
site.com/lib
site.com/plugins
site.com/vendors
site.com/etc.
So I did this to change the CakePHP folder to the installation folder named site.com
$ /Users/username/.../site.com/lib/Cake/Console/cake -app /Users/.../site.com
Now I get this message:
Welcome to CakePHP v2.0.4 Console
---------------------------------------------------------------
App : site.com
Path: /Users/.../public_html/site.com/
---------------------------------------------------------------
Current Paths:
-app: site.com
-working: /Users/.../site.com
-root: /Users/.../public_html
-core: /Users/.../site.com/lib
Now if I write
$ /Users/username/.../site.com/lib/Cake/Console/cake schema create DbAcl
I get the wrong original path again with a different error:
Welcome to CakePHP v2.0.4 Console
---------------------------------------------------------------
App : username
Path: /Users/username/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
/Users/username/Config/Schema/db_acl.php could not be loaded
How can I fix the path correctly?
strange thing, if I set user folder first, it works correctly:
$ cd folder/webserver/public_html/cake-app-folder
$ sudo lib/Cake/Console/cake schema DbAcl
in this way it works perfect
The real reason why many people that want to use Cakephp ACL system face this problem is that they ignore the right position where they should be before execute this command.
If you notice the error message, it says : "/Users/username/Config/Schema/db_acl.php could not be loaded".
Which is normal, actually the db_acl.php file is located in /Users/username/app/Config/Schema/db_acl.php
==> To let cakePhp fetch the file from the right place you have to be positioned in the app folder of your cake project before executing the command (cd folder/webserver/public_html/cake-app-folder in your case or c:\wamp\www\cakeTest\app for a windows project case)
Dr.Lotfi
Coopa' easy'

Resources