This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path.gitlab-ci.yml
115 lines (108 loc) · 4.75 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
services:
- docker:dind
variables:
DOCKER_TLS_CERTDIR: ""
stages:
- build
- deploy
build-dev:
image: docker:latest
stage: build
services:
- docker:dind
environment:
name: development
tags:
- 8gb
- docker
script:
- docker login registry.gitlab.com -u $CI_REGISTRY_USER -p $CI_BUILD_TOKEN
- docker build -t threeleaf-backend:develop .
- docker tag threeleaf-backend:develop registry.gitlab.com/neotericeu/three-leaf/threeleaf-backend:develop
- docker tag threeleaf-backend:develop registry.gitlab.com/neotericeu/three-leaf/threeleaf-backend:${CI_COMMIT_SHORT_SHA}
- docker push registry.gitlab.com/neotericeu/three-leaf/threeleaf-backend:develop
- docker push registry.gitlab.com/neotericeu/three-leaf/threeleaf-backend:${CI_COMMIT_SHORT_SHA}
- export DOCKER_LOGIN=$(docker run -e AWS_ACCESS_KEY_ID=$AWS_KEY -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET -e AWS_DEFAULT_REGION=$AWS_REGION garland/aws-cli-docker:latest aws ecr get-login --no-include-email --region eu-west-1)
- $DOCKER_LOGIN
- docker tag threeleaf-backend:develop 180122916419.dkr.ecr.eu-west-1.amazonaws.com/threeleaf:develop
- docker push 180122916419.dkr.ecr.eu-west-1.amazonaws.com/threeleaf:develop
after_script:
- docker rmi threeleaf-backend:develop
- docker rmi registry.gitlab.com/neotericeu/three-leaf/threeleaf-backend:develop
- docker rmi registry.gitlab.com/neotericeu/three-leaf/threeleaf-backend:${CI_COMMIT_SHORT_SHA}
- docker rmi 180122916419.dkr.ecr.eu-west-1.amazonaws.com/threeleaf:develop
only:
- develop
deploy-dev:
image: python:latest
stage: deploy
environment:
name: development
tags:
- 8gb
- docker
dependencies:
- build-dev
script:
- pip install awscli
- curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
- echo "$(curl -s https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest.md5) /usr/local/bin/ecs-cli" | md5sum -c -
- chmod +x /usr/local/bin/ecs-cli
- ecs-cli configure --cluster threeleaf-backend --region $AWS_REGION --default-launch-type FARGATE --config-name threeleaf-backend
- ecs-cli configure profile --access-key $AWS_KEY --secret-key $AWS_SECRET --profile-name threeleaf-backend
- ecs-cli compose --file ./docker-compose.dev.yml --project-name threeleaf-backend --ecs-params ./ecs/ecs-params.dev.yml service up --cluster-config threeleaf-backend --timeout 30 --region $AWS_REGION --force-deployment --target-group-arn $AWS_TARGET_GROUP_ARN --container-name threeleaf-backend --container-port 80
only:
- develop
build-master:
image: docker:latest
stage: build
services:
- docker:dind
environment:
name: staging
tags:
- 8gb
- docker
script:
- docker build -t threeleaf-backend:master .
- export DOCKER_LOGIN=$(docker run -e AWS_ACCESS_KEY_ID=$AWS_STAG_KEY -e AWS_SECRET_ACCESS_KEY=$AWS_STAG_SECRET -e AWS_DEFAULT_REGION=$AWS_STAG_REGION garland/aws-cli-docker:latest aws ecr get-login --no-include-email)
- $DOCKER_LOGIN
- docker tag threeleaf-backend:master 391232177924.dkr.ecr.us-east-2.amazonaws.com/threeleaf-stag:master
- docker push 391232177924.dkr.ecr.us-east-2.amazonaws.com/threeleaf-stag:master
only:
- master
deploy-master:
image: python:latest
stage: deploy
environment:
name: staging
tags:
- 8gb
- docker
dependencies:
- build-master
script:
- pip install awscli
- curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
- echo "$(curl -s https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest.md5) /usr/local/bin/ecs-cli" | md5sum -c -
- chmod +x /usr/local/bin/ecs-cli
- ecs-cli configure --cluster threeleaf-stag --region $AWS_STAG_REGION --default-launch-type FARGATE --config-name threeleaf-stag
- ecs-cli configure profile --access-key $AWS_STAG_KEY --secret-key $AWS_STAG_SECRET --profile-name threeleaf-stag
- ecs-cli compose --file ./docker-compose.stag.yml --project-name threeleaf-stag --ecs-params ./ecs/ecs-params.stag.yml service up --cluster-config threeleaf-stag --timeout 30 --region $AWS_STAG_REGION --force-deployment --target-group-arn $AWS_STAG_TARGET_GROUP_ARN --container-name threeleaf-stag --container-port 80
only:
- master
build-tag:
image: docker:latest
stage: build
services:
- docker:dind
tags:
- 8gb
- docker
script:
- docker login registry.gitlab.com -u $CI_REGISTRY_USER -p $CI_BUILD_TOKEN
- docker build -t threeleaf-backend:${CI_COMMIT_TAG} .
- docker tag threeleaf-backend:${CI_COMMIT_TAG} registry.gitlab.com/neotericeu/three-leaf/threeleaf-backend:${CI_COMMIT_TAG}
- docker push registry.gitlab.com/neotericeu/three-leaf/threeleaf-backend:${CI_COMMIT_TAG}
only:
- tags