为什么我无法在 aws codebuild 上检索作曲家缓存文件夹目录?
Why I am unable to retrieve the composer caching folder dir on aws codebuild?
在我的项目中,为了加快构建速度,我尝试使用以下 buildspec.yml
:
来缓存 composer 缓存文件夹
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
所以我想知道为什么代码构建无法在 install
阶段填充 COMPOSER_CACHE_DIR
文件夹?我检查了 S3,文件按预期放置。我的缓存也没有过期,我使用自己的 docker 图片而不是亚马逊提供的图片。
这与您使用的变量替换格式或缓存路径格式有关。检查下面的工作示例。在第一个 运行 中,缓存目录中没有任何内容,在第二个 运行 中,将填充文件:
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/**/*
在我的项目中,为了加快构建速度,我尝试使用以下 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
所以我想知道为什么代码构建无法在 install
阶段填充 COMPOSER_CACHE_DIR
文件夹?我检查了 S3,文件按预期放置。我的缓存也没有过期,我使用自己的 docker 图片而不是亚马逊提供的图片。
这与您使用的变量替换格式或缓存路径格式有关。检查下面的工作示例。在第一个 运行 中,缓存目录中没有任何内容,在第二个 运行 中,将填充文件:
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/**/*