-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
178 lines (161 loc) · 6.9 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
variables:
REACT_APP_BUY_LMR_URL: $BUY_LMR_URL
REACT_APP_CHAIN_ID: $CHAIN_ID
REACT_APP_CLONE_FACTORY: $CLONE_FACTORY_ADDRESS
REACT_APP_ETHERSCAN_URL: $ETHERSCAN_URL
REACT_APP_GITBOOK_URL: $GITBOOK_URL
REACT_APP_INDEXER_URL: $INDEXER_URL
REACT_APP_LUMERIN_TOKEN_ADDRESS: $LUMERIN_TOKEN_ADDRESS
REACT_APP_READ_ONLY_ETH_NODE_URL: $MARKETPLACE_ETH_NODE
REACT_APP_TITAN_LIGHTNING_DASHBOARD: $TITAN_LIGHTNING_DASHBOARD
REACT_APP_TITAN_LIGHTNING_POOL: $TITAN_LIGHTNING_POOL
REACT_APP_VALIDATOR_PUBLIC_KEY: $VALIDATOR_PUBLICKEY
REACT_APP_VALIDATOR_URL: $VALIDATOR_URL
REACT_APP_VALIDATOR_REGISTRY_ADDRESS: $VALIDATOR_REGISTRY_ADDRESS
stages:
- develop
- review
- deploy
.update_lumerin_json: &update_lumerin_json |
echo "**************************"
echo "*** Updating lumerin.json"
echo "**************************"
sed -i -e "s/LUMERIN_TOKEN_ADDRESS_VAR/${REACT_APP_LUMERIN_TOKEN_ADDRESS}/g" src/contracts/Lumerin.json
.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_NAME:$IMAGE_TAG
.build_image: &build_image |
echo "*****************************"
echo "Building & Pushing image..."
echo "*****************************"
docker build \
--build-arg REACT_APP_BUY_LMR_URL=$REACT_APP_BUY_LMR_URL \
--build-arg REACT_APP_CHAIN_ID=$REACT_APP_CHAIN_ID \
--build-arg REACT_APP_CLONE_FACTORY=$REACT_APP_CLONE_FACTORY \
--build-arg REACT_APP_ETHERSCAN_URL=$REACT_APP_ETHERSCAN_URL \
--build-arg REACT_APP_GITBOOK_URL=$REACT_APP_GITBOOK_URL \
--build-arg REACT_APP_INDEXER_URL=$REACT_APP_INDEXER_URL \
--build-arg REACT_APP_LUMERIN_TOKEN_ADDRESS=$REACT_APP_LUMERIN_TOKEN_ADDRESS \
--build-arg REACT_APP_READ_ONLY_ETH_NODE_URL=$REACT_APP_READ_ONLY_ETH_NODE_URL \
--build-arg REACT_APP_TITAN_LIGHTNING_DASHBOARD=$REACT_APP_TITAN_LIGHTNING_DASHBOARD \
--build-arg REACT_APP_TITAN_LIGHTNING_POOL=$REACT_APP_TITAN_LIGHTNING_POOL \
--build-arg REACT_APP_VALIDATOR_PUBLIC_KEY=$REACT_APP_VALIDATOR_PUBLIC_KEY \
--build-arg REACT_APP_VALIDATOR_URL=$REACT_APP_VALIDATOR_URL \
--build-arg REACT_APP_VALIDATOR_REGISTRY_ADDRESS=$REACT_APP_VALIDATOR_REGISTRY_ADDRESS \
-t $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_NAME:$IMAGE_TAG --no-cache .
echo "**************************"
echo "*** Tag Image with $TGT_ENV-latest"
echo "**************************"
docker tag $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_NAME:$IMAGE_TAG $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_NAME:$TGT_ENV-latest
echo "**************************"
echo "*** Push Images"
echo "**************************"
docker push $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_NAME:$IMAGE_TAG
docker push $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_NAME:$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_NAME > 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_NAME:$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_NAME --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_NAME-$TGT_ENV-$CI_AWS_ECS_CLUSTER_REGION"
echo "*** - Service: svc-$CI_AWS_ECS_NAME-$TGT_ENV-$CI_AWS_ECS_CLUSTER_REGION"
echo "*** - Task: tsk-$CI_AWS_ECS_NAME:$REVISION"
echo "*** - Image: $CI_AWS_TitanIO_NET_ECR/$CI_AWS_ECS_NAME:$IMAGE_TAG"
echo "****************************************************"
echo "****************************************************"
aws ecs update-service --region $AWS_DEFAULT_REGION --cluster ecs-$CI_AWS_ECS_NAME-$TGT_ENV-$CI_AWS_ECS_CLUSTER_REGION --service svc-$CI_AWS_ECS_NAME-$TGT_ENV-$CI_AWS_ECS_CLUSTER_REGION --task-definition tsk-$CI_AWS_ECS_NAME:$REVISION
bedrock-02-dev:
environment: dev
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:
- *update_lumerin_json
- *ecr_login_script
- *create_image_tag
- *build_image
- *update_raw_task_definition
- *deploy_new_task_definition
- echo "$TGT_ENV Updated"
titanio-03-stg:
environment: stg
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:
- *update_lumerin_json
- *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: lmn
stage: deploy
only:
- main
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:
- *update_lumerin_json
- *ecr_login_script
- *create_image_tag
- *build_image
- *update_raw_task_definition
- *deploy_new_task_definition
- echo "$TGT_ENV Updated"