-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
169 lines (116 loc) · 6.78 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
variables:
IMAGE_NAME: 'kelsiem.com/logstash-input-okta_system_log'
GITLAB_API_PATH: 'api/v4'
Region: 'ap-southeast-2'
GITLAB_TOKEN: 'qfNHZ6QWQLm98mJJGSPB-deprecated'
stages:
- build
- deploy
Merge Request Feature to develop:
stage: build
script:
- echo CI_COMMIT_REF_NAME is $CI_COMMIT_REF_NAME
- THIS_MERGE_ID=`curl -s -X POST 'https://gitlab.kelsiem.io/'$GITLAB_API_PATH'/projects/'$CI_PROJECT_ID'/merge_requests' -H "Content-Type:application/json" -H 'PRIVATE-TOKEN:'$GITLAB_TOKEN --data '{"source_branch":"'$CI_COMMIT_REF_NAME'","target_branch":"develop","title":"merge '$CI_COMMIT_REF_NAME' to develop in '$IMAGE_NAME'"}' | jq -r ".iid"`
only:
- /^feature\/.*$/
Merge Request Develop to Test:
stage: build
script:
- echo CI_COMMIT_REF_NAME is $CI_COMMIT_REF_NAME
- THIS_MERGE_ID=`curl -s -X POST 'https://gitlab.kelsiem.io/'$GITLAB_API_PATH'/projects/'$CI_PROJECT_ID'/merge_requests' -H "Content-Type:application/json" -H 'PRIVATE-TOKEN:'$GITLAB_TOKEN --data '{"source_branch":"develop","target_branch":"test","title":"merge develop to test in '$IMAGE_NAME'"}' | jq -r ".iid"`
only:
- develop
Merge Request Test To Master:
stage: build
script:
- echo CI_COMMIT_REF_NAME is $CI_COMMIT_REF_NAME
- THIS_MERGE_ID=`curl -s -X POST 'https://gitlab.kelsiem.io/'$GITLAB_API_PATH'/projects/'$CI_PROJECT_ID'/merge_requests' -H "Content-Type:application/json" -H 'PRIVATE-TOKEN:'$GITLAB_TOKEN --data '{"source_branch":"test","target_branch":"master","title":"merge test to master in '$IMAGE_NAME'"}' | jq -r ".iid"`
only:
- test
Build and Push Base Image:
stage: build
script:
# The following is for Amazon's registry
- sudo $(sudo aws ecr get-login --region $Region --registry-ids 137112412989 | awk '{printf $1" "$2" "$3" "$4" "$5" "$6" "$9}')
# The following is for my registry
- sudo $(sudo aws ecr get-login | awk '{printf $1" "$2" "$3" "$4" "$5" "$6" "$9}')
- sudo docker build -f 0-base.Dockerfile -t $IMAGE_NAME:build .
- sudo docker tag $IMAGE_NAME:build 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:base
- sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:base || sudo aws ecr create-repository --repository-name $IMAGE_NAME --region $Region; sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:base
- sudo docker tag $IMAGE_NAME:build 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:Pipeline_$CI_PIPELINE_ID
- sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:Pipeline_$CI_PIPELINE_ID
when: manual
allow_failure: true
Build Develop:
stage: build
script:
# The following is for Amazon's registry
- sudo $(sudo aws ecr get-login --region $Region --registry-ids 137112412989 | awk '{printf $1" "$2" "$3" "$4" "$5" "$6" "$9}')
# The following is for my registry
- sudo $(sudo aws ecr get-login | awk '{printf $1" "$2" "$3" "$4" "$5" "$6" "$9}')
# Build
- sudo docker build -f 1-develop.Dockerfile -t $IMAGE_NAME:build .
# Copy to EFS
- sudo docker run --volume=/opt/efs/plugins:/opt/efs/plugins $IMAGE_NAME:build sh -c '\cp /opt/okta_system_log/*.gem /opt/efs/plugins' # FYI, /opt/efs/plugins is created in base image
# Push Develop
- sudo docker tag $IMAGE_NAME:build 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:develop
- sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:develop || sudo aws ecr create-repository --repository-name $IMAGE_NAME --region $Region; sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:develop
- sudo docker tag $IMAGE_NAME:build 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:Pipeline_$CI_PIPELINE_ID
- sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:Pipeline_$CI_PIPELINE_ID
only:
- develop
Build Test:
stage: build
script:
# The following is for Amazon's registry
- sudo $(sudo aws ecr get-login --region $Region --registry-ids 137112412989 | awk '{printf $1" "$2" "$3" "$4" "$5" "$6" "$9}')
# The following is for my registry
- sudo $(sudo aws ecr get-login | awk '{printf $1" "$2" "$3" "$4" "$5" "$6" "$9}')
# Build
- sudo docker build -f 2-test.Dockerfile -t $IMAGE_NAME:build .
# Push Test
- sudo docker tag $IMAGE_NAME:build 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:test
- sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:test || sudo aws ecr create-repository --repository-name $IMAGE_NAME --region $Region; sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:test
- sudo docker tag $IMAGE_NAME:build 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:Pipeline_$CI_PIPELINE_ID
- sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:Pipeline_$CI_PIPELINE_ID
only:
- test
Build Master:
stage: build
script:
# The following is for Amazon's registry
- sudo $(sudo aws ecr get-login --region $Region --registry-ids 137112412989 | awk '{printf $1" "$2" "$3" "$4" "$5" "$6" "$9}')
# The following is for my registry
- sudo $(sudo aws ecr get-login | awk '{printf $1" "$2" "$3" "$4" "$5" "$6" "$9}')
- sudo docker build -f 3-master.Dockerfile -t $IMAGE_NAME:build .
# Push Latest
- sudo docker tag $IMAGE_NAME:build 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:latest
- sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:latest || sudo aws ecr create-repository --repository-name $IMAGE_NAME --region $Region; sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:latest
- sudo docker tag $IMAGE_NAME:build 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:Pipeline_$CI_PIPELINE_ID
- sudo docker push 383707766587.dkr.ecr.$Region.amazonaws.com/$IMAGE_NAME:Pipeline_$CI_PIPELINE_ID
only:
- master
Push image develop to S3:
stage: deploy
script:
- okta_system_log_GemFile=`ls -rt /opt/efs/plugins/logstash-input-okta_system_log-*.gem | tail -n 1`
- echo okta_system_log_GemFile=$okta_system_log_GemFile
- sudo aws s3 cp $okta_system_log_GemFile s3://kelsiem-io-config/logstash-plugins/develop/
only:
- develop
Push image test to S3:
stage: deploy
script:
- okta_system_log_GemFile=`ls -rt /opt/efs/plugins/logstash-input-okta_system_log-*.gem | tail -n 1`
- echo okta_system_log_GemFile=$okta_system_log_GemFile
- sudo aws s3 cp $okta_system_log_GemFile s3://kelsiem-io-config/logstash-plugins/test/
only:
- test
Push image latest to S3:
stage: deploy
script:
- okta_system_log_GemFile=`ls -rt /opt/efs/plugins/logstash-input-okta_system_log-*.gem | tail -n 1`
- echo okta_system_log_GemFile=$okta_system_log_GemFile
- sudo aws s3 cp $okta_system_log_GemFile s3://kelsiem-io-config/logstash-plugins/master/
only:
- master