使用EB扩展在AmazonLinux2上运行软件包安装命令



我正在使用Amazon Linux 2 EC2实例在Elastic Beanstalk上运行ASP.NET Core 3.1应用程序。我需要我的应用程序能够生成二维码,为此我使用了QRCoder库。它在我的Windows机器上开箱即用,但为了在AmazonLinux2机器上运行,我必须通过SSH运行以下命令:

sudo amazon-linux-extras install epel
sudo yum install libgdiplus

运行完这些命令后,EB应用程序服务器也需要重新启动才能生成图像。

我试图通过在我的应用程序repo根目录中创建.ebextensions/install_gdi.config文件来编写脚本,其中包含以下内容:

commands:
00_install_extras:
command: amazon-linux-extras install -y epel
01_install_gdi:
command: yum install -y libgdiplus

我重新构建了Beanstalk环境,重新部署了新的EC2实例版本,但EB扩展配置文件似乎什么都没做。在我通过SSH连接并在EC2实例上手动运行这些命令之前,仍然无法生成映像。

我读到有其他方法可以自动为AmazonLinux2提供实例,但我找不到好的例子来探索预部署挂钩和Buildfile之类的东西,在这种情况下,EB扩展似乎也是合适的工具。

我的应用程序是使用AWS CodePipeline部署到Elastic Beanstalk的,它连接到GitHub回购。

我试图用AmazonLinux2在EB上复制这个问题,但您的commands运行得非常好。我使用的是Python平台,而不是.NET,但由于两者都基于AL2,我不明白为什么它们在这方面会有所不同。

排除故障,您可以ssh到您的EB实例中,或者从控制台下载EB日志并检查/var/log/cfn-init-cmd.log。它应该包含有关install_gdi.config执行的详细信息。

为了进行比较,我附上了我的输出:

2020-08-30 05:34:52,631 P3617 [INFO] Command 01_install_gdi
2020-08-30 05:35:08,423 P3617 [INFO] -----------------------Command Output-----------------------
2020-08-30 05:35:08,423 P3617 [INFO]    Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
2020-08-30 05:35:08,423 P3617 [INFO]    http://csc.mcs.sdsmt.edu/epel/7/x86_64/repodata/0e811d5e2eb547161695f97c2fb8c2eaa0ccfe0ba7125321404db90dab5af5b3-updateinfo.xml.bz2: [Errno 12] Timeout on http://csc.mcs.sdsmt.edu/epel/7/x86_64/repodata/0e811d5e2eb547161695f97c2fb8c2eaa0ccfe0ba7125321404db90dab5af5b3-updateinfo.xml.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 5 seconds')
2020-08-30 05:35:08,423 P3617 [INFO]    Trying other mirror.
2020-08-30 05:35:08,423 P3617 [INFO]    200 packages excluded due to repository priority protections
2020-08-30 05:35:08,423 P3617 [INFO]    Resolving Dependencies
2020-08-30 05:35:08,424 P3617 [INFO]    --> Running transaction check
2020-08-30 05:35:08,424 P3617 [INFO]    ---> Package libgdiplus.x86_64 0:2.10-10.el7 will be installed
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libXrender.so.1()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libcairo.so.2()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libexif.so.12()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libgif.so.4()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
#
# more logs
#
2020-08-30 05:35:08,433 P3617 [INFO]
2020-08-30 05:35:08,433 P3617 [INFO]    Installed:
2020-08-30 05:35:08,434 P3617 [INFO]      libgdiplus.x86_64 0:2.10-10.el7
2020-08-30 05:35:08,434 P3617 [INFO]
#
# more logs
#
2020-08-30 05:35:08,435 P3617 [INFO]    Complete!
2020-08-30 05:35:08,435 P3617 [INFO] ------------------------------------------------------------
2020-08-30 05:35:08,435 P3617 [INFO] Completed successfully.

问题出在我的buildspec.yml文件上。

它以前是这样的,并且它没有将.ebxtensions文件夹包含在发布工件文件夹中:

version: 0.2
phases:
build:
commands:
- dotnet publish WebApi.csproj -c Release
artifacts:
files:
- bin/Release/netcoreapp3.1/publish/*
discard-paths: yes

我把它改成这样,现在它可以工作了:

version: 0.2
phases:
build:
commands:
- dotnet publish WebApi.csproj -c Release
artifacts:
files:
- '**/*'
base-directory: bin/Release/netcoreapp3.1/publish

相关内容

最新更新