-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yaml
47 lines (44 loc) · 1.72 KB
/
buildspec.yaml
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Don't change this version, this version is buildspec.yml file's version
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- docker login -u $dockerhub_username -p $dockerhub_password
- echo $ECS_SERVICE_NAME
- echo $ECR_REPO_URI
- REPOSITORY_URI=$ECR_REPO_URI
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- echo $CODEBUILD_RESOLVED_SOURCE_VERSION
- IMAGE_TAG=${COMMIT_HASH:latest}
build:
commands:
- echo Build started on `date`
- echo $PROJECT_NAME
- echo $BRANCH_NAME
- |
if echo "$BRANCH_NAME" | grep -q -e "master" -e "main"; then
echo "On dev branch, performing backup..."
zip_file="/codebuild/output/$PROJECT_NAME.zip"
zip -r $zip_file /codebuild/output
aws s3 cp $zip_file s3://biztree-git-backup-bucket/$PROJECT_NAME/$BRANCH_NAME/
echo "s3 backup complete"
else
echo "Not on dev branch, skipping backup."
fi
- 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...
- aws ecr get-login-password | docker login --username AWS --password-stdin $REPOSITORY_URI
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"%s","imageUri":"%s"}]', $ECS_SERVICE_NAME $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
- cat imagedefinitions.json
artifacts:
files: imagedefinitions.json