Skip to content

Commit

Permalink
autoinstrumentation: install musl based autoinstrumentation in Python…
Browse files Browse the repository at this point in the history
… Docker image (#3384)

* autoinstrumentation: install musl in Python Docker image

* Add changelog
  • Loading branch information
xrmx authored Oct 28, 2024
1 parent 6346d40 commit 99bf725
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .chloggen/3384-build-musl-python-autoinstrumentation.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. collector, target allocator, auto-instrumentation, opamp, github action)
component: auto-instrumentation

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: build musl based auto-instrumentation in Python docker image

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

# (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:
19 changes: 15 additions & 4 deletions autoinstrumentation/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# To build one auto-instrumentation image for Python, please:
# - Ensure the packages are installed in the `/autoinstrumentation` directory. This is required as when instrumenting the pod,
# one init container will be created to copy all the content in `/autoinstrumentation` directory to your app's container. Then
# - Ensure the packages are installed in the `/autoinstrumentation,{-musl}` directory. This is required as when instrumenting the pod,
# one init container will be created to copy all the content in `/autoinstrumentation{,-musl}` directory to your app's container. Then
# update the `PYTHONPATH` environment variable accordingly. To achieve this, you can mimic the one in `autoinstrumentation/python/Dockerfile`
# by using multi-stage builds. In the first stage, install all the required packages in one custom directory with `pip install --target`.
# Then in the second stage, copy the directory to `/autoinstrumentation`.
# Then in the second stage, copy the directory to `/autoinstrumentation{,-musl}`.
# - Ensure you have `opentelemetry-distro` and `opentelemetry-instrumentation` or your customized alternatives installed.
# Those two packages are essential to Python auto-instrumentation.
# - Grant the necessary access to `/autoinstrumentation` directory. `chmod -R go+r /autoinstrumentation`
# - Grant the necessary access to `/autoinstrumentation{,-musl}` directory. `chmod -R go+r /autoinstrumentation`
# - For auto-instrumentation by container injection, the Linux command cp is
# used and must be availabe in the image.
FROM python:3.11 AS build
Expand All @@ -17,8 +17,19 @@ ADD requirements.txt .

RUN mkdir workspace && pip install --target workspace -r requirements.txt

FROM python:3.11-alpine AS build-musl

WORKDIR /operator-build

ADD requirements.txt .

RUN apk add gcc python3-dev musl-dev linux-headers
RUN mkdir workspace && pip install --target workspace -r requirements.txt

FROM busybox

COPY --from=build /operator-build/workspace /autoinstrumentation
COPY --from=build-musl /operator-build/workspace /autoinstrumentation-musl

RUN chmod -R go+r /autoinstrumentation
RUN chmod -R go+r /autoinstrumentation-musl

0 comments on commit 99bf725

Please sign in to comment.