forked from aws-samples/aws-appmesh-eks-gitlab-cicd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
105 lines (89 loc) · 3.49 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
image : python:3.8.6-alpine3.11
variables:
DOCKER_DRIVER: overlay2
APP_NAME: appmesh-app
default:
before_script:
- |
apk --update add curl=7.67.0-r1 jq=1.6-r0 bash=5.0.11-r1
pip --no-cache-dir install --upgrade pip awscli==1.18.154 && aws --version && rm -rf /var/cache/apk/*
export KUBECTL_VERSION=v1.19.0
curl -L -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl
chmod +x /usr/bin/kubectl
kubectl version --client
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
mv /tmp/eksctl /usr/local/bin
eksctl version
stages:
- test
- publish
- deploy
- kill
unit-test:
stage: test
script:
- sleep 3
- echo "unit-tests executed"
integration-test:
stage: test
script:
- sleep 3
- echo "integration-tests executed"
push_to_ecr:
stage: publish
image: docker:latest
services:
- docker:dind
before_script:
- |
docker --version
apk add --no-cache curl jq python3 py-pip && pip install awscli==1.18.154
script:
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
- export ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
- echo "ACCOUNT_ID= $ACCOUNT_ID"
- export REPOSITORY_URL=$ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/flask-app:${CI_PIPELINE_ID} && echo $REPOSITORY_URL
- cd src/
- docker build -t $REPOSITORY_URL .
- docker push $REPOSITORY_URL
- docker tag $REPOSITORY_URL $ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/flask-app:latest
- docker push $ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/flask-app:latest
deploy%25:
stage: deploy
when: manual
script:
- export INIT_WEIGHT=75 && export NEW_WEIGHT=25
- eksctl utils write-kubeconfig --kubeconfig kubeconfig-$CLUSTER_NAME.yaml --cluster $CLUSTER_NAME --region $AWS_DEFAULT_REGION
- export KUBECONFIG=${PWD}/kubeconfig-$CLUSTER_NAME.yaml
- chmod 775 pipeline.sh && ./pipeline.sh deploy
deploy%50:
stage: deploy
when: manual
script:
- export INIT_WEIGHT=50 && export NEW_WEIGHT=50
- eksctl utils write-kubeconfig --kubeconfig kubeconfig-$CLUSTER_NAME.yaml --cluster $CLUSTER_NAME --region $AWS_DEFAULT_REGION
- export KUBECONFIG=${PWD}/kubeconfig-$CLUSTER_NAME.yaml
- chmod 775 pipeline.sh && ./pipeline.sh deploy
deploy%75:
stage: deploy
when: manual
script:
- export INIT_WEIGHT=25 && export NEW_WEIGHT=75
- eksctl utils write-kubeconfig --kubeconfig kubeconfig-$CLUSTER_NAME.yaml --cluster $CLUSTER_NAME --region $AWS_DEFAULT_REGION
- export KUBECONFIG=${PWD}/kubeconfig-$CLUSTER_NAME.yaml
- chmod 775 pipeline.sh && ./pipeline.sh deploy
deploy%100:
stage: deploy
when: manual
script:
- export INIT_WEIGHT=0 && export NEW_WEIGHT=100
- eksctl utils write-kubeconfig --kubeconfig kubeconfig-$CLUSTER_NAME.yaml --cluster $CLUSTER_NAME --region $AWS_DEFAULT_REGION
- export KUBECONFIG=${PWD}/kubeconfig-$CLUSTER_NAME.yaml
- chmod 775 pipeline.sh && ./pipeline.sh deploy
kill_previous:
stage: kill
when: manual
script:
- eksctl utils write-kubeconfig --kubeconfig kubeconfig-$CLUSTER_NAME.yaml --cluster $CLUSTER_NAME --region $AWS_DEFAULT_REGION
- export KUBECONFIG=${PWD}/kubeconfig-$CLUSTER_NAME.yaml
- chmod 775 pipeline.sh && ./pipeline.sh destroy