将搭建的网站发布到azure

时间:2014-08-24 20:54:29

标签: asp.net visual-studio azure yeoman gulp

我已经将Steve Sanderson的generator-ko用于yeoman

下图显示了它创建的结构:

output from generator-ko

适合调试的源代码位于 src 文件夹中。 gulp用于构建(最小化,连接等),此输出位于 dist 文件夹中。

所以,关注业务:我有什么选择将其发布到Azure(网站)?该项目很可能会在Visual Studio上进行托管,我希望将构建系统用于夜间构建,运行测试等。

我考虑过将项目转换为ASP.NET项目,以便利用它提供的一些功能(发布等),但我不确定这是否是最佳方法,或者如何实际执行这个问题非常适合。例如,我应该如何处理我有一个src文件夹和一个dist文件夹而不是一个Web根目录的事实?

我还想利用测试系统(karma,jasmine)作为构建过程的一部分。

你可能已经明白了,我对从这里去哪里感到有点无能为力。你将如何实现我在此描述的内容?

1 个答案:

答案 0 :(得分:6)

我将自己提供一个答案,以防其他人想知道同样的事情会偶然发现这个问题:

在做了一些挖掘之后,我决定创建一个使用本地git存储库设置的Azure网站,如上所述here

然后我使用npm来安装kudu-cli并使用它来生成.deployment脚本,如here所述

然后我修改了脚本以安装我的bower模块并运行我的gulp脚本。最后,我修改了脚本,以便只将/ dist文件夹的内容复制到发布目标文件夹。

如果其他人像我一样无能为力,以下信息可能会有用:Azure网站托管模型实际上非常直接。如果您愿意,您可以轻松地在本地构建并使用ftp手动发布/ dist文件夹。

按请求更新:构建脚本

@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off

:: ----------------------
:: KUDU Deployment Script
:: Version: 0.1.11
:: ----------------------

:: 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%\npm\kuduSync.cmd
)
goto Deployment

:: Utility Functions
:: -----------------

:SelectNodeVersion

IF DEFINED KUDU_SELECT_NODE_VERSION_CMD (
  :: The following are done only on Windows Azure Websites environment
  call %KUDU_SELECT_NODE_VERSION_CMD% "%DEPLOYMENT_SOURCE%" "%DEPLOYMENT_TARGET%" "%DEPLOYMENT_TEMP%"
  IF !ERRORLEVEL! NEQ 0 goto error

  IF EXIST "%DEPLOYMENT_TEMP%\__nodeVersion.tmp" (
    SET /p NODE_EXE=<"%DEPLOYMENT_TEMP%\__nodeVersion.tmp"
    IF !ERRORLEVEL! NEQ 0 goto error
  )

  IF EXIST "%DEPLOYMENT_TEMP%\__npmVersion.tmp" (
    SET /p NPM_JS_PATH=<"%DEPLOYMENT_TEMP%\__npmVersion.tmp"
    IF !ERRORLEVEL! NEQ 0 goto error
  )

  IF NOT DEFINED NODE_EXE (
    SET NODE_EXE=node
  )

  SET NPM_CMD="!NODE_EXE!" "!NPM_JS_PATH!"
) ELSE (
  SET NPM_CMD=npm
  SET NODE_EXE=node
)

goto :EOF

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------
:Deployment
echo Handling node.js deployment.

echo %DEPLOYMENT_SOURCE%
echo %DEPLOYMENT_TARGET%

echo 1. Select node version
call :SelectNodeVersion

echo 2. Install npm packages
IF EXIST "%DEPLOYMENT_SOURCE%\package.json" (
  pushd "%DEPLOYMENT_SOURCE%"
  call :ExecuteCmd !NPM_CMD! install 
  IF !ERRORLEVEL! NEQ 0 goto error
  popd
)

echo 3. Install bower packages
IF EXIST "%DEPLOYMENT_SOURCE%\bower.json" (
  pushd "%DEPLOYMENT_SOURCE%"
  :: call :ExecuteCmd !NPM_CMD! install bower
  call "%DEPLOYMENT_SOURCE%"/node_modules/.bin/bower install -g --config.interactive=false
  IF !ERRORLEVEL! NEQ 0 goto error 
  popd
)


:RELEASE
echo 4. Install and run gulp [RELEASE]
IF EXIST "%DEPLOYMENT_SOURCE%\gulpfile.js" (
    pushd "%DEPLOYMENT_SOURCE%"
    call "%DEPLOYMENT_SOURCE%"/node_modules/.bin/gulp
    IF !ERRORLEVEL! NEQ 0 goto error 
    popd
)

echo 5. KuduSync [RELEASE]
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
    call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%/dist" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
    IF !ERRORLEVEL! NEQ 0 goto error
)
:EODEP

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Post deployment stub
IF DEFINED POST_DEPLOYMENT_ACTION call "%POST_DEPLOYMENT_ACTION%"
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.

这是在.deployment文件

中引用的
[config]
command = deploy.cmd