-
Notifications
You must be signed in to change notification settings - Fork 438
/
generate.sh
executable file
·120 lines (98 loc) · 2.89 KB
/
generate.sh
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
#!/bin/bash
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
#
# Adapted from:
# opentelemetry-java/buildscripts/semantic-convention/generate.sh
# for opentelemetry-cpp
#
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="${SCRIPT_DIR}/../../"
# freeze the spec & generator tools versions to make the generation reproducible
# repository: https://github.com/open-telemetry/semantic-conventions
SEMCONV_VERSION=1.29.0
# repository: https://github.com/open-telemetry/weaver
WEAVER_VERSION=0.11.0
SEMCONV_VERSION_TAG=v$SEMCONV_VERSION
WEAVER_VERSION_TAG=v$WEAVER_VERSION
SCHEMA_URL="https://opentelemetry.io/schemas/${SEMCONV_VERSION}"
INCUBATING_DIR=incubating
cd ${SCRIPT_DIR}
rm -rf semantic-conventions || true
mkdir semantic-conventions
cd semantic-conventions
git init
git remote add origin https://github.com/open-telemetry/semantic-conventions.git
git fetch origin "$SEMCONV_VERSION_TAG"
git reset --hard FETCH_HEAD
cd ${SCRIPT_DIR}
# SELINUX
# https://docs.docker.com/storage/bind-mounts/#configure-the-selinux-label
USE_MOUNT_OPTION=""
if [ -x "$(command -v getenforce)" ]; then
SELINUXSTATUS=$(getenforce);
if [ "${SELINUXSTATUS}" == "Enforcing" ]; then
echo "Detected SELINUX"
USE_MOUNT_OPTION=":z"
fi;
fi
# DOCKER
# ======
#
# docker is a root container
#
# MY_UID=$(id -u)
# MY_GID=$(id -g)
# docker --user ${MY_UID}:${MY_GID}
#
# PODMAN
# ======
#
# podman is a rootless container
# docker is an alias to podman
#
# docker --user 0:0
MY_UID=$(id -u)
MY_GID=$(id -g)
if [ -x "$(command -v docker)" ]; then
PODMANSTATUS=$(docker -v | grep -c podman);
if [ "${PODMANSTATUS}" -ge "1" ]; then
echo "Detected PODMAN"
# podman is a rootless container.
# Execute the docker image as root,
# to avoid creating files as weaver:weaver in the container,
# so files end up created as the local user:group outside the container.
MY_UID="0"
MY_GID="0"
# Possible alternate solution: --userns=keep-id
fi;
fi
generate() {
TARGET=$1
OUTPUT=$2
FILTER=$3
docker run --rm --user ${MY_UID}:${MY_GID} \
-v ${SCRIPT_DIR}/semantic-conventions/model:/source${USE_MOUNT_OPTION} \
-v ${SCRIPT_DIR}/templates:/templates${USE_MOUNT_OPTION} \
-v ${ROOT_DIR}/tmpgen/:/output${USE_MOUNT_OPTION} \
otel/weaver:$WEAVER_VERSION_TAG \
registry \
generate \
--registry=/source \
--templates=/templates \
${TARGET} \
/output/${TARGET} \
--param output=${OUTPUT} \
--param filter=${FILTER} \
--param schema_url=${SCHEMA_URL}
}
# stable attributes and metrics
mkdir -p ${ROOT_DIR}/tmpgen
generate "./" "./" "stable"
mkdir -p ${ROOT_DIR}/tmpgen/${INCUBATING_DIR}
generate "./" "./${INCUBATING_DIR}/" "any"
cp -r ${ROOT_DIR}/tmpgen/*.h \
${ROOT_DIR}/api/include/opentelemetry/semconv/
cp -r ${ROOT_DIR}/tmpgen/${INCUBATING_DIR}/*.h \
${ROOT_DIR}/api/include/opentelemetry/semconv/incubating