Skip to content

Commit

Permalink
Add journalctl to docker image (open-telemetry#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyc-splunk authored Dec 10, 2021
1 parent 6be5591 commit ec5bb0a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ jobs:
echo "Failing job execution: fail to start otelcol docker container in 10 seconds."
exit 1
fi
# ensure journalctl can run with the collected libraries
docker exec otelcol /bin/journalctl
docker-otelcol-windows:
name: docker-otelcol-windows
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,13 @@ endif
cp ./bin/otelcol_linux_$(ARCH) ./cmd/otelcol/otelcol
cp ./bin/translatesfx_linux_$(ARCH) ./cmd/otelcol/translatesfx
cp ./bin/migratecheckpoint_linux_$(ARCH) ./cmd/otelcol/migratecheckpoint
cp ./internal/buildscripts/packaging/collect-libs.sh ./cmd/otelcol/collect-libs.sh
docker buildx build --platform linux/$(ARCH) -o type=image,name=otelcol:$(ARCH),push=false --build-arg ARCH=$(ARCH) --build-arg SMART_AGENT_RELEASE=$(SMART_AGENT_RELEASE) ./cmd/otelcol/
docker tag otelcol:$(ARCH) otelcol:latest
rm ./cmd/otelcol/otelcol
rm ./cmd/otelcol/translatesfx
rm ./cmd/otelcol/migratecheckpoint
rm ./cmd/otelcol/collect-libs.sh

.PHONY: binaries-all-sys
binaries-all-sys: binaries-darwin_amd64 binaries-linux_amd64 binaries-linux_arm64 binaries-windows_amd64
Expand Down
10 changes: 10 additions & 0 deletions cmd/otelcol/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ RUN if [ "$ARCH" = "amd64" ]; then \
fi
RUN find /usr/lib/splunk-otel-collector/agent-bundle -wholename "*test*.key" -delete -or -wholename "*test*.pem" -delete

FROM debian:11.1 as journalctl
RUN apt update
RUN apt install -y systemd
COPY collect-libs.sh /collect-libs.sh
RUN /collect-libs.sh /opt/journalctl /bin/journalctl

FROM scratch
ENV SPLUNK_BUNDLE_DIR=/usr/lib/splunk-otel-collector/agent-bundle
ENV SPLUNK_COLLECTD_DIR=${SPLUNK_BUNDLE_DIR}/run/collectd
Expand All @@ -50,11 +56,15 @@ COPY --from=otelcol --chown=999 /otel /etc/otel
COPY --from=otelcol --chown=999 /otel/collector /etc/otel/collector
COPY --from=smartagent --chown=999 /usr/lib/splunk-otel-collector /usr/lib/splunk-otel-collector

COPY --from=journalctl --chown=999 /bin/journalctl /bin/journalctl
COPY --from=journalctl --chown=999 /opt/journalctl /

COPY --chown=999 config/collector/gateway_config.yaml /etc/otel/collector/gateway_config.yaml
COPY --chown=999 config/collector/otlp_config_linux.yaml /etc/otel/collector/otlp_config_linux.yaml
COPY --chown=999 config/collector/agent_config.yaml /etc/otel/collector/agent_config.yaml
COPY --chown=999 config/collector/fargate_config.yaml /etc/otel/collector/fargate_config.yaml
COPY --chown=999 config/collector/ecs_ec2_config.yaml /etc/otel/collector/ecs_ec2_config.yaml

USER splunk-otel-collector
ENTRYPOINT ["/otelcol"]
EXPOSE 13133 14250 14268 4317 4318 6060 8888 9411 9443 9080
80 changes: 80 additions & 0 deletions internal/buildscripts/packaging/collect-libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

set -e

usage() {
echo 'Usage: $1 output_dir binary_path ...'
}

output_dir=$1
if [[ -e "$output_dir" ]]; then
echo "$output_dir exists!" >&2
exit 1
fi
mkdir -p $output_dir

shift
binary_paths=$@

if [[ ${#binary_paths[@]} == 0 ]]
then
usage
exit 1
fi

echo "Copying dependent libs to $output_dir"

find_deps() {
local paths=$@
find $paths -type f -o -type l -and -executable -or -name "*.so*" | \
xargs ldd | \
grep -o '/.*' | awk '{print $1}' | grep -v ':$' | sort -u
}

copy_lib_and_links() {
local lib=$1
local output_dir=$2

while [ 0 ]; do
file=$(basename $lib)
dir=$(dirname $lib)
mkdir -p ${output_dir}/$dir
cp -a $lib ${output_dir}/$dir
lib=$(readlink "${dir}/$file" || true)
if [[ -z "$lib" ]]; then
break
fi
libdir=$(dirname $lib)
if [[ "${libdir:0:1}" != "/" ]]; then
lib=${dir}/$lib
fi
done
}

libs="$(find_deps $binary_paths)"
transitive_libs="$(find_deps $libs)"

for lib in $libs $transitive_libs
do
if [[ ! -e ${output_dir}/$lib ]]; then
copy_lib_and_links $lib $output_dir
echo "Pulled in $lib"
fi
done

echo "Processed $(wc -w <<< $libs) libraries"

echo "Checking for missing lib dependencies..."

# Look for all of the deps now in the output_dir and make sure we have them
new_deps=$(find_deps $output_dir)
for dep in $new_deps
do
stat ${dep} >/dev/null
if [[ $? != 0 ]]; then
echo "Missing dependency in target dir: $dep" >&2
exit 1
fi
done

echo "Everything is there!"

0 comments on commit ec5bb0a

Please sign in to comment.