Docker作为有效的Rails开发环境

时间:2021-01-23 23:33:39

[UPDATE]

Unfortunately, dear colleagues, I gave up on docker for now. Main factors:

不幸的是,亲爱的同事们,我现在放弃了码头工作者。主要因素:

  • Poor shared volume performance (there are some workarounds using additional tools, but it seems more of a hack). This is not an issue for those fine folks that use Linux, though!
  • 共享卷的性能很差(有一些使用其他工具的解决方法,但它似乎更像是一个黑客攻击)。但对于那些使用Linux的优秀人员来说,这不是问题!
  • I have underrated some upfront work, which is required to make remote runtimes play nicely with editors/IDEs. Things like linting assume a local runtime out of the box and it seems the most widespread solution is a myriad of bash wrapper scripts to delegate execution to a docker container.
  • 我已经低估了一些前期工作,这需要使远程运行时与编辑器/ IDE很好地协同工作。像linting这样的东西假设一个开箱即用的本地运行时,似乎最普遍的解决方案是无数的bash包装器脚本将执行委托给docker容器。

Also we hired two DevOps guys, who have quite a bit of docker experience, if they will come up, how to (painlessly!) introduce docker in our company for both hosting and development, I will be happy to revise this topic.

我们还雇了两个DevOps人员,他们有相当多的码头工作经验,如果他们会出现,如何(无痛地!)在我们公司引入docker进行托管和开发,我很乐意修改这个话题。


[OLD POST]

[旧帖子]

As a new version utilising native OSX hypervisor is now available, I've decided to try pushing all my Ruby/Rails/JS development to the docker containers. I've played quite a bit on a fresh El Capitan installation, by trying to dockerize a few private gems we have and our monolith Rails application.

由于现在可以使用本机OSX管理程序的新版本,我决定尝试将所有Ruby / Rails / JS开发推送到docker容器。我在一个新的El Capitan装置上玩了很多,试图将我们拥有的一些私人宝石和我们的monolith Rails应用程序对接。

There are a few questions, I was hoping our community may help to solve.

有几个问题,我希望我们的社区可以帮助解决。

The goal - everything works and host has only iTerm, git, Sublime, SourceTree and Docker installed (nothing is carved in stone, if some additional dependency(-ies) may improve/make the workflow significantly easier, I will be happy to review the options)

目标 - 一切正常,主机只安装了iTerm,git,Sublime,SourceTree和Docker(没有什么是一成不变的,如果一些额外的依赖(-ies)可能会改善/使工作流程变得更加容易,我将很乐意审查选项)

Requirements

要求

  • There are quite a few services (EngineYard, ElastiBeanstalk, Github etc) that require my keys to function correctly, I should be able to reuse the ones that are on my host machine.
  • 有很多服务(EngineYard,ElastiBeanstalk,Github等)需要我的密钥才能正常运行,我应该能够重用我主机上的密钥。
  • Reusing installed RubyGems across all Ruby app containers would be nice. Basically docker container/docker-compose file is setup in a way that it mounts the same directory that will be a GEM_PATH, bundler in each container will install gems there. Application bundler should take care of loading the right versions.
  • 在所有Ruby应用程序容器中重用已安装的RubyGems会很不错。基本上docker container / docker-compose文件的安装方式是它安装了一个GEM_PATH的同一目录,每个容器中的bundler将在那里安装gem。应用程序捆绑器应该负责加载正确的版本。
  • I should be able to debug code easily - putting breakpoints and interacting with debugger as it would be running locally
  • 我应该能够轻松地调试代码 - 放置断点并与调试器进行交互,因为它将在本地运行
  • It should support TDD cycle - I change file, it's caught by guard process in the container and related tests are executed
  • 它应该支持TDD循环 - 我更改文件,它被容器中的保护进程捕获并执行相关测试
  • When executing Cucumber/Selenium tests I should be able to see what's happening in the browsers. (As I understand the options are - connecting through VNC to virtual frame buffer or running X server locally. I'd prefer options that involve less dependencies on the host side).
  • 执行Cucumber / Selenium测试时,我应该能够看到浏览器中发生了什么。 (据我所知,选项是 - 通过VNC连接到虚拟帧缓冲区或在本地运行X服务器。我更喜欢在主机端具有较少依赖性的选项)。

Questions

问题

  • Dockerizing existing apps is relatively easy these days, how do you, good people, handle creation/bootstrapping new projects? Common dev container that has usual dependencies?
  • 如今,对现有应用程序进行Docker化相对容易,您,好人,如何处理创建/引导新项目?具有通常依赖性的公共开发容器?
  • Is it possible to setup the things the way that container "keeps running" more or less like a VM? (This may solve lots of my requirements - running guard, easier debugging, launching arbitrary processes in the same run)
  • 是否有可能以容器“持续运行”的方式设置或多或少像VM一样? (这可能解决了我的许多要求 - 运行后卫,更容易调试,在同一次运行中启动任意进程)
  • I intend to use docker to pack our application for CI purposes. This means that for different environments, there might be a slightly different dependencies, also mounted volumes will differ (probably container for CI won't have those). Should it be solved as different config in docker-compose.yml (volumes) or defined inside a different docker file that inherits from the base one ?
  • 我打算使用docker打包我们的CI应用程序。这意味着对于不同的环境,可能存在稍微不同的依赖关系,也会使安装的卷不同(可能CI的容器不会具有这些容器)。它应该在docker-compose.yml(卷)中作为不同的配置解决,还是在从底层继承的另一个docker文件中定义?

Other thoughts

其他想法

I am also fine trying out commercial or none-commercial tool, that wraps/bundles the described tooling. So far I've found a thing called http://wercker.com), the thing I don't like about it, it seems like it requires you to setup dev env anyways, which kill the purpose of the whole endeavour.

我也很好地尝试商业或非商业工具,包装/捆绑所描述的工具。到目前为止,我发现了一个名为http://wercker.com的东西,我不喜欢它,似乎它需要你设置dev env,这会杀死整个努力的目的。

Feel free to down vote this question if it was posted before and answered clearly. On the other hand I would be happy if this thread will produce guides, links, suggestions to get it done smoothly, I am pretty sure this interests quite a few devs these days.

如果之前发布并明确回答,请随意向下投票。另一方面,如果这个帖子会产生指南,链接,建议顺利完成,我会很高兴,我很确定这些日子里有很多开发人员。

2 个解决方案

#1


3  

Consider orats (opinionated rails application templates):

考虑orats(固定的rails应用程序模板):

The goal is to provide you an excellent base application that you can use on your next Rails project.

目标是为您提供一个出色的基础应用程序,您可以在下一个Rails项目中使用它。

And:

和:

It also happens to use Docker so that your app can be ran on any major platform -- even without needing Ruby installed.

它也碰巧使用Docker,因此您的应用程序可以在任何主要平台上运行 - 即使不需要安装Ruby。


To some of your other requirements:

对于您的其他一些要求:

  • my keys ... I should be able to reuse the ones that are on my host machine

    我的钥匙......我应该可以重复使用主机上的那些

    Specify keys in your docker-compose.yml but omit the value.

    在docker-compose.yml中指定键但省略该值。

  • putting breakpoints and interacting with debugger

    放置断点并与调试器交互

    When starting a service, instead of docker-compose up, use docker-compose run --service-ports. This will allow e.g. binding.pry to work.

    在启动服务时,使用docker-compose run --service-ports而不是docker-compose。这将允许例如binding.pry工作。

  • When executing Cucumber/Selenium tests I should be able to see what's happening in the browsers.

    执行Cucumber / Selenium测试时,我应该能够看到浏览器中发生了什么。

    This is tricky. For a workaround consider using save_screenshot, and (the important part) save it to a directory which is mounted to a volume on the Docker host. Open that directory on the host and you'll be able to see an updating screenshot.

    这很棘手。有关解决方法,请考虑使用save_screenshot,并将(重要部分)保存到安装到Docker主机上的卷的目录中。在主机上打开该目录,您将能够看到更新的屏幕截图。

#2


0  

some notes about usage docker for development:

有关使用docker进行开发的一些注意事项:

  • run bash command inside docker and to work as in VM, link
  • 在docker中运行bash命令并在VM中工作,链接
  • map port of container with host machine and use browser link
  • 使用主机映射容器端口并使用浏览器链接
  • map files link
  • 地图文件链接
  • .env technique of setting variables allows usage of docker in any environment including CI link
  • .env设置变量的技术允许在包括CI链接的任何环境中使用docker
  • bash scripts and container naming can help to automate tasks link
  • bash脚本和容器命名可以帮助自动化任务链接

#1


3  

Consider orats (opinionated rails application templates):

考虑orats(固定的rails应用程序模板):

The goal is to provide you an excellent base application that you can use on your next Rails project.

目标是为您提供一个出色的基础应用程序,您可以在下一个Rails项目中使用它。

And:

和:

It also happens to use Docker so that your app can be ran on any major platform -- even without needing Ruby installed.

它也碰巧使用Docker,因此您的应用程序可以在任何主要平台上运行 - 即使不需要安装Ruby。


To some of your other requirements:

对于您的其他一些要求:

  • my keys ... I should be able to reuse the ones that are on my host machine

    我的钥匙......我应该可以重复使用主机上的那些

    Specify keys in your docker-compose.yml but omit the value.

    在docker-compose.yml中指定键但省略该值。

  • putting breakpoints and interacting with debugger

    放置断点并与调试器交互

    When starting a service, instead of docker-compose up, use docker-compose run --service-ports. This will allow e.g. binding.pry to work.

    在启动服务时,使用docker-compose run --service-ports而不是docker-compose。这将允许例如binding.pry工作。

  • When executing Cucumber/Selenium tests I should be able to see what's happening in the browsers.

    执行Cucumber / Selenium测试时,我应该能够看到浏览器中发生了什么。

    This is tricky. For a workaround consider using save_screenshot, and (the important part) save it to a directory which is mounted to a volume on the Docker host. Open that directory on the host and you'll be able to see an updating screenshot.

    这很棘手。有关解决方法,请考虑使用save_screenshot,并将(重要部分)保存到安装到Docker主机上的卷的目录中。在主机上打开该目录,您将能够看到更新的屏幕截图。

#2


0  

some notes about usage docker for development:

有关使用docker进行开发的一些注意事项:

  • run bash command inside docker and to work as in VM, link
  • 在docker中运行bash命令并在VM中工作,链接
  • map port of container with host machine and use browser link
  • 使用主机映射容器端口并使用浏览器链接
  • map files link
  • 地图文件链接
  • .env technique of setting variables allows usage of docker in any environment including CI link
  • .env设置变量的技术允许在包括CI链接的任何环境中使用docker
  • bash scripts and container naming can help to automate tasks link
  • bash脚本和容器命名可以帮助自动化任务链接