codepipelineを使ってcodebuildを使ってみたい
Q&A
Closed
解決したいこと
gitにpushしてcodebuildを動かしたい。
参考資料
https://zoo200.net/deploy-ecs-with-cicd-codepipeline-codebuild/
参考資料の通りにやっているんですができません。
発生している問題・エラー
[Container] 2025/02/20 08:37:50.223536 Running on CodeBuild On-demand
[Container] 2025/02/20 08:37:50.223554 Waiting for agent ping
[Container] 2025/02/20 08:37:50.425826 Waiting for DOWNLOAD_SOURCE
[Container] 2025/02/20 08:37:52.016935 Phase is DOWNLOAD_SOURCE
[Container] 2025/02/20 08:37:52.056544 CODEBUILD_SRC_DIR=/codebuild/output/src4124269803/src
[Container] 2025/02/20 08:37:52.057387 YAML location is /codebuild/readonly/buildspec.yml
[Container] 2025/02/20 08:37:52.060785 Setting HTTP client timeout to higher timeout for S3 source
[Container] 2025/02/20 08:37:52.060923 Processing environment variables
[Container] 2025/02/20 08:37:52.247625 No runtime version selected in buildspec.
[Container] 2025/02/20 08:37:52.278039 Moving to directory /codebuild/output/src4124269803/src
[Container] 2025/02/20 08:37:52.278168 Cache is not defined in the buildspec
[Container] 2025/02/20 08:37:52.278179 Cache is not defined in the buildspec
[Container] 2025/02/20 08:37:52.320969 Unable to initialize cache download: no paths specified to be cached
[Container] 2025/02/20 08:37:52.404475 Configuring ssm agent with target id: codebuild:1f405fd4-49f4-44ee-a1de-101997d08be6
[Container] 2025/02/20 08:37:52.458763 Successfully updated ssm agent configuration
[Container] 2025/02/20 08:37:52.459147 Registering with agent
[Container] 2025/02/20 08:37:52.498976 Phases found in YAML: 3
[Container] 2025/02/20 08:37:52.498998 PRE_BUILD: 1 commands
[Container] 2025/02/20 08:37:52.499004 BUILD: 2 commands
[Container] 2025/02/20 08:37:52.499007 POST_BUILD: 2 commands
[Container] 2025/02/20 08:37:52.499285 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2025/02/20 08:37:52.499299 Phase context status code: Message:
[Container] 2025/02/20 08:37:52.569212 Entering phase INSTALL
[Container] 2025/02/20 08:37:52.608281 Phase complete: INSTALL State: SUCCEEDED
[Container] 2025/02/20 08:37:52.608299 Phase context status code: Message:
[Container] 2025/02/20 08:37:52.643097 Entering phase PRE_BUILD
[Container] 2025/02/20 08:37:52.680103 Running command aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin アカウント名.dkr.ecr.ap-northeast-1.amazonaws.com
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credential-stores
Login Succeeded
[Container] 2025/02/20 08:38:04.024246 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2025/02/20 08:38:04.024263 Phase context status code: Message:
[Container] 2025/02/20 08:38:04.060281 Entering phase BUILD
[Container] 2025/02/20 08:38:04.061709 Running command docker build -t $ImageName -f ./Dockerfile .
#0 building with "default" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2B done
#1 DONE 0.0s
ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory
[Container] 2025/02/20 08:38:04.375154 Command did not exit successfully docker build -t $ImageName -f ./Dockerfile . exit status 1
[Container] 2025/02/20 08:38:04.380714 Phase complete: BUILD State: FAILED
[Container] 2025/02/20 08:38:04.380734 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -t $ImageName -f ./Dockerfile .. Reason: exit status 1
[Container] 2025/02/20 08:38:04.420422 Entering phase POST_BUILD
[Container] 2025/02/20 08:38:04.421670 Running command docker tag $ImageName:latest アカウント名.dkr.ecr.ap-northeast-1.amazonaws.com/$ImageName:latest
Error response from daemon: No such image: simple-docker-service-0a2fef3e6675:latest
[Container] 2025/02/20 08:38:04.438880 Command did not exit successfully docker tag $ImageName:latest 684591648795.dkr.ecr.ap-northeast-1.amazonaws.com/$ImageName:latest exit status 1
[Container] 2025/02/20 08:38:04.443905 Phase complete: POST_BUILD State: FAILED
[Container] 2025/02/20 08:38:04.443922 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker tag $ImageName:latest アカウント名.dkr.ecr.ap-northeast-1.amazonaws.com/$ImageName:latest. Reason: exit status 1
[Container] 2025/02/20 08:38:04.498945 Set report auto-discover timeout to 5 seconds
[Container] 2025/02/20 08:38:04.498993 Expanding base directory path: .
[Container] 2025/02/20 08:38:04.502334 Assembling file list
[Container] 2025/02/20 08:38:04.502350 Expanding .
[Container] 2025/02/20 08:38:04.505651 Expanding file paths for base directory .
[Container] 2025/02/20 08:38:04.505667 Assembling file list
[Container] 2025/02/20 08:38:04.505671 Expanding **/*
[Container] 2025/02/20 08:38:04.510085 No matching auto-discover report paths found
[Container] 2025/02/20 08:38:04.510138 Report auto-discover file discovery took 0.011192 seconds
[Container] 2025/02/20 08:38:04.510161 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
[Container] 2025/02/20 08:38:04.510168 Phase context status code: Message:
フォルダの中身
version: 0.2
phases:
pre_build:
commands:
- aws --version
- AWS_ACCOUNT_ID=xxxxxxx
- ECR_URI=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com
- REPOSITORY_URI=${ECR_URI}/demo-repo:latest
- CONTAINER_NAME=demo-repo
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ECR_URI
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"%s","imageUri":"%s"}]' $CONTAINER_NAME $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json
Dockerfile
FROM nginx
COPY index.html /usr/share/nginx/html
Hello CI/CD!
自分で試したこと
codepipelineを作成してみました。