-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuildspec.yml
32 lines (30 loc) · 1.24 KB
/
buildspec.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
version: 0.2
env:
secrets-manager:
LOCAL_DOCKER_HUB_ACCESS_TOKEN: "DockerHubAccessToken2:DOCKER_HUB_ACCESS_TOKEN"
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- echo Logging Docker Hub...
- docker login --username $DOCKER_USERNAME -p $LOCAL_DOCKER_HUB_ACCESS_TOKEN
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $IMAGE_NAME:latest .
- docker tag $IMAGE_NAME:latest $ECR_REPO_URL:latest
- docker tag $IMAGE_NAME:latest $ECR_REPO_URL:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $ECR_REPO_URL:latest
- docker push $ECR_REPO_URL:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"%s","imageUri":"%s"}]' $CONTAINER_NAME $ECR_REPO_URL:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json