-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yml
37 lines (36 loc) · 1.53 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
33
34
35
36
37
version: 0.2
# John Massey, ASCR Federal
# 7/31/2019
# REQUIREMENTS
# CodeBuild ENV Vars
# AWS_DEFAULT_REGION (us-east-1)
# AWS_ACCOUNT_ID
# IMAGE_REPO_NAME (ECR Repo Name)
# IMAGE_TAG (Docker Image Tag)
# BASE_IMAGE_NAME (Default Name of docker image post build step)
# ENVIRONMENT (based on REP or SCEN + DEV, TEST, PROD)
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- echo $AWS_DEFAULT_REGION
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
install:
runtime-versions:
docker: 18
build:
commands:
- echo Build started on `date`
- echo Building the Dockerfile
- docker build -t $IMAGE_REPO_NAME:latest .
- docker tag $BASE_IMAGE_NAME:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:latest
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image to AWS ECR...
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:latest
- MY_MANIFEST=$(aws ecr batch-get-image --repository-name $IMAGE_REPO_NAME --image-ids imageTag=latest --region $AWS_DEFAULT_REGION --query images[].imageManifest --output text)
- IMAGE_TAG=$IMAGE_TAG"_"$JENKINS_ID
- IMAGE_TAG=$(echo "$IMAGE_TAG" | sed 's#/#\_#g')
- echo $IMAGE_TAG
- aws ecr put-image --repository-name $IMAGE_REPO_NAME --image-tag $IMAGE_TAG --image-manifest "$MY_MANIFEST" --region $AWS_DEFAULT_REGION