-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
45 lines (36 loc) · 1.61 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
services:
- docker:18-dind
variables:
REPOSITORY_URL: 873931742302.dkr.ecr.us-east-1.amazonaws.com
stages:
- deploy
deploy_prod:
stage: deploy
image: docker:latest
when: manual
rules:
- if: $CI_COMMIT_BRANCH == "main"
variables:
REPOSITORY_IMAGE: prod-nft-stats-api
API_TASK_DEFINITION: aws/prod-backend-task-definition.json
ECS_CLUSTER: prod-nft-stats-cluster
ECS_SERVICE: prod-nft-stats-api-service
CONTAINER_NAME: prod-nft-stats-api
DOCKER_TLS_CERTDIR: ""
before_script:
- apk add --no-cache --update curl jq py-pip
- pip install awscli
- cat "$PROD_ENV" > "$(pwd)/.env"
script:
- aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $REPOSITORY_URL
# Build docker image
- docker build -t $REPOSITORY_URL/$REPOSITORY_IMAGE:$CI_COMMIT_SHORT_SHA .
- docker push $REPOSITORY_URL/$REPOSITORY_IMAGE:$CI_COMMIT_SHORT_SHA
# Configure task definition - API
- sed -i -e "s/REPOSITORY_URL/$REPOSITORY_URL/g" $API_TASK_DEFINITION
- sed -i -e "s/REPOSITORY_IMAGE/$REPOSITORY_IMAGE/g" $API_TASK_DEFINITION
- sed -i -e "s/REPOSITORY_TAG/$CI_COMMIT_SHORT_SHA/g" $API_TASK_DEFINITION
# Update tasks and services - API
- API_REV=$(aws ecs register-task-definition --region $AWS_DEFAULT_REGION --cli-input-json file://$API_TASK_DEFINITION | jq --raw-output '.taskDefinition.revision')
- aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --task-definition ${CONTAINER_NAME}:${API_REV} --region $AWS_DEFAULT_REGION
- aws ecs wait services-stable --cluster $ECS_CLUSTER --service $ECS_SERVICE