在我的项目中,为了加快构建速度,我试图使用以下方法来缓存composer缓存文件夹。buildspec.yml
:
version: 0.2
env:
variables:
COMPOSER_CACHE_DIR: "${CODEBUILD_SRC_DIR}/.cache/composer"
phases:
install:
commands:
- apk add --update git
- echo ${COMPOSER_CACHE_DIR}
- mkdir -p ${COMPOSER_CACHE_DIR}
- ls -l ${COMPOSER_CACHE_DIR}
build:
commands:
- ls -l ${COMPOSER_CACHE_DIR}
- ls -l vendor
- composer install --no-dev --no-progress --no-suggest --optimize-autoloader
- ls -l ${COMPOSER_CACHE_DIR}
artifacts:
files:
- app/**/*
- bootstrap/**/*
- config/**/*
- database/**/*
- machine/**/*
- public/**/*
- resources/**/*
- routes/**/*
- scripts/**/*
- vendor/**/*
- .env
- appspec.yml
- artisan
- composer.json
cache:
paths:
- ${COMPOSER_CACHE_DIR}
但一旦构建运行一次,我 ls -l ${COMPOSER_CACHE_DIR}
执行时,会显示一个空的文件夹。
[Container] 2020/04/23 07:28:43 Running command ls -l ${COMPOSER_CACHE_DIR}
total 0
但是一旦 composer install
然后再执行 COMPOSER_CACHE_DIR
正在被填充。
[Container] 2020/04/23 07:29:36 Running command ls -l ${COMPOSER_CACHE_DIR}
total 8
drwxr-xr-x 41 root root 4096 Apr 23 07:29 files
drwxr-xr-x 3 root root 4096 Apr 23 07:28 repo
所以我想知道为什么代码制作无法填充到... ... COMPOSER_CACHE_DIR
文件夹上 install
阶段?我检查了S3和文件被放置的预期。我也没有在缓存上放置过期,而且我使用我自己的docker镜像而不是amazon提供的镜像。
这与你使用的变量替换格式或缓存路径格式有关。请看下面的工作示例。在第一次运行时,缓存目录中什么都没有,在第二次运行时,文件将被填充。
version: 0.2
env:
variables:
COMPOSER_CACHE_DIR: .cache/composer
phases:
install:
commands:
- ls -al .
- ls -l .cache/composer
- echo .cache/composer
- mkdir -p .cache/composer
- ls -l .cache/composer
build:
commands:
- ls -l .cache/composer
- touch .cache/composer/a.txt
- touch .cache/composer/b.txt
- pwd
- ls -al
cache:
paths:
- .cache/composer/**/*