-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
155 lines (140 loc) · 5.46 KB
/
.gitlab-ci.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Please keep variables in alphabetical order
# variables:
stages:
- develop
- review
- deploy
.ecr_login_script: &ecr_login_script |
echo "**************************"
echo "*** ECR Login to Shared Titanio-NET Repo in USE-1"
echo "**************************"
docker system prune -af
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $CI_AWS_TitanIO_NET_ECR
.create_image_tag: &create_image_tag |
echo "**************************"
echo "*** Tag Image "
echo "**************************"
IMAGE_TAG="$(echo $CI_COMMIT_SHA | head -c 8)-$TGT_ENV"
echo $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_SVC:$IMAGE_TAG
.build_image: &build_image |
echo "*****************************"
echo "Building & Pushing image..."
echo "*****************************"
docker build \
--build-arg ADMIN_API_KEY=$ADMIN_API_KEY \
--build-arg CLONE_FACTORY_ADDRESS=$CLONE_FACTORY_ADDRESS \
--build-arg ETH_NODE_URL=$INDEXER_ETH_NODE \
--build-arg FASTIFY_PLUGIN_TIMEOUT=60000 \
--build-arg PORT=80 \
-t $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_SVC:$IMAGE_TAG --no-cache .
echo "**************************"
echo "*** Tag Image with $TGT_ENV-latest"
echo "**************************"
docker tag $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_SVC:$IMAGE_TAG $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_SVC:$TGT_ENV-latest
echo "**************************"
echo "*** Push Images"
echo "**************************"
docker push $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_SVC:$IMAGE_TAG
docker push $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_SVC:$TGT_ENV-latest
.update_raw_task_definition: &update_raw_task_definition |
echo "**************************"
aws ecs describe-task-definition --region $AWS_DEFAULT_REGION --task-definition tsk-$CI_AWS_ECS_SVC > output.json
echo "**************************"
echo "*** Original Task Definition"
echo "**************************"
jq . output.json
# Update the Image
jq '.taskDefinition.containerDefinitions[].image = "'$CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_SVC:$TGT_ENV-latest'"' output.json > updated.json
# Extract JUST Task Definition from the output.json file
jq '.taskDefinition' updated.json > extracted.json
# Remove sections that are not needed
jq 'del(.taskDefinitionArn, .revision, .status, .requiresAttributes, .compatibilities, .registeredBy, .registeredAt)' extracted.json > input.json
sed -i 's/'$CI_AWS_ACCOUNT_SBX'/'$TGT_ACCOUNT'/g' input.json
echo "**************************"
echo "*** New Task Definition"
echo "**************************"
jq . input.json
.deploy_new_task_definition: &deploy_new_task_definition |
aws ecs register-task-definition --region $AWS_DEFAULT_REGION --cli-input-json file://input.json
REVISION=$(aws ecs describe-task-definition --task-definition tsk-$CI_AWS_ECS_SVC --region $AWS_DEFAULT_REGION | egrep "revision" | tr "/" " " | awk '{print $2}' | sed 's/"$//' | cut -d "," -f 1)
echo "****************************************************"
echo "****************************************************"
echo "*** Update Task: "
echo "*** - AWS Account: Titanio-$TGT_ENV"
echo "*** - Cluster: ecs-$CI_AWS_ECS_CLUSTER-$TGT_ENV-$CI_AWS_ECS_CLUSTER_REGION"
echo "*** - Service: svc-$CI_AWS_ECS_SVC-$TGT_ENV-$CI_AWS_ECS_CLUSTER_REGION"
echo "*** - Task: tsk-$CI_AWS_ECS_SVC:$REVISION"
echo "*** - Image: $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_SVC:$IMAGE_TAG"
echo "****************************************************"
echo "****************************************************"
aws ecs update-service --region $AWS_DEFAULT_REGION --cluster ecs-$CI_AWS_ECS_CLUSTER-$TGT_ENV-$CI_AWS_ECS_CLUSTER_REGION --service svc-$CI_AWS_ECS_SVC-$TGT_ENV-$CI_AWS_ECS_CLUSTER_REGION --task-definition tsk-$CI_AWS_ECS_SVC:$REVISION
bedrock-02-dev:
environment:
name: dev
url: https://indexer.dev.lumerin.io/api/healthcheck
stage: develop
only:
- dev
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
tags:
- devops
- bedrock
- titanio-dev
- shell
variables:
TGT_ACCOUNT: $CI_AWS_ACCOUNT_DEV
TGT_ENV: dev
script:
- *ecr_login_script
- *create_image_tag
- *build_image
- *update_raw_task_definition
- *deploy_new_task_definition
- echo "$TGT_ENV Updated"
titanio-03-stg:
environment:
name: stg
url: https://indexer.stg.lumerin.io/api/healthcheck
stage: review
only:
- stg
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
tags:
- devops
- bedrock
- titanio-stg
- shell
variables:
TGT_ACCOUNT: $CI_AWS_ACCOUNT_STG
TGT_ENV: stg
script:
- *ecr_login_script
- *create_image_tag
- *build_image
- *update_raw_task_definition
- *deploy_new_task_definition
- echo "$TGT_ENV Updated"
titanio-04-lmn-PROD:
environment:
name: lmn
url: https://indexer.lumerin.io/api/healthcheck
stage: deploy
only:
- main
when: manual
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
tags:
- devops
- bedrock
- titanio-lmn
- shell
variables:
TGT_ACCOUNT: $CI_AWS_ACCOUNT_LMN
TGT_ENV: lmn
script:
- *ecr_login_script
- *create_image_tag
- *build_image
- *update_raw_task_definition
- *deploy_new_task_definition
- echo "$TGT_ENV Updated"