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

[proposal] Use rust based cp tool rather than busybox in autoinstrumentation images. #1698

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions .chloggen/cputil.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: autoinstrumentation

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Replace busybox base image with cp binary in java autoinstrumentation dockerfile

# One or more tracking issues related to the change
issues: [1600]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@

# Target Allocator owners
cmd/otel-allocator @open-telemetry/operator-ta-maintainers

# cp-utility tool
tools/cp-utility @rapphil @bryan-aguilar
Copy link
Contributor

Choose a reason for hiding this comment

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

we'll have to make another group in order to use CODEOWNERS here

4 changes: 4 additions & 0 deletions .github/workflows/publish-autoinstrumentation-java.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:

steps:
- uses: actions/checkout@v3

# this is required so that the cp-utility binary is in included in the docker context.
- name: copy cp-utility
run: cp -r tools/cp-utility autoinstrumentation/java/

- name: Read version
run: echo "VERSION=$(cat autoinstrumentation/java/version.txt)" >> $GITHUB_ENV
Expand Down
39 changes: 36 additions & 3 deletions autoinstrumentation/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,43 @@
# - Grant the necessary access to the jar. `chmod -R go+r /javaagent.jar`
# - For auto-instrumentation by container injection, the Linux command cp is
# used and must be availabe in the image.
FROM busybox

# Stage 1: Build the cp-utility binary
FROM rust:1.69 as builder
Copy link
Member

Choose a reason for hiding this comment

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

can the rust cp impl. be built for all target platforms supported by go? What I have in mind are ibm z + power (that's what we have to support).

Copy link

Choose a reason for hiding this comment

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

yes, s390x and ppc64le are supported by the rust base image and musl.

Are you using the autoinstrumentation images that are published from this repo in those platforms? I'm asking because today they only support arm and x86 (please take a look here)


WORKDIR /usr/src/cp-utility
COPY ./cp-utility .

## TARGETARCH is defined by buildx
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
ARG TARGETARCH

# Run validations and audit only on amd64 bacause it is faster and those two steps
# are only used to validate the source code and don't require anything that is
# architecture specific.

# Validations
## Validate formatting
RUN if [ $TARGETARCH = "amd64" ]; then rustup component add rustfmt && cargo fmt --check ; fi

## Audit dependencies
RUN if [ $TARGETARCH = "amd64" ]; then cargo install cargo-audit && cargo audit ; fi


# Cross-compile based on the target platform.
RUN if [ $TARGETARCH = "amd64" ]; then export ARCH="x86_64" ; \
elif [ $TARGETARCH = "arm64" ]; then export ARCH="aarch64" ; \
else false; \
fi \
&& rustup target add ${ARCH}-unknown-linux-musl \
&& cargo test --target ${ARCH}-unknown-linux-musl \
&& cargo install --target ${ARCH}-unknown-linux-musl --path . --root .

# Stage 2: Create distribution
FROM scratch

ARG version

ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$version/opentelemetry-javaagent.jar /javaagent.jar
COPY --from=builder /usr/src/cp-utility/bin/cp-utility /bin/cp

RUN chmod -R go+r /javaagent.jar
ADD --chmod=go+r https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$version/opentelemetry-javaagent.jar /javaagent.jar
3 changes: 3 additions & 0 deletions tools/cp-utility/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Use git CLI to fetch the source code instead of relying on the rust git implementation
[net]
git-fetch-with-cli = true
262 changes: 262 additions & 0 deletions tools/cp-utility/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tools/cp-utility/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "cp-utility"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# No dependencies here

[dev-dependencies]
# dependencies only used during tests
tempfile = "3.5.0"
uuid = { version = "1.3.1", features = ["v4", "fast-rng"] }

[profile.release]
# Levers to optimize the binary for size
strip = true # Strip symbols
opt-level = "z" # Size optimization
lto = true # linking time optimizations


Loading