Skip to content

Commit cfbb948

Browse files
authored
Set Env variables for Deployment Metrics Rendering in buildkite (#36)
* set env variables for pipeline * remove workspace * add in metrics description
1 parent ed7cc7b commit cfbb948

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.20.3
1+
FROM alpine:3.22.0
22

33
ARG TOOLBOX_VERSION
44
ENV TOOLBOX_VERSION="${TOOLBOX_VERSION}"

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ snyk:
154154
# the Buildkite pipeline. Defaults to false.
155155
always_pass: false
156156

157+
# (Optional)
158+
# APM configuration section.
159+
apm:
160+
# (Optional)
161+
# APM service name to use for submitting metrics to datadog.
162+
# This is the name used for the CI pipelines.
163+
service_name: my-service-name
164+
157165
# (Optional)
158166
# Buildkite configuration section.
159167
buildkite:

lib/buildkite.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,36 @@ _bk_sh_lint_step() {
8787
EOF
8888
}
8989

90+
91+
##
92+
## Print the APM environment variables.
93+
##
94+
_bk_apm_environment_vars() {
95+
local workspace_filter="${1}"
96+
local deployment_service
97+
deployment_service="$(config_value apm.service_name null)"
98+
99+
if [[ "${deployment_service}" != null ]]; then
100+
local environment="development"
101+
local is_production
102+
103+
while IFS=$'\t' read -r is_production; do
104+
if [[ "${is_production}" == true ]]; then
105+
environment="production"
106+
fi
107+
cat << EOF
108+
env:
109+
DD_DEPLOYMENT_ENVIRONMENT: ${environment}
110+
DD_DEPLOYMENT_SERVICE: ${deployment_service}
111+
EOF
112+
done < <(jq -r \
113+
'.terraform.workspaces // []
114+
| map(select(.name == "'"${workspace_filter}"'"))
115+
| map([.is_production])[]
116+
| @tsv' <<< "${config_json}")
117+
fi
118+
}
119+
90120
##
91121
## Print step that lints Terraform files.
92122
##
@@ -278,6 +308,7 @@ _bk_tf_apply_steps_filter() {
278308
concurrency: 1
279309
concurrency_group: ${_bk_pipeline_slug}/${workspace}
280310
EOF
311+
_bk_apm_environment_vars "${workspace}"
281312
done < <(jq -r \
282313
'.terraform.workspaces // []
283314
'"${match_filter}"'

lib/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@
170170
}
171171
}
172172
},
173+
"apm": {
174+
"type": "object",
175+
"additionalProperties": false,
176+
"required": [],
177+
"properties": {
178+
"service_name": {
179+
"type": "string"
180+
}
181+
}
182+
},
173183
"snyk": {
174184
"type": "object",
175185
"additionalProperties": false,

0 commit comments

Comments
 (0)