AWS CodeBuild의 로컬 캐시를 작동 시키려고 노력했지만 제 인생에서 가장 기본적인 캐시도 작동하지 않습니다. 나의 궁극적 인 목표는 여기에 설명 된대로 Gradle 아티팩트를 캐시하는 것 입니다.
그러나 그것을 작동시킬 수 없었기 때문에 더 간단한 테스트를 시도했습니다. 여기서 각 빌드를 증가 /root/foo
시키는 파일로 디렉토리를 캐시하려고 시도했습니다 counter.txt
. 서로의 몇 분 내에 후속 빌드를 실행하면 로그에 "2", "3"등이 표시됩니다. 그러나 실제로 심볼릭 링크가 설정되었지만 다음 빌드는 이전 counter.txt
파일을 보지 못하므로 무언가가 매우 깨졌습니다.
누구나 로컬 캐시가 실제로 CodeBuild에서 작동하는지 확인할 수 있습니까? 현재 기능이 손상되었는지 궁금합니다. 아니면 내가해야 할 일을 완전히 오해하고 있습니까?
buildspec.yml :
version: 0.2
phases:
install:
runtime-versions:
java: corretto8
build:
commands:
- pwd
- ls -l /root/
- ls -l /root/foo/
- ./cache-test.sh
- ls -l /root/
- ls -l /root/foo/
cache:
paths:
- '/root/foo/*'
cache-test.sh :
#!/bin/bash
if [ -d "/root/foo" ]; then
C=$(cat /root/foo/count.txt)
C=$((C + 1))
echo "*********************************"
echo "*********************************"
echo "Incrementing counter to $C"
echo $C > /root/foo/count.txt
echo "*********************************"
echo "*********************************"
else
mkdir /root/foo
echo "*********************************"
echo "*********************************"
echo "File not found, starting count at 1"
echo "*********************************"
echo "*********************************"
echo 1 > /root/foo/count.txt
fi
CodeBuild 출력 : (빠른 연속 실행시에도 동일한 출력)
[Container] 2019/11/10 22:35:08 Waiting for agent ping
[Container] 2019/11/10 22:35:10 Waiting for DOWNLOAD_SOURCE
[Container] 2019/11/10 22:35:10 Phase is DOWNLOAD_SOURCE
[Container] 2019/11/10 22:35:10 CODEBUILD_SRC_DIR=/codebuild/output/src905503483/src
[Container] 2019/11/10 22:35:10 YAML location is /codebuild/output/src905503483/src/buildspec.yml
[Container] 2019/11/10 22:35:10 No commands found for phase name: INSTALL
[Container] 2019/11/10 22:35:10 Processing environment variables
[Container] 2019/11/10 22:35:10 Moving to directory /codebuild/output/src905503483/src
[Container] 2019/11/10 22:35:10 MkdirAll: /codebuild/local-cache/custom/de68c9f22ae028d4e4dfb0d11bbb481053d28b1373db0d6a56ebee0416bf13b2/root/foo
[Container] 2019/11/10 22:35:10 Symlinking: /root/foo => /codebuild/local-cache/custom/de68c9f22ae028d4e4dfb0d11bbb481053d28b1373db0d6a56ebee0416bf13b2/root/foo
[Container] 2019/11/10 22:35:10 Registering with agent
[Container] 2019/11/10 22:35:10 Phases found in YAML: 2
[Container] 2019/11/10 22:35:10 BUILD: 6 commands
[Container] 2019/11/10 22:35:10 INSTALL: 0 commands
[Container] 2019/11/10 22:35:10 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2019/11/10 22:35:10 Phase context status code: Message:
[Container] 2019/11/10 22:35:11 Entering phase INSTALL
[Container] 2019/11/10 22:35:11 Running command echo "Installing corretto(OpenJDK) version 8 ..."
Installing corretto(OpenJDK) version 8 ...
[Container] 2019/11/10 22:35:11 Running command export JAVA_HOME="$JAVA_8_HOME"
[Container] 2019/11/10 22:35:11 Running command export JRE_HOME="$JRE_8_HOME"
[Container] 2019/11/10 22:35:11 Running command export JDK_HOME="$JDK_8_HOME"
[Container] 2019/11/10 22:35:11 Running command for tool_path in "$JAVA_8_HOME"/bin/* "$JRE_8_HOME"/bin/*;
do tool=`basename "$tool_path"`;
if [ $tool != 'java-rmi.cgi' ];
then
rm -f /usr/bin/$tool /var/lib/alternatives/$tool \
&& update-alternatives --install /usr/bin/$tool $tool $tool_path 20000;
fi;
done
[Container] 2019/11/10 22:35:11 Phase complete: INSTALL State: SUCCEEDED
[Container] 2019/11/10 22:35:11 Phase context status code: Message:
[Container] 2019/11/10 22:35:11 Entering phase PRE_BUILD
[Container] 2019/11/10 22:35:11 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2019/11/10 22:35:11 Phase context status code: Message:
[Container] 2019/11/10 22:35:11 Entering phase BUILD
[Container] 2019/11/10 22:35:11 Running command pwd
/codebuild/output/src905503483/src
[Container] 2019/11/10 22:35:11 Running command ls -l /root/
total 4
lrwxrwxrwx 1 root root 103 Nov 10 22:35 foo -> /codebuild/local-cache/custom/de68c9f22ae028d4e4dfb0d11bbb481053d28b1373db0d6a56ebee0416bf13b2/root/foo
[Container] 2019/11/10 22:35:11 Running command ls -l /root/foo/
total 0
[Container] 2019/11/10 22:35:11 Running command ./cache-test.sh
cat: /root/foo/count.txt: No such file or directory
*********************************
*********************************
Incrementing counter to 1
*********************************
*********************************
[Container] 2019/11/10 22:35:11 Running command ls -l /root/
total 4
lrwxrwxrwx 1 root root 103 Nov 10 22:35 foo -> /codebuild/local-cache/custom/de68c9f22ae028d4e4dfb0d11bbb481053d28b1373db0d6a56ebee0416bf13b2/root/foo
[Container] 2019/11/10 22:35:11 Running command ls -l /root/foo/
total 4
-rw-r--r-- 1 root root 2 Nov 10 22:35 count.txt
[Container] 2019/11/10 22:35:11 Phase complete: BUILD State: SUCCEEDED
[Container] 2019/11/10 22:35:11 Phase context status code: Message:
[Container] 2019/11/10 22:35:11 Entering phase POST_BUILD
[Container] 2019/11/10 22:35:11 Phase complete: POST_BUILD State: SUCCEEDED
[Container] 2019/11/10 22:35:11 Phase context status code: Message:
CodeBuild 프로젝트 JSON :
{
"projects": [
{
"name": "test-project",
"arn": "arn:aws:codebuild:us-east-2:xxx:project/xxx",
"source": {
"type": "CODEPIPELINE",
"insecureSsl": false
},
"secondarySourceVersions": [],
"artifacts": {
"type": "CODEPIPELINE",
"name": "test-project",
"packaging": "NONE",
"encryptionDisabled": false
},
"secondaryArtifacts": [],
"cache": {
"type": "LOCAL",
"modes": [
"LOCAL_SOURCE_CACHE",
"LOCAL_CUSTOM_CACHE"
]
},
"environment": {
"type": "LINUX_CONTAINER",
"image": "aws/codebuild/amazonlinux2-x86_64-standard:1.0",
"computeType": "BUILD_GENERAL1_SMALL",
"environmentVariables": [],
"privilegedMode": false,
"imagePullCredentialsType": "CODEBUILD"
},
"serviceRole": "arn:aws:iam::xxx:role/service-role/xxx",
"timeoutInMinutes": 60,
"queuedTimeoutInMinutes": 480,
"encryptionKey": "arn:aws:kms:us-east-2:xxx:alias/aws/s3",
"tags": [],
"created": 1573364156.631,
"lastModified": 1573423155.674,
"badge": {
"badgeEnabled": false
},
"logsConfig": {
"cloudWatchLogs": {
"status": "ENABLED",
"groupName": "xxx",
"streamName": "xxx"
},
"s3Logs": {
"status": "DISABLED",
"encryptionDisabled": false
}
}
}
],
"projectsNotFound": []
}