AWS Amplify控制台中的Gatsby .cache文件夹 [英] Gatsby .cache folder in AWS Amplify Console

查看:103
本文介绍了AWS Amplify控制台中的Gatsby .cache文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我构建了一个Gatsby项目,并使用Amplify控制台并连接我的Bitbucket存储库将其部署在AWS Amplify上.该项目规模不断扩大,现在必须用大量图像构建37页.我正在使用"gatsby-source-custom-api"进行数据提取,该数据提取使用"gatsby-image"进行图像处理.它还提供了一种方法来指定图像是否已更改,因此,如果未更改,它会使用.cache使"gatsby-image"已对其进行优化. 现在,我面临的问题是,AWS Amplify中的两个构建之间的.cache文件夹不可用.它可以存储在某个地方还是有另一种使用方式?现在只需要花费13分钟的时间就可以完成构建,而主要的工作就是图像处理.

Recently I built a Gatsby project and deployed it on AWS Amplify using the Amplify Console and connecting my Bitbucket repo. The project grew and now it has to build 37 pages with a ton of images. I am using ‘gatsby-source-custom-api’ for the data extraction which offers image processing using ‘gatsby-image’. It also offers a way to specify if the images was changed therefore if not changed it uses the .cache to get it already optimized by the ‘gatsby-image’. Now the issue I face is that the .cache folder is not available between builds in AWS Amplify. Can it be stored somewhere or is there another way to use it? Now it takes a good 13 minutes to build and the major part is from image processing.

推荐答案

尝试以下操作:

buildspec.yml

version: 0.2

phases:
  pre_build:
    commands:
      - mkdir -p /build-directory
      - cp -a ${CODEBUILD_SRC_DIR}/. /build-directory
      - cd /build-directory
      - yarn
  build:
    commands:
      - cd /build-directory
      - gatsby build
  post_build:
    commands:
      - cd /build-directory
      - cp -a /build-directory/. ${CODEBUILD_SRC_DIR}
cache:
  paths:
    - 'node_modules/**/*'
    - 'public/**/*'
    - '.cache/**/*'

在撰写本文时,还没有一个整洁的解决方案.缓存整个.cache目录最终将引发以下错误:

As of this writing, there is not a tidy solution. Caching the entire .cache directory will ultimately throw the following error:

无法处理图像/codebuild/output/src***/src/project/.cache/gatsby-source-filesystem//.png输入文件为失踪

Failed to process image /codebuild/output/src***/src/project/.cache/gatsby-source-filesystem//.png Input file is missing

正如您在评论中提到的,Gatsby假定.cache的绝对路径在两次构建之间是一致的.这与CodeBuild不太兼容,因为每个构建版本都会更改构建目录.因此,Gatsby无法找到缓存的文件并引发错误.

As you mentioned in the comments, Gatsby assumes that the absolute path to .cache is consistent between builds. This is not very compatible with CodeBuild since the build directory changes for each build. Because of this, Gatsby isn't able to locate the cached files and throws an error.

因此,创建一致的路径并将工件带到那里将解决此问题.构建完成后,请确保将新工件放入CODEBUILD_SRC_DIR,以便下次可以对其进行缓存!

For this reason, creating a consistent path and bringing the artifacts there will solve the issue. When the build is done, be sure to bring the new artifacts to the CODEBUILD_SRC_DIR so that they can be cached for next time!

这篇关于AWS Amplify控制台中的Gatsby .cache文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆