-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yml
57 lines (56 loc) · 2.09 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
47
48
49
50
51
52
53
54
55
56
57
version: 0.2
env:
variables:
AWS_REGION: "us-east-1"
REACT_APP_USERS_SERVICE_URL: ${ALB_DNS}
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- |
if expr "$CODEBUILD_WEBHOOK_TRIGGER" == "branch/main" >/dev/null && expr "$CODEBUILD_WEBHOOK_HEAD_REF" == "refs/heads/main" >/dev/null; then
DOCKER_TAG=prod
else
DOCKER_TAG=${CODEBUILD_RESOLVED_SOURCE_VERSION}
fi
- echo "Docker tag:" $DOCKER_TAG
- aws s3 cp s3://docker-token/.docker.key .docker.key
- docker login -u $DOCKER_USERNAME --password-stdin < .docker.key
- rm .docker.key
- docker pull $DOCKER_USERNAME/micro-react-nginx-users:$DOCKER_TAG || true
- docker pull $DOCKER_USERNAME/micro-react-nginx-client:builder || true
- docker pull $DOCKER_USERNAME/micro-react-nginx-client:$DOCKER_TAG || true
build:
commands:
- echo building images
- docker-compose up -d --build
- >
docker build \
--cache-from $DOCKER_USERNAME/micro-react-nginx-users:$DOCKER_TAG \
-f services/node-server-users/Dockerfile.prod \
-t $DOCKER_USERNAME/micro-react-nginx-users:$DOCKER_TAG \
./services/node-server-users
- >
docker build \
--target builder \
--cache-from $DOCKER_USERNAME/micro-react-nginx-client:builder \
-f client/Dockerfile.prod \
-t $DOCKER_USERNAME/micro-react-nginx-client:builder \
--build-arg NODE_ENV=production \
./client
- >
docker build \
--cache-from $DOCKER_USERNAME/micro-react-nginx-client:$DOCKER_TAG \
-f client/Dockerfile.prod \
-t $DOCKER_USERNAME/micro-react-nginx-client:$DOCKER_TAG \
./client
post_build:
commands:
- echo pushing prod images to ecr..
- docker push $DOCKER_USERNAME/micro-react-nginx-users:$DOCKER_TAG
- docker push $DOCKER_USERNAME/micro-react-nginx-client:builder
- docker push $DOCKER_USERNAME/micro-react-nginx-client:$DOCKER_TAG
- chmod +x ./deploy.sh
- bash deploy.sh