-
Notifications
You must be signed in to change notification settings - Fork 4
/
cd-buildspec.yml
45 lines (40 loc) · 1.34 KB
/
cd-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
version: 0.2
env:
shell: bash
variables:
ECR_REPOSITORY: cloud-nestjs
IMAGE_TAG: latest
REGION: us-east-1
phases:
install:
runtime-versions:
nodejs: 18.x
commands:
- echo Done installing nodejs version 18 in environment
pre_build:
commands:
- echo Logging in to Amazon ECR...
- ECR_REGISTRY=$(aws ecr describe-repositories --repository-names $ECR_REPOSITORY --region $REGION --query repositories[0].repositoryUri --output text)
- aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $ECR_REGISTRY
- echo Login to ECR successful...
- echo Building and tagging docker image...
- docker build -t $ECR_REGISTRY:$IMAGE_TAG .
- echo Successfully built and tagged docker image...
build:
commands:
- docker run -t -i -p 3000:3000 -d $ECR_REGISTRY:$IMAGE_TAG
- echo "Executing port test in 1 minute(s)..."
- sleep 60
- |
if curl --output /dev/null --silent --head --fail http://localhost:3000/health; then
echo "Application is healthy."
exit 0
else
echo "Application is not healthy."
exit 1
fi
post_build:
commands:
- echo Pushing docker image to registry...
- docker push $ECR_REGISTRY:$IMAGE_TAG
- echo "image=$ECR_REGISTRY:$IMAGE_TAG"