version: 0.2
env:
variables:
AWS_DEFAULT_REGION: ap-northeast-1
ACCOUNT_ID: "123456789012" # 改成你的
REPOSITORY_NAME: "grand-stg-sm-batch" # 改成你的
exported-variables: [IMAGE_TAG, REPOSITORY_URI]
phases:
install:
runtime-versions:
docker: 20
pre_build:
commands:
- set -euo pipefail
- REPOSITORY_URI="${ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${REPOSITORY_NAME}"
- IMAGE_TAG="$(echo ${CODEBUILD_RESOLVED_SOURCE_VERSION:-manual} | cut -c1-7)-${CODEBUILD_BUILD_NUMBER}"
- echo "Repo: $REPOSITORY_URI"
- echo "Tag : $IMAGE_TAG"
- test -n "$REPOSITORY_URI" || (echo "❌ REPOSITORY_URI empty"; exit 2)
- test -n "$IMAGE_TAG" || (echo "❌ IMAGE_TAG empty"; exit 2)
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $REPOSITORY_URI
- cd "$CODEBUILD_SRC_DIR"
- test -f aws/pipeline/build/Dockerfile || (echo "❌ Dockerfile not found"; ls -R; exit 3)
- docker version || (echo "❌ Docker daemon not available. Enable Privileged."; exit 4)
build:
commands:
- docker build --progress=plain -f aws/pipeline/build/Dockerfile -t "$REPOSITORY_URI:$IMAGE_TAG" .
post_build:
commands:
- docker push "$REPOSITORY_URI:$IMAGE_TAG"
- echo "✅ Pushed: $REPOSITORY_URI:$IMAGE_TAG"
artifacts:
files: []
discard-paths: yes
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme