如何在 Elastic Beanstalk 上添加 PATH

6

我希望在eb deploy中添加PATH到包中。 包安装到/var/www/html/vendor/bin

可以通过SSH手动添加,但是如何通过配置文件添加PATH

我有这样的配置文件.ebextensions/ec2.config01-set_timezone正常工作,02-set_path不起作用。

commands:
  01-set_timezone:
    command: cp /usr/share/zoneinfo/Japan /etc/localtime
  02-set_path:
    command: export PATH=$PATH:/var/www/html/vendor/bin
2个回答

10

每个命令都在自己的shell中执行,所以导出不起作用。你需要将它放入~/.bash_profile中,以确保每个新命令都会执行。

commands:
  set_path:
    test: test ! -f /opt/elasticbeanstalk/.post-provisioning-complete
    command: echo 'export PATH=$PATH:/var/www/html/vendor/bin' >> /root/.bash_profile

为了使它仅运行一次,请添加以下文件:

.ebextensions/99_finalize_setup.config:

commands:
  99_write_post_provisioning_complete_file:
    command: touch /opt/elasticbeanstalk/.post-provisioning-complete

每次部署都会将此添加到 .bash_profile 的 PATH 中。有没有办法在每个实例上只添加一次路径。 - Tomotsugu Kaneko
这是答案的关键部分:“每个命令都在自己的 shell 中执行”——理解这一点使我们能够在引用 Anaconda 和 Python 的自定义安装时取得进展,并确保我们在配置脚本中后续命令中使用了正确的 Conda 和 Flask 安装。 - tatlar

0
为了在设置期间使 PATH 可用,您可以执行以下操作。
创建配置文件 .ebextensions/set_path.conf
option_settings:
  "aws:elasticbeanstalk:application:environment":
    "PATH": "/var/www/html/vendor/bin:$PATH"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接