Dockerfile生产/构建/调试/测试环境 [英] Dockerfile production/build/debug/test environment

查看:417
本文介绍了Dockerfile生产/构建/调试/测试环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,您有您的Web应用程序和一些工作流程执行程序:




  • http-server(提供预构建资产文件) - 生产

  • 构建器(从源代码编译/捆绑js / css / html) - 部署/开发

  • 调试器/构建器js源地图) - 开发

  • selenium(运行测试) - 集成测试



我们构建分层图像以使这些工作流执行者最有效地工作?有效地,我的意思是最快运行和最少写。

解决方案

答案可能很简单:只需创建4 Dockerfile s取决于另一个。



您可以添加一个卷以从源部分共享构建。问题是您是否希望将结果资产包含在图像中或者每次从源代码构建。



创建4个文件夹以使 Dockerfile



生产



production / Dockefile

  FROM#put server here 
COPY#put配置这里
#一些其他选项
#卷共享?

构建



build / Dockerfile

 #install dependencies 
ADD#add sources here
RUN#some building script

调试



debug / Dockefile

 #理想情况下,配置生产或构建映像

测试



test / Dockefile

  FROM#import production 
#install test dependencies
RUN#test runner

还有几个选项。
1.使用.gitignore与负模式(或ADD?)

  * 
!directory-i -want-to-add
!另一个目录我想要添加

Plus使用docker命令指定dockerfiles和上下文:

  docker build -t my / debug-image -f docker-debug。 
docker build -t my / serve-image -f docker-serve。
docker build -t my / build-image -f docker-build。
docker build -t my / test-image -f docker-test。

您还可以使用不同的gitignore文件。



< ol start =2>
  • 装载卷
    跳过发送上下文,只需在运行时使用安装卷(使用 -v host-dir:/ docker- dir )。

  • 所以你必须:

      docker build -t my / build-image -f docker-build。 #build`build`图像(devtools像gulp,grunt,bundle,npm等)
    docker run -v output:/ output my / build-image build-command#将文件复制到输出目录
    docker建立-t我/服务图像-f码头服务。 #从生产dir生成
    docker运行我的/ serve-image#从包含或装载dir
    docker build -t my / serve-image -f docker-debug。 #build debug from output dir
    docker运行我的/ serve-image#debug-like服务(使用构建图像与一些手表魔术)


    Imagine you have your web application and some workflow executors:

    • http-server (serving pre-build asset files) - production
    • builder (compiling/bundling js/css/html from sources) - deployment/development
    • debugger/builder (building from sources on the fly, add js source maps) - development
    • selenium (running tests) - integration testing

    How can we construct layered images to get those workflow executors working the most effectively? By effectively I mean "fastest to run and least to write".

    解决方案

    The answer might be straightforward: just create 4 Dockerfiles one depending on another.

    You can add a volume to share build from sources part. The question is whether you want result assets to be included in the image or build it from sources each time.

    Create 4 folders to have Dockerfile in each.

    Production

    production/Dockefile:

    FROM  # put server here
    COPY  # put config here
    # some other option
    # volume sharing?
    

    Build

    build/Dockerfile:

    # install dependencies
    ADD # add sources here
    RUN # some building script
    

    Debug

    debug/Dockefile:

    # ideally, configure production or build image
    

    Test

    test/Dockefile:

    FROM # import production
    # install test dependencies
    RUN # test runner
    

    There are also several options. 1. Use .gitignore with negative pattern (or ADD?)

    *
    !directory-i-want-to-add
    !another-directory-i-want-to-add
    

    Plus use docker command specifying dockerfiles and context:

    docker build -t my/debug-image -f docker-debug .
    docker build -t my/serve-image -f docker-serve .
    docker build -t my/build-image -f docker-build .
    docker build -t my/test-image -f docker-test .
    

    You could also use different gitignore files.

    1. Mount volumes Skip sending context at all, just use mounting volumes during run time (using -v host-dir:/docker-dir).

    So you'd have to:

    docker build -t my/build-image -f docker-build . # build `build` image (devtools like gulp, grunt, bundle, npm, etc)
    docker run -v output:/output my/build-image build-command # copies files to output dir
    docker build -t my/serve-image -f docker-serve . # build production from output dir
    docker run my/serve-image # production-like serving from included or mounted dir
    docker build -t my/serve-image -f docker-debug . # build debug from output dir
    docker run my/serve-image # debug-like serving (uses build-image with some watch magic)
    

    这篇关于Dockerfile生产/构建/调试/测试环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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