在豆茎图像中找不到捆绑包
Posted
技术标签:
【中文标题】在豆茎图像中找不到捆绑包【英文标题】:bundle not found in beanstalk image 【发布时间】:2018-06-24 11:11:45 【问题描述】:我尝试将一个 docker 容器部署到 AWS Elastic Beanstalk,但无法进行迁移。在本地使用以下Dockerfile
时,我可以运行docker exec [image] bundle exec rake db:migrate
以毫无问题地运行迁移,但是在将图像上传到ECR 并运行我的部署后,我的ebextension
出错,无法找到bundle
,如日志末尾所示。不过,日志还显示 bundle
已安装并正在安装软件包。我错过了什么?
Dockerfile
FROM phusion/passenger-ruby24:0.9.27
MAINTAINER openback@gmail.com
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \
build-essential \
nodejs \
tzdata
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Set correct environment variables.
ENV HOME /root
# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]
# === 3 ====
# By default nginx clears all environment variables (except TZ). Tell Nginx to
# preserve these variables. See nginx-env.conf.
COPY nginx-env.conf /etc/nginx/main.d/rails-env.conf
# Nginx and Passenger are disabled by default. Enable them (start Nginx/Passenger).
RUN rm -f /etc/service/nginx/down
# Expose Nginx HTTP service
EXPOSE 80
# === 4 ===
# Our application should be placed inside /home/app. The image has an app user
# with UID 9999 and home directory /home/app. Our application is supposed to run
# as this user. Even though Docker itself provides some isolation from the host
# OS, running applications without root privileges is good security practice.
RUN mkdir -p /home/app/myapp
WORKDIR /home/app/myapp
# Run Bundle in a cache efficient way. Before copying the whole app, copy just
# the Gemfile and Gemfile.lock into the tmp directory and ran bundle install
# from there. If neither file changed, both instructions are cached. Because
# they are cached, subsequent commands—like the bundle install one—remain
# eligible for using the cache. Why? How? See ...
# http://ilikestuffblog.com/2014/01/06/how-to-skip-bundle-install-when-deploying-a-rails-app-to-docker/
COPY app/Gemfile /home/app/myapp/
COPY app/Gemfile.lock /home/app/myapp/
RUN chown -R app:app /home/app/myapp
RUN gem install bundler && bundle install --jobs 20 --retry 5
# === 5 ===
# Adding our web app to the image ... only after bundling do we copy the rest of
# the app into the image.
COPY app /home/app/myapp
RUN chown -R app:app /home/app/myapp
# === 6 ===
# Remove the default site. Add a virtual host entry to Nginx which describes
# where our app is, and Passenger will take care of the rest. See nginx.conf.
RUN rm /etc/nginx/sites-enabled/default
COPY nginx.conf /etc/nginx/sites-enabled/myapp.conf
# Enable insecure SSH when in development mode
RUN if [ "$PASSENGER_APP_ENV" = "development" ]; then rm -f /etc/service/sshd/down; fi
RUN if [ "$PASSENGER_APP_ENV" = "development" ]; then /etc/my_init.d/00_regen_ssh_host_keys.sh; fi
.ebextensions/01_db_migrate.config
container_commands:
db_migrate:
command: bundle exec rake db:migrate
leader_only: true
eb-activity.log
[2018-01-14T21:10:51.873Z] INFO [3552] - [Application deployment app-1d8d-180114_160901@1/StartupStage0/AppDeployPreHook/03build.sh] : Starting activity...
[2018-01-14T21:14:17.998Z] INFO [3552] - [Application deployment app-1d8d-180114_160901@1/StartupStage0/AppDeployPreHook/03build.sh] : Completed activity. Result:
0.9.27: Pulling from phusion/passenger-ruby24
[...]
Step 1 : FROM phusion/passenger-ruby24:0.9.27
---> f1736db761ba
Step 2 : MAINTAINER openback@gmail.com
---> Running in dcddb323b1ab
---> 34d8ff7058b7
Removing intermediate container dcddb323b1ab
Step 3 : RUN apt-get update && apt-get install -y build-essential nodejs tzdata
---> Running in 1af39b2532c2
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
[...]
Get:36 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7,146 B]
Fetched 26.6 MB in 13s (1,996 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
build-essential is already the newest version (12.1ubuntu2).
nodejs is already the newest version (4.2.6~dfsg-1ubuntu4.1).
The following NEW packages will be installed:
tzdata
0 upgraded, 1 newly installed, 0 to remove and 64 not upgraded.
Need to get 166 kB of archives.
After this operation, 2,857 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 tzdata all 2017c-0ubuntu0.16.04 [166 kB]
ESC[91mdpkg-preconfigure: unable to re-open stdin:
ESC[0mFetched 166 kB in 0s (231 kB/s)
Selecting previously unselected package tzdata.
(Reading database ... ^M(Reading database ... 5%^M(Reading database ... 10%^M(Reading database ... 15%^M(Reading database ... 20%^M(Reading database ... 25%^M(Reading database ... 30%^M(Reading database ... 35%^M(Reading database ... 40%^M(Reading database ... 45%^M(Reading database ... 50%^M(Reading database ... 55%^M(Reading database ... 60%^M(Reading database ... 65%^M(Reading database ... 70%^M(Reading database ... 75%^M(Reading database ... 80%^M(Reading database ... 85%^M(Reading database ... 90%^M(Reading database ... 95%^M(Reading database ... 100%^M(Reading database ... 17457 files and directories currently installed.)
Preparing to unpack .../tzdata_2017c-0ubuntu0.16.04_all.deb ...
Unpacking tzdata (2017c-0ubuntu0.16.04) ...
Setting up tzdata (2017c-0ubuntu0.16.04) ...
Current default time zone: 'Etc/UTC'
Local time is now: Sun Jan 14 21:11:42 UTC 2018.
Universal Time is now: Sun Jan 14 21:11:42 UTC 2018.
Run 'dpkg-reconfigure tzdata' if you wish to change it.
---> e053efc9754a
Removing intermediate container 1af39b2532c2
Step 4 : RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
---> Running in 8782ccaa3e8c
---> 503b9f167e76
Removing intermediate container 8782ccaa3e8c
Step 5 : ENV HOME /root
---> Running in 5bf2d12026a5
---> 25ffac45422f
Removing intermediate container 5bf2d12026a5
Step 6 : CMD /sbin/my_init
---> Running in 2f803f206f93
---> 5aa04afc6b64
Removing intermediate container 2f803f206f93
Step 7 : COPY nginx-env.conf /etc/nginx/main.d/rails-env.conf
---> b99cd4eacc70
Removing intermediate container 5c802eda0143
Step 8 : RUN rm -f /etc/service/nginx/down
---> Running in 2345a642a3df
---> 4ef9f33afcb3
Removing intermediate container 2345a642a3df
Step 9 : EXPOSE 80
---> Running in 3220f867b8eb
---> 2f9056eb40cf
Removing intermediate container 3220f867b8eb
Step 10 : RUN mkdir -p /home/app/myapp
---> Running in ac59014fcb80
---> aa94da5606c8
Removing intermediate container ac59014fcb80
Step 11 : WORKDIR /home/app/myapp
---> Running in 47bc5bb22156
---> a92ce1ccf8af
Removing intermediate container 47bc5bb22156
Step 12 : COPY app/Gemfile /home/app/myapp/
---> f26d34889f00
Removing intermediate container 62d0f23c32f0
Step 13 : COPY app/Gemfile.lock /home/app/myapp/
---> 9c894a82eadc
Removing intermediate container cdb974da3596
Step 14 : RUN chown -R app:app /home/app/myapp
---> Running in b324a7fca911
---> 28316c52ffbe
Removing intermediate container b324a7fca911
Step 15 : RUN gem install bundler && bundle install --jobs 20 --retry 5
---> Running in 301e2891ec7c
Successfully installed bundler-1.16.1
1 gem installed
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/.........
Using rake 12.0.0
Fetching i18n 0.8.1
Using minitest 5.10.1
Fetching thread_safe 0.3.6
Fetching builder 3.2.3
Fetching erubi 1.6.0
Fetching mini_portile2 2.1.0
Fetching rack 2.0.1
Fetching nio4r 2.0.0
Fetching websocket-extensions 0.1.2
Fetching mime-types-data 3.2016.0521
Fetching concurrent-ruby 1.0.5
Fetching jsonapi-renderer 0.1.2
Fetching arel 8.0.0
Fetching bcrypt 3.1.11
Using bundler 1.16.1
[...]
Installing rspec-rails 3.5.2
Bundle complete! 21 Gemfile dependencies, 81 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
---> ceb46d19cdbe
Removing intermediate container 301e2891ec7c
Step 16 : COPY app /home/app/myapp
---> 37438b355ef1
Removing intermediate container 472247b188f3
Step 17 : RUN chown -R app:app /home/app/myapp
---> Running in d8f4d671ebfc
---> 63107ffadaf0
Removing intermediate container d8f4d671ebfc
Step 18 : RUN rm /etc/nginx/sites-enabled/default
---> Running in b9c790199ec0
---> 28e9a9e2eb47
Removing intermediate container b9c790199ec0
Step 19 : COPY nginx.conf /etc/nginx/sites-enabled/myapp.conf
---> ee5f7b4707a9
Removing intermediate container d9f68c634c63
Step 20 : RUN if [ "$PASSENGER_APP_ENV" = "development" ]; then rm -f /etc/service/sshd/down; fi
---> Running in 3230417a11be
---> 76ffc8862b1e
Removing intermediate container 3230417a11be
Step 21 : RUN if [ "$PASSENGER_APP_ENV" = "development" ]; then /etc/my_init.d/00_regen_ssh_host_keys.sh; fi
---> Running in 85ed9557eba3
---> 16105a75b008
Removing intermediate container 85ed9557eba3
Successfully built 16105a75b008
Successfully built aws_beanstalk/staging-app
[2018-01-14T21:14:17.999Z] INFO [3552] - [Application deployment app-1d8d-180114_160901@1/StartupStage0/AppDeployPreHook] : Completed activity. Result: Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/pre.
[2018-01-14T21:14:17.999Z] INFO [3552] - [Application deployment app-1d8d-180114_160901@1/StartupStage0/EbExtensionPostBuild] : Starting activity...
[2018-01-14T21:14:18.308Z] INFO [3552] - [Application deployment app-1d8d-180114_160901@1/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
[2018-01-14T21:14:18.309Z] INFO [3552] - [Application deployment app-1d8d-180114_160901@1/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_APPNAME] : Starting activity...
[2018-01-14T21:14:18.543Z] INFO [3552] - [Application deployment app-1d8d-180114_160901@1/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_APPNAME/Command db_migrate] : Starting activity...
[2018-01-14T21:14:18.550Z] INFO [3552] - [Application deployment app-1d8d-180114_160901@1/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_APPNAME/Command db_migrate] : Activity execution failed, because: /bin/sh: bundle: command not found (ElasticBeanstalk::ExternalInvocationError)
【问题讨论】:
【参考方案1】:所以经过更多搜索,我发现我对 container_commands
感到困惑,因为我对 Beanstalk 感到困惑。 Beanstalk 启动 AWS 提供的 docker 容器,在其中运行 docker
并使用您的图像。所以container_commands
在 AWS 容器中运行一个命令,而不是更深一层,这是我的容器。
我在那里运行迁移仍然有问题,但我更接近了。
【讨论】:
以上是关于在豆茎图像中找不到捆绑包的主要内容,如果未能解决你的问题,请参考以下文章
webpack css-loader 在外部样式表的 url() 引用中找不到图像
在捆绑包 NSBundle 中找不到名为“Storyboard.storyboard”的故事板
Xcode 11 在捆绑包 NSBundle 中找不到名为“Main”的情节提要