在Docker容器内部或外部运行Grunt / Gulp? [英] Run Grunt / Gulp inside Docker container or outside?

查看:195
本文介绍了在Docker容器内部或外部运行Grunt / Gulp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试为使用grunt / gulp部署在Docker容器中的nodejs应用程序的构建过程确定一个良好的做法。非常满意以下序列:


  • 使用容器外部的grunt(或gulp)构建

  • add ./dist文件夹到容器

  • 运行npm install(带--production标志)在容器内



但是,在我找到的每个示例中,我都看到了不同的方法:


  • 将./src文件夹添加到容器中

  • 在容器中运行npm install(使用dev依赖项)

  • 运行bower install(如果需要) gulp)在容器内



IMO,第一种方法生成更轻且更高效的容器,但所有示例都使用第二种方法。我是否错过了什么?

解决方案

我看到的唯一区别是您可以在第二种方法中重现完整的grunt安装。 / p>

在第一种情况下,您取决于可能在不同环境中以不同方式完成的本地操作。

一个容器应该放在一个可以容易地复制的图像中,而不是依赖于包含需要什么的主文件夹(不知道该部分是如何完成的)。

< hr>

如果安装时出现的构建环境开销太大而无法使用图像,您可以:



然后最终结果是带有应用程序的图片目前在其文件系统上。



这是您的方法1和2之间的混合。


I'm trying to identify a good practice for the build process of a nodejs app using grunt/gulp to be deployed inside a docker container.

I'm pretty happy with the following sequence:

  • build using grunt (or gulp) outside container
  • add ./dist folder to container
  • run npm install (with --production flag) inside container

But in every example I find, I see a different approach:

  • add ./src folder to container
  • run npm install (with dev dependencies) inside container
  • run bower install (if required) inside container
  • run grunt (or gulp) inside container

IMO, the first approach generates a lighter and more efficient container, but all of the examples out there are using the second approach. Am I missing something?

解决方案

The only difference I see is that you can reproduce a full grunt installation in the second approach.

With the first one, you depend on a local action which might be done differently, on different environments.

A container should be based in an image that can be reproduced easily instead of depending on an host folder which contains "what is needed" (not knowing how that part has been done)


If the build environment overhead which comes with the installation is too much for a grunt image, you can:

  • create an image "app.tar" dedicated for the installation (I did that for Apache, that I had to recompile, creating a deb package in a shared volume).
    In your case, you can create an archive ('tar') of the app installed.
  • creating a container from a base image, using the volume from that first container

    docker run --it --name=app.inst --volumes-from=app.tar ubuntu untar /shared/path/app.tar
    docker commit app.inst app
    

Then end result is an image with the app present on its filesystem.

This is a mix between your approach 1 and 2.

这篇关于在Docker容器内部或外部运行Grunt / Gulp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆