azure设置静态ip_在Microsoft Azure上运行Ruby Middleman静态站点生成器

azure设置静态ip

azure设置静态ip

Middleman is "a static site generator using all the shortcuts and tools in modern web development." With any static site generator you can run it all locally and then push/FTP/whatever the resulting HTML to any host. However, static site generators are even more fun when you can host the source code in Git and have your static site build and deploy in the cloud.

Middleman是“使用现代Web开发中所有快捷方式和工具的静态站点生成器”。 使用任何静态站点生成器,您都可以在本地运行它,然后将生成HTML推送/ FTP /任何内容推送到任何主机。 但是,当您可以在Git中托管源代码并在云中构建和部署静态站点时,静态站点生成器会更加有趣。

Middleman uses Ruby for its build system and views, and some of the Gems it uses are native gems. That means if you are a Windows user, your system will need not just Ruby, but the Ruby DevKit so you can build those native gems. The DevKit is a lovely set of tools that "makes it easy to build and use native C/C++ extensions such as RDiscount and RedCloth for Ruby on Windows."

Middleman将Ruby用于其构建系统和视图,并且它使用的某些Gems是本机gem。 这意味着,如果您是Windows用户,则系统将不仅需要Ruby,还需要Ruby DevKit,因此您可以构建这些本机gem。 DevKit是一套不错的工具,“可以轻松构建和使用Windows上的RDiscount和RedCloth等本机C / C ++扩展”。

Azure Websites supports not just ASP.NET today, but also node.js, PHP, Python, and Java, all built in. But not Ruby, directly, yet. Also, Azure Websites doesn't know formally about the idea of a static site generator. You might be thinking, oh, this'll be hard, I'll need to use a VM and do this myself.

Azure网站现在不仅支持ASP.NET,而且还支持全部内置的node.js,PHP,Python和Java。但是,尚不直接支持Ruby。 此外,Azure网站也不正式了解静态网站生成器的概念。 您可能会想,哦,这很难,我需要使用VM并自己完成。

However, even though Azure Websites are totally "platform as a service" there's still a Windows Virtual Machine underneath, and you can use the disk space however you like. You've got a LOT of control and can even get a hold of a console where you can run commands and install stuff. The Azure Portal lets you open a command line from your website.

但是,即使Azure网站完全是“平台即服务”,其下方仍然是Windows虚拟机,您可以随意使用磁盘空间。 您拥有很多控制权,甚至可以拥有一个控制台,您可以在其中运行命令并安装内容。 Azure门户使您可以从网站打开命令行。

The New Azure Portal

Check me out, here in the new Azure Portal. This is where I did my practice work to see if I could programmatically download and install Ruby via a script. I tried a number of different commands, all from the browser, and explored a number of ideas. When I got it working, I put together a batch file called GetRuby. I could have also used a shell script or PowerShell, but Batch was easy given what I was doing.

在新的Azure Portal中,在此处检查我。 这是我进行练习的地方,以查看是否可以通过脚本以编程方式下载和安装Ruby。 我尝试了许多不同的命令,所有这些命令都来自浏览器,并探索了许多想法。 当它开始工作时,我将一个名为GetRuby的批处理文件放在一起。 我也可以使用Shell脚本或PowerShell,但是考虑到我在做什么,批处理很容易。

ASIDE: You may recognize that console from this video I did about the "Super Secret Debug Console" in Azure. It's not so secret now, it's a feature.  There is still a cool debug "sidecar" website for every Azure site, it's at http://YOURSITENAME.scm.azurewebsites.net/DebugConsole but now a version of the console is in the portal as well.

旁白:您可能从我录制的有关Azure中“超级秘密调试控制台”的视频中认识到该控制台。 现在不是那么秘密了,它是一个功能。 每个Azure站点仍然有一个很酷的调试“ sidecar”网站,位于http://YOURSITENAME.scm.azurewebsites.net/DebugConsole,但现在门户中也有该控制台的版本。

Azure Websites uses an open source project called Kudu to deploy from locations with source like Github. Kudu supports custom deployment scripts where you can jump in and do whatever you like (within the limits of the security sandbox)

Azure网站使用名为Kudu的开源项目从具有Github之类的来源的位置进行部署。 Kudu支持自定义部署脚本,您可以在其中执行任何操作(在安全沙箱范围内)

Basically I needed to do these things before running Middleman on my source:

基本上,在源上运行Middleman之前,我需要执行以下操作:

  • Ensure Ruby is installed and in the path.

    确保Ruby已安装并且在路径中。
  • Ensure the DevKit (which includes native compilers, etc) is installed

    确保已安装DevKit(包括本地编译器等)
  • Initialize and setup DevKit for builds

    初始化并设置DevKit以进行构建
  • Update RubyGems to 2.2.3 until the Windows version of Ruby has this included

    将RubyGems更新为2.2.3,直到Windows版本的Ruby包含此版本为止
  • Install eventmachine 1.0.7, a problematic gem on Windows

    安装eventmachine 1.0.7,这是Windows上有问题的gem
  • Run the Ruby Bundler's update

    运行Ruby Bundler的更新
  • Install Middleman

    安装中间人

And then, every deployment run the Middleman static site generator.

然后,每个部署都运行Middleman静态站点生成器。

  • Middleman build

    中间人建立

The first part is a one time thing for a new website. I just need to make sure Ruby is around and in the path. The second part is what runs every time a source file for my static site generator is checked in. It runs middleman build. Then at the very end, Kudu takes the results from the /build folder and moves them to /wwwroot, which makes the changes live.

第一部分是新网站的一次性内容。 我只需要确保Ruby在路上并在路上即可。 第二部分是每次检入我的静态站点生成器的源文件时运行的内容。它运行Middleman构建。 然后,最后,Kudu从/ build文件夹中获取结果,并将其移至/ wwwroot,从而使更改生效。

Here's an annotated part of the first bit, but the actual file is on GitHub. Note that I'm putting stuff in %temp% for speed. Turns out %temp% a local drive, so it's a few times faster than using the main drive, which makes this deployment faster. However, it's cleared out often, so if I wanted things to be persistent but slower to deploy, I'd put them in D:\deployments\tools. As it is, the deploy is fast (less than a minute) when Ruby is there, and just about 3 minutes to get and setup Ruby when it's not. The exists check handles the case when a deploy happens but %temp% has been cleared so it'll get Ruby again.

这是第一部分的带注释部分,但实际文件位于GitHub上。 请注意,我将内容放入%temp%以提高速度。 原来%temp%是本地驱动器,所以它比使用主驱动器快几倍,这使部署速度更快。 但是,它经常被清除,因此,如果我希望事情是持久的但部署速度较慢,则可以将它们放在D:\ deployments \ tools中。 照原样,当有Ruby时,部署速度很快(不到一分钟),而在没有Ruby时,部署和部署大约只有3分钟。 存在检查处理部署发生但%temp%已清除的情况,因此它将再次获得Ruby。

NOTE: If this seems confusing or complex, it's because I like to give folks LOTS of detail. But just look at my repository. All we have is a standard "Middleman init" site plus the Azure-generator deploy.cmd and my getruby.cmd. That's all you need, plus a Basic Azure Website. The getruby.cmd is my automating what you'd have to any way on a Windows machine without Ruby.

注意:如果这看起来令人困惑或复杂,那是因为我想给人们很多细节。 但是,只需查看我的存储库即可。 我们所拥有的只是一个标准的“ Middleman init”网站,以及Azure生成器deploy.cmd和我的getruby.cmd。 这就是您所需要的,再加上一个基本的Azure网站。 getruby.cmd是我在没有Ruby的Windows机器上以任何方式自动执行的操作。

REM Note that D:\local\temp is a LOCAL drive on Azure, and very fast
SET PATH=%PATH%;D:\local\temp\r\ruby-2.1.5-x64-mingw32\bin

pushd %temp%
REM If you need things to be persistent, then put them elsewhere, not in TEMP
if not exist r md r
cd r
if exist ruby-2.1.5-x64-mingw32 goto end

echo No Ruby, need to get it!

REM Get 64-bit Ruby
curl -o ruby215.zip http://dl.bintray.com/oneclick/rubyinstaller/ruby-2.1.5-x64-mingw32.7z?direct
ECHO START Unzipping Ruby. 7Zip is already on Azure Websites
REM Note Azure deployments run faster with 7Zip not spewing so much. Redirect to a file.
d:\7zip\7za x -y ruby215.zip > out

REM Get DevKit to build Ruby native gems
REM If you don't need DevKit for your Gems, rem this out.
curl -o DevKit.zip http://cdn.rubyinstaller.org/archives/devkits/DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe
ECHO START Unzipping DevKit
d:\7zip\7za x -y -oDevKit DevKit.zip > out
ECHO DONE Unzipping DevKit

ruby DevKit\dk.rb init

REM Tell DevKit where Ruby is
echo --- > config.yml
echo - d:/local/temp/r/ruby-2.1.5-x64-mingw32 >> config.yml

REM Setup DevKit
ruby DevKit\dk.rb install

REM Update Gem223 until someone fixes the Ruby Windows installer https://github.com/oneclick/rubyinstaller/issues/261
curl -L -o update.gem https://github.com/rubygems/rubygems/releases/download/v2.2.3/rubygems-update-2.2.3.gem
call gem install --local update.gem
call update_rubygems --no-ri --no-rdoc > updaterubygemsout
ECHO What's our new Rubygems version?
call gem --version
call gem uninstall rubygems-update -x

REM This is needed on Windows, why is this gem such a problem?
ECHO Install eventmachine 1.0.7
call gem install eventmachine -v '1.0.7' --no-ri --no-rdoc > updateventmachineout

call bundle update

ECHO Install middleman...the whole point!
call gem install middleman --no-ri --no-rdoc

:end
popd

call middleman build

REM KuduSync and actual /build to /wwwroot is after this in deploy.cmd!

And in the Deploy.cmd all I needed to change was this under SETUP. This is where YOU can do whatever you like. Note since I'm using Batch, I need to put CALL in front of other Batch files (and Ruby uses them also!) otherwise my script will just end early.

在Deploy.cmd中,我所需要做的就是在SETUP下进行更改。 您可以在这里做任何您喜欢的事情。 请注意,由于我正在使用Batch,因此需要将CALL放在其他Batch文件的前面(Ruby也使用它们!),否则我的脚本将尽早结束。

ECHO CALLING GET RUBY

call getruby.cmd

ECHO WE MADE IT

Then later, still in Deploy.cmd, I just added \build to the source directory name.

然后,仍然在Deploy.cmd中,我只是在源目录名称中添加了\ build。

call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%\build" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"

And that's it.  Now whenever I updated my views or other things in my Middleman source on GitHub, it automatically deploys to my live site.

就是这样。 现在,每当我在GitHub上的Middleman源代码中更新视图或其他内容时,它就会自动部署到我的实时站点。

Yes, again, to be clear, I realize it's a static site generator that I could run locally and FTP the results, but I'm working in a small team and this is a great way for us to collaborate on our static site. Plus, when it's done, it's all done and I don't have to mess with it again.

是的,再次明确地说,我意识到这是一个静态站点生成器,可以在本地运行并通过FTP发送结果,但是我的工作小组很小,这是我们在静态站点上进行协作的一种好方法。 另外,完成后,一切都完成了,我不必再去麻烦它了。

Middleman Static Site Generator on Azure

调试自定义Azure网站部署 (Debugging Custom Azure Website Deployments)

I thought debugging my GetRuby batch file was going to be a nightmare. However, it turns out that the Azure cross-platform command line (the Azure x-plat CLI, open source, and written in nodejs, BTW) can connect to Azure's log streaming service. "Azure Site Log Tail" lets me see the LIVE console output as the deploy happens!

我以为调试我的GetRuby批处理文件将是一场噩梦。 但是,事实证明,Azure跨平台命令行(Azure x-plat CLI,开源,并用nodejs,BTW编写)可以连接到Azure的日志流服务。 当部署发生时, “ Azure Site Log Tail”让我看到LIVE控制台的输出!

Azure Site Log Tail

Now, note that the need for this whole "getruby.bat" file totally goes away if the Azure Websites folks start including Ruby and DevKit in the Azure Websites VM image by default. That would make Ruby, Rails, Gems, DevKit, etc. available to everyone. Do you want Ruby on Azure? Do you care? Sound off in the comments!

现在,请注意,如果默认情况下Azure网站人员开始在Azure Websites VM映像中包括Ruby和DevKit,则完全不需要整个“ getruby.bat”文件。 这将使每个人都可以使用Ruby,Rails,Gems,DevKit等。 您是否要在Azure上使用Ruby? 你关心? 在评论中听起来不错!

HELP: The batch file could use more testing, especially for robustness as well as Ruby-correctness as I'm likely confused about a few things, but it works for me and it's a great start. Sometimes different native gems don't build, though, or Gems complains about conflicting versions and asks me to run Bundler. I have no idea why. Running things twice clears it. It's either my bug or someone else's. :)

帮助:批处理文件可能需要进行更多测试,尤其是在鲁棒性和Ruby正确性方面,因为我可能对某些事情感到困惑,但这对我有用,这是一个很好的开始。 但是,有时有时无法构建不同的本地gem,或者Gems抱怨版本冲突,并要求我运行Bundler。 我不知道为什么。 运行两次可以清除它。 这是我的虫子还是别人的虫子。 :)

I'm just happy that Azure Websites is as flexible as it is that I was able to console into it from the browser, look around, add my own custom deployment hook, and do something I initially didn't think was possible!

我很高兴Azure网站如此灵活,因为我能够从浏览器中对其进行控制台,环顾四周,添加自己的自定义部署挂钩,并做一些我最初认为不可能的事情!

Give Azure Websites a try FOR FREE, no signup, no credit card for an hour in a sandbox with PHP, Node, ASP.NET, or Java at http://try.azurewebsites.net. (Full Disclosure, I helped a little with this site, so I'm a fan.)

在带有PHP,Node,ASP.NET或Java的沙箱中免费试用Azure网站一个小时,无需注册,也无需使用信用卡一小时,网址为http://try.azurewebsites.net 。 (完全公开,我在此站点上提供了一些帮助,所以我是粉丝。)

相关链接 (Related Links)

翻译自: https://www.hanselman.com/blog/running-the-ruby-middleman-static-site-generator-on-microsoft-azure

azure设置静态ip

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值