问题描述
寻找一种从 3 个独立的 github 存储库部署到 azure Web 应用程序的方法.其中一个存储库是主网站,另外两个是其他项目使用的常用库.我们希望部署从所有三个存储库下拉到一个工件目录,运行 msbuild 并将工件复制到 wwwroot.
Looking for a way to deploy to an azure web app from 3 separate github repositories. One of the repositories is the main website, the other two are common libraries used by other projects. We want the deployment to pull down from all three repositories into an artifact directory, run msbuild and copy over the artifacts to wwwroot.
我假设我需要一个自定义 .deployment 文件以及一个 kudu 批处理文件.但是我找不到任何关于如何从多个 github 存储库中下拉的示例.
I am assuming i will need a custom .deployment file along with a kudu batch file. But I can't find any examples on how to pull down from multiple github repositories.
拼写
推荐答案
根据你的描述,你可以创建自己的.deployment和deploy.cmd文件,先克隆第二个和第三个github仓库公共库到web app文件夹然后使用 msbuild 命令构建它.
According to your description, you could create your own .deployment and deploy.cmd file to firstly clone the second and third github repositories common libraries to the web app folder then use msbuild command to build it.
注意:您无法将第二个和第三个 github 存储库克隆到工件目录.因为,您有 3 个独立的 github 存储库,每个存储库都有自己的 .git 文件.我们无法将这三个结合起来.所以我建议你可以先克隆第二个和第三个存储库到新文件夹,然后使用 msbuild 构建它.
Notice: You couldn't clone the second and third github repositories to artifact directory. Because, you have 3 separate github repositories, each repository has its own .git file. We couldn't combine this three. So I suggest you could firstly clone the second and third repository to new folder and use msbuild to build it.
更多细节,您可以参考以下步骤:
More details, you could refer to below steps:
首先,我建议您可以从 KUDU 控制台下载部署脚本.
Firstly, I suggest you could download the deployment script from the KUDU console.
注意:在你已经从git部署之后,可以下载这个文件.我们以这个文件为例来添加代码.如果没有,可以按照我的 deployment.cmd 进行操作.记得更改项目名称.
Notice:After you have already deployed from the git, this file could be downloaded.We use this file as a example to add codes. If you doesn't have you could follow my deployment.cmd. Remember changing the project name.
如下:
打开 Kudu.
下载部署脚本.
然后您可以更改发现它包含 .deployment 和 deploy.cmd 文件.
Then you could change find it contains the .deployment and deploy.cmd file.
将以下代码添加到deploy.cmd文件中,并将这两个文件添加到你的git文件夹中进行推送.
Add below codes to the deploy.cmd file and add this two file into your git folder to push.
git clone https://github.com/{yourgithubname}/BrandoGitTestLibrary.git D:homesite{foldername}
echo second project
:: 1. Start restore second project
dotnet restore "D:homesite{foldername}BrandoGitTestLibraryBrandoGitTestLibrary.csproj"
:: 2. Build to DEPLOYMENT_TEMP wait copy
dotnet build "D:homesite{foldername}BrandoGitTestLibraryBrandoGitTestLibrary.csproj" --output "%DEPLOYMENT_TEMP%"
此代码用于构建您的公共库到临时文件夹等待复制.
This code is used to build your common library to tempfolder wait for copying.
主站发布后,将临时文件夹复制到wwwrot.
After the main website published, it will copy the tempfolder to the wwwrot.
全部 deploy.cmd 文件.
The total deploy.cmd file.
注意:此示例仅构建两个存储库.如果你想构建和发布 3 个仓库,你只需要添加代码再次克隆.
Notice: This example just build two repositories. If you want to build and publish 3 repositories, you just need add the codes to clone again.
git clone https://github.com/BrandoTest/BrandoGitTestLibrary.git D:homesitesencondproject
echo second project
:: 3. Start restore second project
dotnet restore "D:homesitesencondprojectBrandoGitTestLibraryBrandoGitTestLibrary.csproj"
:: 4. Build and publish
dotnet build "D:homesitesencondprojectBrandoGitTestLibraryBrandoGitTestLibrary.csproj" --output "%DEPLOYMENT_TEMP%"
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off
:: ----------------------
:: KUDU Deployment Script
:: Version: 1.0.15
:: ----------------------
:: Prerequisites
:: -------------
:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
goto error
)
:: Setup
:: -----
setlocal enabledelayedexpansion
SET ARTIFACTS=%~dp0%..artifacts
IF NOT DEFINED DEPLOYMENT_SOURCE (
SET DEPLOYMENT_SOURCE=%~dp0%.
)
IF NOT DEFINED DEPLOYMENT_TARGET (
SET DEPLOYMENT_TARGET=%ARTIFACTS%wwwroot
)
IF NOT DEFINED NEXT_MANIFEST_PATH (
SET NEXT_MANIFEST_PATH=%ARTIFACTS%manifest
IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%manifest
)
)
IF NOT DEFINED KUDU_SYNC_CMD (
:: Install kudu sync
echo Installing Kudu Sync
call npm install kudusync -g --silent
IF !ERRORLEVEL! NEQ 0 goto error
:: Locally just running "kuduSync" would also work
SET KUDU_SYNC_CMD=%appdata%
pmkuduSync.cmd
)
IF NOT DEFINED DEPLOYMENT_TEMP (
SET DEPLOYMENT_TEMP=%temp%\___deployTemp%random%
SET CLEAN_LOCAL_DEPLOYMENT_TEMP=true
)
IF DEFINED CLEAN_LOCAL_DEPLOYMENT_TEMP (
IF EXIST "%DEPLOYMENT_TEMP%" rd /s /q "%DEPLOYMENT_TEMP%"
mkdir "%DEPLOYMENT_TEMP%"
)
IF DEFINED MSBUILD_PATH goto MsbuildPathDefined
SET MSBUILD_PATH=%ProgramFiles(x86)%MSBuild14.0BinMSBuild.exe
:MsbuildPathDefined
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------
echo Handling ASP.NET Core Web Application deployment.
:: 1. Restore nuget packages
call :ExecuteCmd dotnet restore "%DEPLOYMENT_SOURCE%TestForCore2.csproj"
IF !ERRORLEVEL! NEQ 0 goto error
:: 2. Build and publish
call :ExecuteCmd dotnet publish "%DEPLOYMENT_SOURCE%TestForCore2.csproj" --output "%DEPLOYMENT_TEMP%" --configuration Release
IF !ERRORLEVEL! NEQ 0 goto error
:: 5. KuduSync
call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
IF !ERRORLEVEL! NEQ 0 goto error
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end
:: Execute command routine that will echo out when error
: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.
结果:
这篇关于从多个存储库部署到 Azure Web App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!