如何在 Elastic Beanstalk 中收集和安装 Bower 托管包图像和字体

How to collect and install bower managed package images and fonts in Elastic Beanstalk

所以,我有一个 Flask 应用程序(基于 https://github.com/sloria/cookiecutter-flask 上的优秀入门应用程序),我正在尝试设置它以部署到弹性 beanstalk。该应用程序使用 bower 包管理器安装 javascript 库和依赖项。

问题:我已将我的容器设置为正确安装 npmbower(使用 https://gist.github.com/growingdever/8eb2ae8e5793b9c1cd09) and the associated .css and .js assets are all available to my application (using Flask-Assets 中的示例),但是相关的图像和字体文件仍在它们的包目录中。

我建议的解决方案: 我需要将它们全部收集起来并移动到 app/static/imagesapp/static/fonts 以便软件包找到它们。有人解决过这个问题吗?

所以简单的解决方案是最好的。使用符号链接将文件放在正确的位置是可行的。

另一种方法是 运行宁 container_commandsbower 包中复制文件。在下面的代码片段中,您可以将单词 app 替换为您应用的 directory/name。我已经告诉 bower 将软件包安装到 app/static/libs

container_commands:
    04_project_bower_install:
        command: 'bower --allow-root install'
        leader-only: 'false'
    05_move_fonts:
        command: 'mkdir -p app/static/fonts;
            export DIRS=`find app/static/libs -name fonts -type d -print `;
            export FILES=`find $DIRS \( -name \*.ttf -o -name \*.woff -o -name \*.woff2 -o -name \*.eot -o -name \*.svg \) -print`;
            echo "copying fonts $FILES";
            cp -fu $FILES app/static/fonts'
        leader-only: 'false'
    06_move_images:
        command: 'mkdir -p app/static/images;
            export DIRS=`find app/static/libs -name images -type d -print `;
            export FILES=`find $DIRS \( -name "*.jpg" -or -name "*.png" -or -name "*.gif" -or -name "*.svg" \) -print -maxdepth 1 -type f`;
            echo "copying image $FILES";
            cp -fu $FILES app/static/images'
        leader-only: 'false'

可以说,编写一个小的 asset_setup.sh 和 运行 可能更容易,而不是将复制命令嵌入到 .ebextensions 配置文件中。