Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cflinuxfs4 stack #174

Merged
merged 49 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e4c9482
wip: convert python scripts to ruby
NouemanKHAL Jun 6, 2023
d5bdc3a
reset Dockerfile
NouemanKHAL Jun 22, 2023
2b4d837
reset datadog.yaml file
NouemanKHAL Jun 22, 2023
d52a49a
export new PATH with ruby/bin and update dd_export_env and safe_sourc…
NouemanKHAL Jul 3, 2023
9fc036a
add install-ruby script (must be compatible with dash)
NouemanKHAL Jul 3, 2023
8e5a796
remove install-ruby script
NouemanKHAL Jul 3, 2023
833897a
add ruby tarball to the source and install it offline
NouemanKHAL Jul 3, 2023
79e3fd1
fix supply script: RUBY_TAR path and some code still using install-ruby
NouemanKHAL Jul 3, 2023
11df8bd
update all the scripts to use instead of ruby
NouemanKHAL Jul 3, 2023
c1edf2d
update all scripts to use RUBY_BIN as the existing binary if ruby is …
NouemanKHAL Jul 3, 2023
1ea62e6
fix supply to use existing ruby binary
NouemanKHAL Jul 4, 2023
1da767e
remove some extra code
NouemanKHAL Jul 4, 2023
efbc64a
remove PATH export in dd_export_env as its not needed
NouemanKHAL Jul 4, 2023
414b73e
match bin/compile with bin/supply
NouemanKHAL Jul 4, 2023
b3f3d49
add download_ruby function to scripts/prepare.sh
NouemanKHAL Jul 4, 2023
371a164
use the downloaded ruby tarball
NouemanKHAL Jul 4, 2023
02a6320
update .gitignore to ignore the ruby_3.0.5.tgz file
NouemanKHAL Jul 4, 2023
e7793c6
WIP
NouemanKHAL Jul 11, 2023
1eea0ac
dev 8
NouemanKHAL Jul 19, 2023
30eff09
add exports for ruby libs
NouemanKHAL Jul 20, 2023
aded312
working ruby PATH export
NouemanKHAL Jul 20, 2023
895756f
remove RUBY_BIN from bin/supply and all RUBY_DIR paths to PATH
NouemanKHAL Jul 21, 2023
d9a9783
update Installing Ruby message
NouemanKHAL Jul 21, 2023
fbcd54f
stop copying the ruby.tgz to DATADOG_DIR
NouemanKHAL Jul 21, 2023
ad3411f
remove RUBY_DIR
NouemanKHAL Jul 21, 2023
d9a171f
remove ruby from test-endpoint.sh
NouemanKHAL Jul 21, 2023
9323837
export .global_env file with the PATH variable
NouemanKHAL Jul 21, 2023
2ee5abd
use .global_env to remove RUBY_BIN from update_agent_config.sh
NouemanKHAL Jul 21, 2023
0acc5de
fix the PATH export to always keep current PATH of the calling process
NouemanKHAL Jul 21, 2023
23f713d
remove RUBY_BIN from run-datadog.sh
NouemanKHAL Jul 21, 2023
9a29006
fix redirect-logs.sh indirect using of ruby via the redirect function
NouemanKHAL Jul 22, 2023
f374da8
delete find_ruby func and RUBY_BIN from utils.sh
NouemanKHAL Jul 22, 2023
aa6e910
print the VERSION from the file in config.yml
NouemanKHAL Jul 22, 2023
38fb15e
cleanup + fix VERSION file output to the config.yml
NouemanKHAL Jul 22, 2023
4754905
Merge remote-tracking branch 'origin/master' into noueman/working-rub…
NouemanKHAL Jul 22, 2023
156f214
sync bin/compile with bin/supply
NouemanKHAL Jul 22, 2023
abe7d05
reset VERSION file
NouemanKHAL Jul 22, 2023
89516d6
recompute DD_TAGS in test-endpoint.sh using ruby
NouemanKHAL Jul 22, 2023
28ad6d2
cleanup + output VERSION in the supply/compile scripts
NouemanKHAL Jul 22, 2023
7999832
fix .global_env to import PATH only when ruby is missing
NouemanKHAL Jul 25, 2023
c0e570a
print ruby version in the same line
NouemanKHAL Jul 25, 2023
1d28a8c
update bin/compile to match bin/supply
NouemanKHAL Jul 25, 2023
724789f
fix .global_env to only add the buildpack directory to the PATH
NouemanKHAL Jul 25, 2023
430ea4d
update PATH exports to add the new paths to the end to avoid shadowin…
NouemanKHAL Jul 26, 2023
d4d5d97
make the compile script a symlink to supply script
NouemanKHAL Jul 26, 2023
a0d0c87
fix RUBY_CMD to point to the ruby bin
NouemanKHAL Jul 27, 2023
12b4d8e
revert bin/compile to symlink change
NouemanKHAL Jul 27, 2023
17ba16c
cleanup + add comments
NouemanKHAL Jul 27, 2023
670cb06
add ruby to 3rd-party license
NouemanKHAL Aug 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib/dogstatsd
lib/agent
lib/trace-agent
lib/ruby_3.0.5.tgz
venv
tmp
.DS_Store
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Component,Origin,License,Copyright
lib,ruby,BSD-2-Clause,Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
38 changes: 33 additions & 5 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
#!/usr/bin/env bash

echo "-----> DatadogBuildpack/compile"


BIN_DIR=$(cd $(dirname $0); pwd)
ROOT_DIR=$(dirname ${BIN_DIR})
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
DEPS_DIR=$3
DEPS_IDX=$4
DATADOG_DIR="${BUILD_DIR}/.datadog"
BUILDPACK_VERSION="$(cat "${ROOT_DIR}/VERSION")"

echo "-----> DatadogBuildpack/$(basename $0) version $BUILDPACK_VERSION"

mkdir -p "${DATADOG_DIR}/scripts"
cp "${ROOT_DIR}/lib/scripts/update_agent_config.sh" "${DATADOG_DIR}/scripts/update_agent_config.sh"
chmod +x "${DATADOG_DIR}/scripts/update_agent_config.sh"
cp "${ROOT_DIR}/lib/scripts/get_tags.rb" "${DATADOG_DIR}/scripts/get_tags.rb"


RUBY_CMD=ruby

# install ruby if needed (the case of cflinuxfs4 or custom stacks)
if ! which ruby > /dev/null; then
NouemanKHAL marked this conversation as resolved.
Show resolved Hide resolved
echo "Installing Ruby"
tar -xzf "${ROOT_DIR}/lib/ruby_3.0.5.tgz" -C "$DEPS_DIR/$DEPS_IDX" && echo "Ruby Install finished"
export PATH=$PATH:/home/vcap/deps/$DEPS_IDX/bin
RUBY_CMD=$DEPS_DIR/$DEPS_IDX/bin/ruby
fi

# create a .global_env file to be sourced by external scripts
# for now, it appends the buildpack deps/bin folder to the PATH env variable of the caller
# this is needed for stacks where ruby is not installed since our scripts rely on it
echo "if ! which ruby > /dev/null; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "if ! which ruby > /dev/null; then
echo "if ! which ruby > /dev/null; then

Can you add a comment here explaining why we do this?

export PATH=\$PATH:/home/vcap/deps/$DEPS_IDX/bin
fi" > "$DATADOG_DIR/.global_env"

# for subsquent buildpacks and for buildpack metadata detection
echo "config: {}
name: datadog
version: ${BUILDPACK_VERSION}" > "$DEPS_DIR/$DEPS_IDX/config.yml"

echo "Installing Datadog IOT Agent, Dogstatsd and Trace Agent"

mkdir -p "${BUILD_DIR}/.profile.d"
Expand All @@ -37,6 +61,7 @@ cp "${ROOT_DIR}/lib/scripts/update_tags.rb" "${DATADOG_DIR}/scripts/update_tags.

cp "${ROOT_DIR}/lib/scripts/parse_env_vars.rb" "${DATADOG_DIR}/scripts/parse_env_vars.rb"
cp "${ROOT_DIR}/lib/scripts/nc.rb" "${DATADOG_DIR}/scripts/nc.rb"

cp "${ROOT_DIR}/lib/scripts/utils.sh" "${DATADOG_DIR}/scripts/utils.sh"
cp "${ROOT_DIR}/lib/scripts/check_datadog.sh" "${DATADOG_DIR}/scripts/check_datadog.sh"

Expand Down Expand Up @@ -67,8 +92,11 @@ chmod +x "${BUILD_DIR}/.profile.d/01-run-datadog.sh"
# export DD environment variables
dd_export_env "${DATADOG_DIR}/.raw_datadog_env"

# for debugging purposes
echo "ruby version check: $($RUBY_CMD -v)"

# sanitize env vars and export a new a env file
ruby "${DATADOG_DIR}/scripts/parse_env_vars.rb" "${DATADOG_DIR}/.raw_datadog_env" "${DATADOG_DIR}/.datadog_env"
$RUBY_CMD "${DATADOG_DIR}/scripts/parse_env_vars.rb" "${DATADOG_DIR}/.raw_datadog_env" "${DATADOG_DIR}/.datadog_env"

# export DD_TAGS for ddtrace
export DD_TAGS=$(ruby "${DATADOG_DIR}"/scripts/get_tags.rb)
export DD_TAGS=$($RUBY_CMD "${DATADOG_DIR}"/scripts/get_tags.rb)
38 changes: 33 additions & 5 deletions bin/supply
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
#!/usr/bin/env bash

echo "-----> DatadogBuildpack/supply"


BIN_DIR=$(cd $(dirname $0); pwd)
ROOT_DIR=$(dirname ${BIN_DIR})
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
DEPS_DIR=$3
DEPS_IDX=$4
DATADOG_DIR="${BUILD_DIR}/.datadog"
BUILDPACK_VERSION="$(cat "${ROOT_DIR}/VERSION")"

echo "-----> DatadogBuildpack/$(basename $0) version $BUILDPACK_VERSION"

mkdir -p "${DATADOG_DIR}/scripts"
cp "${ROOT_DIR}/lib/scripts/update_agent_config.sh" "${DATADOG_DIR}/scripts/update_agent_config.sh"
chmod +x "${DATADOG_DIR}/scripts/update_agent_config.sh"
cp "${ROOT_DIR}/lib/scripts/get_tags.rb" "${DATADOG_DIR}/scripts/get_tags.rb"


RUBY_CMD=ruby

# install ruby if needed (the case of cflinuxfs4 or custom stacks)
if ! which ruby > /dev/null; then
echo "Installing Ruby"
tar -xzf "${ROOT_DIR}/lib/ruby_3.0.5.tgz" -C "$DEPS_DIR/$DEPS_IDX" && echo "Ruby Install finished"
export PATH=$PATH:/home/vcap/deps/$DEPS_IDX/bin
RUBY_CMD=$DEPS_DIR/$DEPS_IDX/bin/ruby
fi

# create a .global_env file to be sourced by external scripts
# for now, it appends the buildpack deps/bin folder to the PATH env variable of the caller
# this is needed for stacks where ruby is not installed since our scripts rely on it
echo "if ! which ruby > /dev/null; then
export PATH=\$PATH:/home/vcap/deps/$DEPS_IDX/bin
fi" > "$DATADOG_DIR/.global_env"

# for subsquent buildpacks and for buildpack metadata detection
echo "config: {}
name: datadog
version: ${BUILDPACK_VERSION}" > "$DEPS_DIR/$DEPS_IDX/config.yml"

echo "Installing Datadog IOT Agent, Dogstatsd and Trace Agent"

mkdir -p "${BUILD_DIR}/.profile.d"
Expand All @@ -37,6 +61,7 @@ cp "${ROOT_DIR}/lib/scripts/update_tags.rb" "${DATADOG_DIR}/scripts/update_tags.

cp "${ROOT_DIR}/lib/scripts/parse_env_vars.rb" "${DATADOG_DIR}/scripts/parse_env_vars.rb"
cp "${ROOT_DIR}/lib/scripts/nc.rb" "${DATADOG_DIR}/scripts/nc.rb"

cp "${ROOT_DIR}/lib/scripts/utils.sh" "${DATADOG_DIR}/scripts/utils.sh"
cp "${ROOT_DIR}/lib/scripts/check_datadog.sh" "${DATADOG_DIR}/scripts/check_datadog.sh"

Expand Down Expand Up @@ -67,8 +92,11 @@ chmod +x "${BUILD_DIR}/.profile.d/01-run-datadog.sh"
# export DD environment variables
dd_export_env "${DATADOG_DIR}/.raw_datadog_env"

# for debugging purposes
echo "ruby version check: $($RUBY_CMD -v)"

# sanitize env vars and export a new a env file
ruby "${DATADOG_DIR}/scripts/parse_env_vars.rb" "${DATADOG_DIR}/.raw_datadog_env" "${DATADOG_DIR}/.datadog_env"
$RUBY_CMD "${DATADOG_DIR}/scripts/parse_env_vars.rb" "${DATADOG_DIR}/.raw_datadog_env" "${DATADOG_DIR}/.datadog_env"

# export DD_TAGS for ddtrace
export DD_TAGS=$(ruby "${DATADOG_DIR}"/scripts/get_tags.rb)
export DD_TAGS=$($RUBY_CMD "${DATADOG_DIR}"/scripts/get_tags.rb)
3 changes: 3 additions & 0 deletions lib/redirect-logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ DATADOG_DIR="${DATADOG_DIR:-/home/vcap/app/.datadog}"

source "${DATADOG_DIR}/scripts/utils.sh"

# source updated PATH
. "$DATADOG_DIR/.global_env"

DD_EU_API_SITE="https://api.datadoghq.eu/api/"
DD_US_API_SITE="https://api.datadoghq.com/api/"
DD_API_SITE=${DD_US_API_SITE}
Expand Down
10 changes: 7 additions & 3 deletions lib/run-datadog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ SUPPRESS_DD_AGENT_OUTPUT="${SUPPRESS_DD_AGENT_OUTPUT:-true}"
DD_ENABLE_CAPI_METADATA_COLLECTION="${DD_ENABLE_CAPI_METADATA_COLLECTION:-false}"
LOCKFILE="${DATADOG_DIR}/lock"
FIRST_RUN="${FIRST_RUN:-true}"
USER_TAGS="${DD_TAGS}"

. "${DATADOG_DIR}/scripts/utils.sh"

# source updated PATH
. "$DATADOG_DIR/.global_env"

export DD_TAGS=$(ruby "${DATADOG_DIR}/scripts/get_tags.rb")
echo "${DD_TAGS}" > "${DATADOG_DIR}/.dd_tags.txt"

source "${DATADOG_DIR}/scripts/utils.sh"

setup_datadog() {
pushd "${DATADOG_DIR}"

Expand Down Expand Up @@ -231,7 +235,7 @@ main() {
exec 9>&-
fi
fi

# wait for the trace agent startup
if [ "${DD_WAIT_TRACE_AGENT}" = "true" ]; then
timeout=120
Expand Down
1 change: 1 addition & 0 deletions lib/scripts/create_logs_config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2022-Present Datadog, Inc.
Expand Down
1 change: 1 addition & 0 deletions lib/scripts/get_tags.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2017-Present Datadog, Inc.
Expand Down
1 change: 1 addition & 0 deletions lib/scripts/parse_env_vars.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2022-Present Datadog, Inc.
Expand Down
13 changes: 8 additions & 5 deletions lib/scripts/update_agent_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
DATADOG_DIR="${DATADOG_DIR:-/home/vcap/app/.datadog}"
LOCK="${DATADOG_DIR}/update_agent_config.lock"

# source updated PATH
. "$DATADOG_DIR/.global_env"

# import utils function such as log_message
release_lock() {
log_info "releasing lock '${LOCK}'"
Expand All @@ -15,7 +18,7 @@ release_lock() {

write_tags_to_file() {
export DD_TAGS=$(ruby "${DATADOG_DIR}"/scripts/get_tags.rb)

export LOGS_CONFIG_DIR="${DATADOG_DIR}/dist/conf.d/logs.d"
export LOGS_CONFIG

Expand Down Expand Up @@ -60,7 +63,7 @@ main() {
done

log_info "acquired lock '${LOCK}'"

# ensures the lock is released on exit
trap release_lock INT TERM EXIT

Expand All @@ -72,10 +75,10 @@ main() {
sleep 2
done

timeout 300s "${DATADOG_DIR}/scripts/check_datadog.sh"
timeout 300s "${DATADOG_DIR}/scripts/check_datadog.sh"
exit_code=$?
# verify that check_datadog exited successfully

# verify that check_datadog exited successfully
if [ ${exit_code} -ne 0 ]; then
log_error "could not find agent, aborting update script!"
exit ${exit_code}
Expand Down
2 changes: 1 addition & 1 deletion lib/scripts/update_tags.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2022-Present Datadog, Inc.

#!/usr/bin/env ruby

DATADOG_DIR = ENV.fetch("DATADOG_DIR", "/home/vcap/app/.datadog")
DD_UPDATE_SCRIPT_WARMUP = ENV.fetch("DD_UPDATE_SCRIPT_WARMUP", "180")
Expand Down
3 changes: 3 additions & 0 deletions lib/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ dd_export_env() {
if [ -n "${TAGS}" ]; then
echo "export TAGS='${TAGS}'" >> "${env_file}"
fi
if [ -n "${PATH}" ]; then
echo "export PATH='${PATH}'" >> "${env_file}"
fi
if [ -n "${DD_UPDATE_SCRIPT_WARMUP}" ]; then
echo "export DD_UPDATE_SCRIPT_WARMUP='${DD_UPDATE_SCRIPT_WARMUP}'" >> "${env_file}"
fi
Expand Down
5 changes: 5 additions & 0 deletions lib/test-endpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2017-Present Datadog, Inc.

DATADOG_DIR="${DATADOG_DIR:-/home/vcap/app/.datadog}"

# source updated PATH
. "$DATADOG_DIR/.global_env"

unset DD_LOGS_VALID_ENDPOINT
DATADOG_DIR="${DATADOG_DIR:-/home/vcap/app/.datadog}"
DD_EU_API_SITE="https://api.datadoghq.eu/api/"
Expand Down
7 changes: 7 additions & 0 deletions scripts/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function download_dogstatsd() {
cp ${TMPDIR}/opt/datadog-dogstatsd/bin/dogstatsd ${SRCDIR}/lib/dogstatsd
}

function download_ruby() {
curl -LS "https://buildpacks.cloudfoundry.org/dependencies/ruby/ruby_3.0.5_linux_x64_cflinuxfs3_098393c3.tgz" -o ${SRCDIR}/lib/ruby_3.0.5.tgz
}

function cleanup() {
rm -rf ${TMPDIR}
}
Expand All @@ -70,6 +74,7 @@ function main() {
rm -f ${SRCDIR}/lib/agent
rm -f ${SRCDIR}/lib/dogstatsd
rm -f ${SRCDIR}/lib/trace-agent
rm -f ${SRCDIR}/lib/ruby_3.0.5.tgz

# Download the new ones
download_trace_agent ${VERSION}
Expand All @@ -80,6 +85,8 @@ function main() {

download_dogstatsd ${VERSION}
chmod +x ${SRCDIR}/lib/dogstatsd

download_ruby
fi
}

Expand Down
Loading