-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
79 lines (73 loc) · 3.71 KB
/
.travis.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
dist: focal
language: ruby
services:
- docker
branches:
only:
- qa
- production
jobs:
include:
- stage: docker build
if: (branch = qa or branch = production)
before_install:
- if [[ $TRAVIS_BRANCH == "qa" ]];
then
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID_QA};
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY_QA};
export ENV="qa";
fi
- if [[ "$TRAVIS_BRANCH" == "production" ]];
then
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID_PRODUCTION};
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY_PRODUCTION};
export ENV="production";
fi
env:
- ECR_URL=946183545209.dkr.ecr.us-east-1.amazonaws.com/my-library-nyc-app
- AWS_DEFAULT_REGION=us-east-1
- AWS_REGION=us-east-1
install:
- pip install --user awscli
- export LOCAL_TAG_NAME="${ENV}-latest"
script:
- eval $(aws ecr get-login --no-include-email --region us-east-1)
- DOCKER_BUILDKIT=1 docker build -t "$LOCAL_TAG_NAME" --secret id=AWS_ACCESS_KEY_ID --secret id=AWS_SECRET_ACCESS_KEY --build-arg RAILS_ENV="${ENV}" .
- docker tag "$LOCAL_TAG_NAME" "$ECR_URL:$LOCAL_TAG_NAME"
# Re-tag last latest image just in case
- |
MANIFEST=$(aws ecr batch-get-image --repository-name my-library-nyc-app --image-ids imageTag="$ENV-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest')
aws ecr batch-delete-image --repository-name my-library-nyc-app --image-ids imageTag="$ENV-previous" || true
aws ecr put-image --repository-name my-library-nyc-app --image-tag "$ENV-previous" --image-manifest "$MANIFEST"
- docker push "$ECR_URL:$LOCAL_TAG_NAME"
- stage: deploy qa
if: branch IN (qa) AND type != pull_request
env:
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID_QA
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY_QA
- AWS_DEFAULT_REGION=us-east-1
- AWS_REGION=us-east-1
- CLUSTER_NAME=mylibrarynycapp-qa
- DELAYED_JOB_NAME=mylibrarynycapp-qa-delayed-job
install:
- pip install --user awscli
script:
- aws ecs update-service --cluster $CLUSTER_NAME --service $CLUSTER_NAME --force-new-deployment
- aws ecs update-service --cluster $CLUSTER_NAME --service $DELAYED_JOB_NAME --force-new-deployment
- stage: deploy production
if: branch IN (production) AND type != pull_request
env:
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY_PRODUCTION
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID_PRODUCTION
- AWS_DEFAULT_REGION=us-east-1
- AWS_REGION=us-east-1
- CLUSTER_NAME=mylibrarynycapp-production
- DELAYED_JOB_NAME=mylibrarynycapp-production-delayed-job
install:
- pip install --user awscli
script:
- aws ecs update-service --cluster $CLUSTER_NAME --service $CLUSTER_NAME --force-new-deployment
- aws ecs update-service --cluster $CLUSTER_NAME --service $DELAYED_JOB_NAME --force-new-deployment
env:
global:
- secure: gLvQY4s1wSXf5hb51e3BH9dlAJBcG55IR4AUlhtIpiQPf/jj4N9oS5tZbmpQnDeT/IJAceL+4sQcL13LRCCArCxlEHow1TdaYFVVix1ABbMH3ge6ZZrQ/ckVaWMv3AIJej8IF0c4skO90fFBz32KAdC2wUmB3/p38WwMHc72KyQa8LwwfhKRx5i14IRF4/IgW7wlZV6zlxJTXyVR1wXB3ghI+8YcuuKdT8PVMwxsBZ6qQjhthg0ez3F0X/Ccd2xqw4X5HfohDpl0HmDeoqJrJt58hGq7p6qx++gHGHn2ByoIeqRNYsTD07MbczQjvvyHHdKNhu2Qv4cwEw6Uhgmx4m/8YbdimFjVB83tLgAfswLEvMtsAOz0gZ7OiED2gvpzfIHy6z5lgzGJ1KmJH9RodcHuP0gV+txhTBfCbn3anBQoF4gYxXxloYI3Aiptl5EU3HSeduxs2TLhk0Vs6Mmzw4thMyyyBRDPdPl8AJR/vcJB7nw1ZTBfxFU4ShvcanqgZsrUh6BsvcbPRJOBmj8Xc0vJwRn7VpvUTvDe3gBNgN06uxyuLMFRdt5u7Ed1DFCRLLBKX1nID04+51HAJtmS4oT5WYtxZzR0n9rlr0bT4sxHHtEdXN8V09d+2OZHQERHh/ekBdJj0N1BChGm4DOW4GDw3p/Tx7gymiB0vxEHrGU=