-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildspec.yml
46 lines (42 loc) · 1.73 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
38
39
40
41
42
43
44
45
46
version: 0.2
phases:
install:
commands:
- echo "Full environment:"
- printenv
pre_build:
commands:
- echo "Logging into Amazon ECR"
- $(aws ecr get-login --no-include-email --region $AWS_REGION)
build:
commands:
#
# create docker image and push to ECR
#
- echo Build started on `date`
- echo Building the docker image
- docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest || true
- docker build -t $ECR_REPOSITORY:latest --cache-from $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest .
- docker tag $ECR_REPOSITORY:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest
#
# download packer and jq
#
- echo Creating AMI
- curl -qL -o packer.zip https://releases.hashicorp.com/packer/1.2.1/packer_1.2.1_linux_amd64.zip
- unzip packer.zip
- curl -qL -o jq https://stedolan.github.io/jq/download/linux64/jq
- chmod +x ./jq
#
# setup AWS creds for packer
#
- curl -qL -o aws_credentials.json http://169.254.170.2/$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI > aws_credentials.json
- aws configure set region $AWS_REGION
- aws configure set aws_access_key_id `./jq -r '.AccessKeyId' aws_credentials.json`
- aws configure set aws_secret_access_key `./jq -r '.SecretAccessKey' aws_credentials.json`
- aws configure set aws_session_token `./jq -r '.Token' aws_credentials.json`
#
# run packer to create AMI
#
- ./packer build -color=false ops/packer.json
- echo Build completed on `date`