Skip to content

Commit

Permalink
GitLab compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneTR committed Oct 18, 2024
1 parent 2b5b6ff commit 0d7c4d5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,14 @@ See also our [work on analysing fixed frequency in Cloud Providers and CI/CD](ht

### Testing

For local testing you can just run in the docker container of your choice, directly from the root of the repository:
For local testing you can just run in the docker container of your choice, directly from the root of the repository.

Here is an example with the Circle-CI base image:
```bash
docker run --rm -it -v ./:/tmp/data:ro cimg/base:current bash /tmp/data/local_ci.example.sh
```

### Testing for KDE pipelines
```bash
docker run --rm -it -v ./:/tmp/data:ro invent-registry.kde.org/sysadmin/ci-images/suse-qt67:latest bash /tmp/data/local_ci.example.sh
```
11 changes: 7 additions & 4 deletions eco-ci-gitlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ variables:
ECO_CI_DISPLAY_BADGE: "true"
ECO_CI_DISPLAY_TABLE: "true"
ECO_CI_SHOW_CARBON: "true"
ECO_CI_COMPANY_UUID: ""
ECO_CI_PROJECT_UUID: ""
ECO_CI_MACHINE_UUID: ""
ECO_CI_FILTER_TYPE: ""
ECO_CI_FILTER_PROJECT: ""
ECO_CI_FILTER_MACHINE: ""
ECO_CI_FILTER_TAGS: ""
ECO_CI_JSON_OUTPUT: "false"
ECO_CI_CALCULATE_CO2: "true"
ECO_CI_CLONE_BRANCH: "main"
ECO_CI_MACHINE_POWER_DATA: "gitlab_EPYC_7B12_saas-linux-small-amd64.sh"
ECO_CI_API_ENDPOINT_ADD: "https://api.green-coding.io/v2/ci/measurement/add"
ECO_CI_API_BADGE_GET: "https://api.green-coding.io/v1/ci/badge/get"

.start_measurement:
script:
Expand All @@ -20,7 +23,7 @@ variables:
fi
git clone --depth 1 --single-branch --branch "${ECO_CI_CLONE_BRANCH}" https://github.com/green-coding-solutions/eco-ci-energy-estimation /tmp/eco-ci-repo
/tmp/eco-ci-repo/scripts/setup.sh start_measurement "${ECO_CI_MACHINE_POWER_DATA}" "${CI_PIPELINE_ID}" "${CI_COMMIT_REF_NAME}" "${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}" "${CI_PROJECT_ID}" "gitlab-ci.yml" "${CI_COMMIT_SHA}" "gitlab" "${ECO_CI_SEND_DATA}" "${ECO_CI_COMPANY_UUID}" "${ECO_CI_PROJECT_UUID}" "${ECO_CI_MACHINE_UUID}" "${ECO_CI_CALCULATE_CO2}" "${ECO_CI_JSON_OUTPUT}"
/tmp/eco-ci-repo/scripts/setup.sh start_measurement "${ECO_CI_MACHINE_POWER_DATA}" "${CI_PIPELINE_ID}" "${CI_COMMIT_REF_NAME}" "${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}" "${CI_PROJECT_ID}" "gitlab-ci.yml" "${CI_COMMIT_SHA}" "gitlab" "${ECO_CI_SEND_DATA}" "${ECO_CI_FILTER_TYPE}" "${ECO_CI_FILTER_PROJECT}" "${ECO_CI_FILTER_MACHINE}" "${ECO_CI_FILTER_TAGS}" "${ECO_CI_CALCULATE_CO2}" "${ECO_CI_JSON_OUTPUT}" "${ECO_CI_API_ENDPOINT_ADD}" "{$ECO_CI_API_BADGE_GET}"
.get_measurement:
script:
Expand Down
35 changes: 18 additions & 17 deletions local_ci.example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@ set -euo pipefail

shell=bash

ECO_CI_SEND_DATA="true"
ECO_CI_DISPLAY_BADGE="true"
ECO_CI_DISPLAY_TABLE="true"
ECO_CI_SEND_DATA='true'
ECO_CI_DISPLAY_BADGE='true'
ECO_CI_DISPLAY_TABLE='true'

ECO_CI_WORKFLOW_ID="YOUR WORKFLOW ID"
ECO_CI_WORKFLOW_ID='YOUR WORKFLOW ID'

ECO_CI_COMPANY_UUID=""
ECO_CI_PROJECT_UUID=""
ECO_CI_MACHINE_UUID=""
# If you want filter data in the GMT Dashboard or in CarbonDB you can here manually set data for drill-down later
# The values given are just some default recommendations
ECO_CI_FILTER_TYPE=''
ECO_CI_FILTER_PROJECT='CI/CD'
ECO_CI_FILTER_MACHINE='local-runner'
ECO_CI_FILTER_TAGS='' # Tags must be comma separated. Tags cannot have commas itself or contain quotes

CALCULATE_CO2="true"
JSON_OUTPUT="true"
ECO_CI_CALCULATE_CO2='true'
ECO_CI_JSON_OUTPUT='true'

# Please input valid UUIDs here if you want to use CarbonDB (https://www.green-coding.io/projects/carbondb/)
# Generate one here for example: https://www.freecodeformat.com/validate-uuid-guid.php
# ECO_CI_COMPANY_UUID="YOUR COMPANY UUID"
# ECO_CI_PROJECT_UUID="YOUR PROJECT UUID"
# ECO_CI_MACHINE_UUID="YOUR MACHINE UUID"
# Change this to a local installation of the GMT if you have
ECO_CI_API_ENDPOINT_ADD='http://api-478gtuzwbe72.green-coding.io:9142/v2/ci/measurement/add'
ECO_CI_API_BADGE_GET='https://api.green-coding.io/v1/ci/badge/get'

# Use a generated power curve from Cloud Energy here
MACHINE_POWER_DATA="default.sh"
ECO_CI_MACHINE_POWER_DATA="default.sh"

# Initialize
echo "Initialize"

$shell "$(dirname "$0")/scripts/setup.sh" start_measurement "$MACHINE_POWER_DATA" "MY_RUN_ID" "NO_BRANCH" "LOCAL_TEST_REPO" "$ECO_CI_WORKFLOW_ID" "MY WORKFLOW NAME" "NO SHA" "local" "$ECO_CI_SEND_DATA" "$ECO_CI_COMPANY_UUID" "$ECO_CI_PROJECT_UUID" "$ECO_CI_MACHINE_UUID" "$CALCULATE_CO2" "$JSON_OUTPUT"
$shell "$(dirname "$0")/scripts/setup.sh" start_measurement "$ECO_CI_MACHINE_POWER_DATA" "MY_RUN_ID" "NO_BRANCH" "LOCAL_TEST_REPO" "$ECO_CI_WORKFLOW_ID" "MY WORKFLOW NAME" "NO SHA" "local" "$ECO_CI_SEND_DATA" "$ECO_CI_FILTER_TYPE" "$ECO_CI_FILTER_PROJECT" "$ECO_CI_FILTER_MACHINE" "$ECO_CI_FILTER_TAGS" "$ECO_CI_CALCULATE_CO2" "$ECO_CI_JSON_OUTPUT" "$ECO_CI_API_ENDPOINT_ADD" "$ECO_CI_API_BADGE_GET"

echo "Duration: "$(($(date +%s) - $(cat /tmp/eco-ci/timer-total.txt)))

Expand Down Expand Up @@ -67,7 +68,7 @@ cat /tmp/eco-ci/cpu-util-total.txt

$shell "$(dirname "$0")/scripts/display_results.sh" display_results $ECO_CI_DISPLAY_TABLE $ECO_CI_DISPLAY_BADGE

if [[ "$JSON_OUTPUT" == 'true' ]]; then
if [[ "$ECO_CI_JSON_OUTPUT" == 'true' ]]; then
echo "JSON Dump:"
cat /tmp/eco-ci/lap-data.json
cat /tmp/eco-ci/total-data.json
Expand Down
5 changes: 4 additions & 1 deletion scripts/make_measurement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ function make_measurement() {
unit="mJ"
model_name_uri=$(echo $MODEL_NAME | jq -Rr @uri)

tags_as_json_list=$(echo "\"${FILTER_TAGS}\"" | sed s/,/\",\"/g)
tags_as_json_list=''
if [[ "$FILTER_TAGS" != '' ]]; then # prevent sending [""] array if empty
tags_as_json_list=$(echo "\"${FILTER_TAGS}\"" | sed s/,/\",\"/g)
fi

curl -X POST "${API_ENDPOINT_ADD}" -H 'Content-Type: application/json' -d "{
\"energy_uj\":\"${value_uJ}\",
Expand Down

0 comments on commit 0d7c4d5

Please sign in to comment.