-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket-pipelines.yml
143 lines (130 loc) · 4.42 KB
/
bitbucket-pipelines.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
# Prerequisites: $DOCKERHUB_USERNAME, $DOCKERHUB_PASSWORD, ${DOCKER_REGISTRY} setup as deployment variables
# image: atlassian/default-image:3
image: amazon/aws-cli
.set_environment: &setenv |
export DOCKER_REPO=${DOCKER_REGISTRY}/${BITBUCKET_REPO_SLUG}
export IMAGE_TAG=${DOCKER_REPO}:${BITBUCKET_COMMIT::7}
export DOCKERFILE_PATH=Dockerfile
env
aws configure set aws_access_key_id "${AWS_KEY}"
aws configure set aws_secret_access_key "${AWS_SECRET}"
aws ecr get-login-password --region "${AWS_REGION}" | docker login --username AWS --password-stdin ${DOCKER_REGISTRY}
.build_and_push_images: &build_and_push_images |
docker build . --file ${DOCKERFILE_PATH} --tag ${IMAGE_TAG}
docker push ${IMAGE_TAG}
.pull_images: &pull_images |
docker pull ${IMAGE_TAG}
.retag_and_push_images: &retag_and_push_images |
docker tag ${IMAGE_TAG} ${NEW_IMAGE_TAG}
docker push ${NEW_IMAGE_TAG}
definitions:
services:
docker:
memory: 7128
steps:
- step: &build_and_push_image_to_ecr
name: Build & Push Images To ECR
script:
- *setenv
- export NEW_IMAGE_TAG=${DOCKER_REPO}:${BITBUCKET_TAG}
- *build_and_push_images
- *retag_and_push_images
services:
- docker
caches:
- docker
size: 2x
- step: &mark_image_ready_for_prd
name: Mark Image Tag Ready For Prd
trigger: manual
script:
- *setenv
- export NEW_IMAGE_TAG=${DOCKER_REPO}:READY-FOR-PROD
- *pull_images
- *retag_and_push_images
services:
- docker
size: 2x
- step: &release_image_on_prd
name: Realse Image On Prd
script:
- *setenv
- export IMAGE_TAG=${DOCKER_REPO}:READY-FOR-PROD
- export NEW_IMAGE_TAG=${DOCKER_REPO}:${BITBUCKET_TAG}
- *pull_images
- *retag_and_push_images
services:
- docker
size: 2x
- step: &deploy_service
name: Deploy Service
script:
- *setenv
- sed 's#__DEPLOY_IMAGE_TAG__#'${DOCKER_REPO}:${BITBUCKET_TAG}'#' deploy/deployment.yaml > deploy/deployment.yml
- cat deploy/deployment.yml
- pipe: atlassian/aws-eks-kubectl-run:1.2.0
variables:
AWS_ACCESS_KEY_ID: "${AWS_KEY}" # Optional if already defined in the context.
AWS_SECRET_ACCESS_KEY: "${AWS_SECRET}" # Optional if already defined in the context.
AWS_DEFAULT_REGION: "ap-southeast-1" # Optional if already defined in the context.
CLUSTER_NAME: "${CLUSTER_NAME}"
KUBECTL_ARGS:
- "-n"
- "data-api"
KUBECTL_COMMAND: "apply"
RESOURCE_PATH: "deploy/deployment.yml"
services:
- docker
pipelines:
tags:
####################################
############ CI For STG ############
####################################
'*.*.*-stg':
- step:
name: STG - Build & Push Image
<<: *build_and_push_image_to_ecr
# - step:
# name: STG - Deploy Service
# deployment: stg
# <<: *deploy_service
####################################
############ CI For UAT ############
####################################
'*.*.*-uat':
- step:
name: UAT - Update image tag
<<: *build_and_push_image_to_ecr
# - step:
# name: UAT - Deploy Service
# deployment: uat
# <<: *deploy_service
- step:
name: READY FOR PRD - Update image tag
<<: *mark_image_ready_for_prd
trigger: manual
###################################
########## CI For PRE-PRD #########
###################################
# '*.*.*-preprd':
# - step:
# name: PRD - Update image tag
# script:
# - *setenv
# - export IMAGE_TAG=${DOCKER_REPO}:READY-FOR-PROD
# - export NEW_IMAGE_TAG=${DOCKER_REPO}:${BITBUCKET_TAG}
# services:
# - docker
# caches:
# - docker
####################################
############ CI For PRD ############
####################################
'*.*.*-prd':
- step:
name: PRD - Release Image On PRD
<<: *release_image_on_prd
# - step:
# name: PRD - Deploy Service
# deployment: prd
# <<: *deploy_service