🚨 This project is still here for reference, but the concept is being now maintained in keptn-docker-tasks repo 🚨
Dockerized script that will perform the logic to perform a Keptn Onboard Project and the adding the SLO and SLI files to support Keptn Quality Gates
Use Cases:
- Add this prior to sending the keptn evaluation
Script logic:
- Valiate the passed in shipyard, sli, and slo files exists
- Download the Keptn CLI
- Authenticate the Keptn CLI for the passed in api and token
- If keptn project does not exist, then call
keptn cli create project
- If keptn service does not exist, then call
keptn cli create service
- If pass in
DYNATRACE_MONITORING
astrue
, then callkeptn configure monitoring dynatrace
for the project and callkeptn add-resource
for the passed in sli file - Always call
keptn add-resource
for the passed in slo file
Assumption for setup:
- Using
Keptn 0.7.x
and have a service onboarded. See example this repo for example for how to setup keptn on k3s with a sample application - https://github.com/dt-demos/keptn-k3s-demo - Have docker to run the
docker run
command - Use the pre-built
robjahn/keptn-prepare-project-bash
image or build your own image.
Call the docker run
command as shown in this example.
NOTE: the path to the files match the VOLUME that was specified in the docker run command. In this example mapped to the /tmp
directory within docker.
#!/bin/bash
image=robjahn/keptn-prepare-project-bash
keptnApiUrl=https://api.keptn.<YOUR KEPTN DOMAIN>
keptnApiToken=<YOUR KEPTN TOKEN>
project=demo
service=simplenodeservice
stage=dev
source=local
shipyardFile=/tmp/testing/shipyard.yaml
sloFile=/tmp/testing/slo.yaml
jmeterFile=
dynatraceMonitoring=true
dynatraceSliFile=/tmp/testing/dynatrace/sli.yaml
debug=true
docker run -it --rm \
--env KEPTN_URL=$keptnApiUrl \
--env KEPTN_TOKEN=$keptnApiToken \
--env PROJECT=$project \
--env SERVICE=$service \
--env STAGE=$stage \
--env SOURCE=$source \
--env SHIPYARD_FILE=$shipyardFile \
--env SLO_FILE=$sloFile \
--env DYNATRACE_MONITORING=$dynatraceMonitoring \
--env DYNATRACE_SLI_FILE=$dynatraceSliFile \
--env DEBUG=$debug \
-v ${PWD}:/tmp \
$image
Refer to the table below for parameters:
Required | Name | Description | Valid Values | Default |
---|---|---|---|---|
Y | KEPTN_URL | URL to Keptn API (1) | example https://api.keptn.11.22.33.44/api | |
Y | KEPTN_TOKEN | Keptn API Token (2) | ||
Y | PROJECT | Keptn Project Name | example: keptnorders | |
Y | SERVICE | Keptn Service Name | example: frontend | |
Y | STAGE | Keptn Stage Name | example: staging | |
Y | SHIPYARD_FILE | Keptn project file path within docker | example: /tmp/shipyard.yaml | |
Y | SLO_FILE | Keptn SLO path within docker | example: /tmp/slo.yaml | |
SOURCE | Description for the evaluation request | example: Azure-DevOps | unknown | |
DEBUG | Detailed Messsage | true, false | false | |
DYNATRACE_MONITORING | Configure Dynatrace monitoring for Keptn | true, false | true | |
DYNATRACE_SLI_FILE | Keptn sli file path within docker | example: /tmp/dynatrace/shipyard.yaml | ||
JMETER_FILE | Keptn jmeter file path within docker | example: /tmp/myscript.jmx |
Footnotes:
(1) Use this command to get your Keptn API URL
keptn status
(2) Use this command to get your Keptn Token. If not unix, then refer to keptn docs.
echo "$(kubectl get secret keptn-api-token -n keptn -ojsonpath={.data.keptn-api-token} | base64 --decode)"
Use the following helper unix bash scripts to build and test the docker image
buildpush.sh
builds local docker image and then pushes it to registrybuildtest.sh
builds local docker image and then calls thetest.sh
script
Local setup
-
Copy the example from the
usage
section above into a file calledtest.sh
and then adjust the values for your testing. Note thattest.sh
is part of.gitignore
so fill in your unique arguments and they won't be saved to the repo. -
After you save the file run
chmod +x test.sh
-
Test by just calling
./test.sh
and review the results in your Keptn Bridge UI