-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.yml
228 lines (199 loc) · 7.71 KB
/
config.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2.1
orbs:
buildevents: honeycombio/buildevents@0.2.7
kubernetes: circleci/kubernetes@1.3.0
executors:
linuxgo:
docker:
- image: golang:1
commands:
go-build:
steps:
## method 1 to send a command span
## the raw buildevents binary is available in the $PATH but requires more arguments
## don't use CGO so that this binary can run in alpine-linux containers
- run: |
GOOS=linux \
GOARCH=amd64 \
CGO_ENABLED=0 \
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID go_build -- \
go build -i -ldflags "-X main.Version=${MAJOR}.${MINOR}.${BUILD_NUMBER} -X main.Branch=${CIRCLE_BRANCH} -X main.Hash=${CIRCLE_SHA1}" \
-o $GOPATH/bin \
./...
jobs:
setup:
executor: linuxgo
steps:
- buildevents/start_trace
watch:
executor: linuxgo
steps:
- buildevents/watch_build_and_finish
test:
executor: linuxgo
steps:
- buildevents/with_job_span:
steps:
- checkout
## method 2 to send a command span
## buildevent/berun is a circleci friendly way to create a buildevents command span
- buildevents/berun:
bename: go_test
becommand: go test -v ./...
build:
executor: linuxgo
environment:
BUILD_NUMBER: <<pipeline.number>>
steps:
- buildevents/with_job_span:
steps:
- checkout
- run: buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID go_mod_downlaod -- go mod download
- go-build:
- run: mkdir -v artifacts; cp -v $GOPATH/bin/go-discord-bot artifacts/
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID bicep_install -- \
curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 && \
chmod +x ./bicep && \
mv ./bicep /usr/local/bin/bicep
- run: |
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID bicep_build -- \
bicep build deploy.bicep --outfile artifacts/deploy.json
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID update_pod_version -- \
sed -i "s/{{ContainerVersion}}/$MAJOR.$MINOR.$BUILD_NUMBER/g" deploy.yml \
&& cp deploy.yml artifacts/deploy.yml
- run: echo "size=$(du -sb artifacts | cut -f 1)" >> $BASH_ENV
- buildevents/add_context:
field_name: artifacts_size_bytes
field_value: $size
- buildevents/add_context:
field_name: build_version
field_value: $MAJOR.$MINOR.$BUILD_NUMBER
- store_artifacts:
path: artifacts/
- persist_to_workspace:
# Must be an absolute path, or relative path from working_directory. This is a directory on the container which is
# taken to be the root directory of the workspace.
root: artifacts
# Must be relative path from root
paths:
- go-discord-bot
- deploy.json
- deploy.yml
publish:
machine:
image: ubuntu-2004:202201-02
environment:
BUILD_NUMBER: <<pipeline.number>>
steps:
- buildevents/with_job_span:
steps:
- checkout
- attach_workspace:
# Must be absolute path or relative path from working_directory
at: artifacts
- run: echo "$ACR_PASSWORD" | docker login halbarad.azurecr.io -u $ACR_USER --password-stdin
- run: echo "export SHORT_SHA=$(echo $CIRCLE_SHA1 | head -c 8)" >> $BASH_ENV
# build the docker container
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID docker_build -- \
docker build . -t halbarad.azurecr.io/go/discord-bot:$SHORT_SHA \
-t halbarad.azurecr.io/go/discord-bot:$MAJOR.$MINOR.$BUILD_NUMBER
## push the docker container to ACR
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID docker_push -- \
docker push halbarad.azurecr.io/go/discord-bot:$SHORT_SHA && \
docker push halbarad.azurecr.io/go/discord-bot:$MAJOR.$MINOR.$BUILD_NUMBER
- buildevents/add_context:
field_name: container_version
field_value: $MAJOR.$MINOR.$BUILD_NUMBER
deploy:
docker:
- image: mcr.microsoft.com/azure-cli:2.20.0
environment:
BUILD_NUMBER: <<pipeline.number>>
steps:
- buildevents/with_job_span:
steps:
- attach_workspace:
# Must be absolute path or relative path from working_directory
at: artifacts
- kubernetes/install-kubectl
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID az_login -- \
az login --service-principal -u $AZ_SP_UUID -p $AZ_SP_PASS --tenant $AZ_SP_TENANT
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID az_infra_update -- \
az deployment group create --resource-group $AZ_RG --template-file artifacts/deploy.json \
--name $MAJOR.$MINOR.$BUILD_NUMBER --parameters containerName=$AZ_ACI
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID az_kube_connection -- \
az aks get-credentials --resource-group $AKS_RG --name $AKS_NAME
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID kube_config_update -- \
kubectl apply -f artifacts/deploy.yml
- run: |
DATE=$(date +%s)
curl https://api.honeycomb.io/1/markers/$HONEYCOMB_DATASET -X POST \
-H "X-Honeycomb-Team: $MARKER_API_KEY" \
-d '{"message":"deploy '$MAJOR'.'$MINOR'.'$BUILD_NUMBER'", "type":"deploy", "start_time":'$DATE'}'
featureflags:
docker:
- image: mcr.microsoft.com/powershell:latest
environment:
BUILD_NUMBER: <<pipeline.number>>
steps:
- buildevents/with_job_span:
steps:
- checkout
# push new flags into Optimizely
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID publish_feature_flags -- \
pwsh -File Update-FeatureFlags.ps1 -ApiKey $OPTIMIZELY_TOKEN -Path flags.json
workflows:
build:
jobs:
- setup:
filters:
tags:
only: /.*/
- watch:
requires:
- setup
filters:
tags:
only: /.*/
- test:
requires:
- setup
filters:
tags:
only: /.*/
- build:
requires:
- setup
filters:
tags:
only: /.*/
- publish:
requires:
- build
filters:
branches:
only: main
- featureflags:
requires:
- build
filters:
branches:
only: main
- deploy:
requires:
- publish
filters:
branches:
only: main