如何在部署之前缩小源代码

发布于 2024-12-23 05:32:54 字数 359 浏览 2 评论 0原文

我正在通过使用 capistrano 从 git 部署一个 php 项目。我目前正在通过一些 capistrano 任务来缩小我的 javascript (使用 jammit)和 css (使用 yui)。我看到的问题是,我是在目标服务器上进行这种缩小,而不是在本地预部署代码库。令人担忧的原因是,我将 javascript 压缩从 yui 切换到 jammit,并且当我的部署服务器已经安装了这个新的 ruby​​ gem 时,我不想在多个生产服务器上安装它。我从另一个开发人员那里继承了 capistrano 文件,所以我不是 100% 清楚代码何时检出、何时发送到远程服务器的过程,以及我应该挂钩什么任务。

我最初的想法是在“部署”之前执行此操作,但我再次不确定是否有可用的源代码。

I am deploying a php project from git through the use of capistrano. I am currently minifying my javascript (using jammit) and css (using yui) through some capistrano tasks already. The issue I see is that I am doing this minification on the destination servers rather than once locally pre-deployment of the code base. The cause of concern is that I switched the javascript minification from yui to jammit and do not want to have to install this new ruby gem on multiple production servers when my deployment servers already have it installed. I inherited the capistrano file from anohter developer so I'm not 100% clear on the process of when the code gets checked out, and when it gets sent to the remote server, and what task I should hook into.

My initial thought is to do it before "deploy" but again, am not sure I'll have the source code available to act on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑾兮 2024-12-30 05:32:54

简短的回答是“你不”。 deploy 钩子调用deploy:update_code

部署:update_code,{:例外=>{:no_release=>true}}

将您的项目复制到远程服务器。这是任何部署的第一阶段;将更新的代码和资产移动到部署服务器。但是,您很少会直接调用此任务;相反,您应该调用“部署”任务(以执行完整部署)或“更新”任务(如果您想单独执行“重新启动”任务)。

您需要确保将 :scm 变量设置为您正在使用的源代码管理软件(默认为 :subversion),并将 :deploy_via 变量设置为您要用于部署的策略(默认为:结帐)。

它将一次性执行以下操作:

  1. 签出代码
  2. 压缩代码
  3. 将代码移动到远程服务器
  4. 清理本地代码

(根据您的部署设置,会有一些变化)。

然而,
我能够通过使用下载和上传命令来解决这个问题。

tmp_path = "/tmp/#{release_name}/public"
download "#{current_path}/public/javascripts", "#{tmp_path}/javascripts/":via => :scp, :recurisve => true
system "jammit -o #{tmp_path}/javascripts -c #{tmp_path}/javascripts/assets.yml"
upload  "#{tmp_path}/javascripts/common.js", "#{current_path}/public/javascripts", :via => :scp
system "rm -rf #{tmp_path}"

我不喜欢它,因为它不太干净,但它可以按照我需要的方式完成工作。

The short answer is "you don't". The deploy hook calls deploy:update_code

deploy:update_code, {:except=>{:no_release=>true}}

Copies your project to the remote servers. This is the first stage of any deployment; moving your updated code and assets to the deployment servers. You will rarely call this task directly, however; instead, you should call the deploy’ task (to do a complete deploy) or theupdate’ task (if you want to perform the `restart’ task separately).

You will need to make sure you set the :scm variable to the source control software you are using (it defaults to :subversion), and the :deploy_via variable to the strategy you want to use to deploy (it defaults to :checkout).

Which does the following in one fell swoop:

  1. Checkout code
  2. Zip up code
  3. move code to remote server
  4. clean up local code

(with some variation depending on your deployment settings).

However,
I was able to to get around this by utilizing the download and upload commands.

tmp_path = "/tmp/#{release_name}/public"
download "#{current_path}/public/javascripts", "#{tmp_path}/javascripts/":via => :scp, :recurisve => true
system "jammit -o #{tmp_path}/javascripts -c #{tmp_path}/javascripts/assets.yml"
upload  "#{tmp_path}/javascripts/common.js", "#{current_path}/public/javascripts", :via => :scp
system "rm -rf #{tmp_path}"

I don't like it as it's not quite as clean, but it gets the job done the way I need to get it done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文