Skip to content

Commit 3bfe704

Browse files
authored
Merge branch 'main' into fix-gunicorn
2 parents 4dcb485 + 6177b7e commit 3bfe704

File tree

7 files changed

+685
-4
lines changed

7 files changed

+685
-4
lines changed

.codespellrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[codespell]
22
# skipping auto generated folders
33
skip = ./.tox,./.mypy_cache,./target,*/LICENSE,./venv,*/sql_dialect_keywords.json
4-
ignore-words-list = afterall,assertIn
4+
ignore-words-list = afterall,assertIn, crate

Dockerfile

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# The packages are installed in the `/autoinstrumentation` directory. This is required as when instrumenting the pod by CWOperator,
44
# one init container will be created to copy all the content in `/autoinstrumentation` directory to app's container. Then
55
# update the `PYTHONPATH` environment variable accordingly. Then in the second stage, copy the directory to `/autoinstrumentation`.
6+
7+
# Stage 1: Install ADOT Python in the /operator-build folder
68
FROM python:3.11 AS build
79

810
WORKDIR /operator-build
@@ -18,11 +20,42 @@ RUN sed -i "/opentelemetry-exporter-otlp-proto-grpc/d" ./aws-opentelemetry-distr
1820

1921
RUN mkdir workspace && pip install --target workspace ./aws-opentelemetry-distro
2022

21-
FROM public.ecr.aws/amazonlinux/amazonlinux:minimal
23+
# Stage 2: Build the cp-utility binary
24+
FROM rust:1.75 as builder
25+
26+
WORKDIR /usr/src/cp-utility
27+
COPY ./tools/cp-utility .
28+
29+
## TARGETARCH is defined by buildx
30+
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
31+
ARG TARGETARCH
32+
33+
# Run validations and audit only on amd64 because it is faster and those two steps
34+
# are only used to validate the source code and don't require anything that is
35+
# architecture specific.
36+
37+
# Validations
38+
# Validate formatting
39+
RUN if [ $TARGETARCH = "amd64" ]; then rustup component add rustfmt && cargo fmt --check ; fi
40+
41+
# Audit dependencies
42+
RUN if [ $TARGETARCH = "amd64" ]; then cargo install cargo-audit && cargo audit ; fi
43+
44+
45+
# Cross-compile based on the target platform.
46+
RUN if [ $TARGETARCH = "amd64" ]; then export ARCH="x86_64" ; \
47+
elif [ $TARGETARCH = "arm64" ]; then export ARCH="aarch64" ; \
48+
else false; \
49+
fi \
50+
&& rustup target add ${ARCH}-unknown-linux-musl \
51+
&& cargo test --target ${ARCH}-unknown-linux-musl \
52+
&& cargo install --target ${ARCH}-unknown-linux-musl --path . --root .
53+
54+
# Stage 3: Build the distribution image by copying the THIRD-PARTY-LICENSES, the custom built cp command from stage 2, and the installed ADOT Python from stage 1 to their respective destinations
55+
FROM scratch
2256

2357
# Required to copy attribute files to distributed docker images
2458
ADD THIRD-PARTY-LICENSES ./THIRD-PARTY-LICENSES
2559

60+
COPY --from=builder /usr/src/cp-utility/bin/cp-utility /bin/cp
2661
COPY --from=build /operator-build/workspace /autoinstrumentation
27-
28-
RUN chmod -R go+r /autoinstrumentation

tools/cp-utility/.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Use git CLI to fetch the source code instead of relying on the rust git implementation
2+
[net]
3+
git-fetch-with-cli = true

tools/cp-utility/Cargo.lock

Lines changed: 221 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/cp-utility/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "cp-utility"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
# No dependencies here
10+
11+
[dev-dependencies]
12+
# dependencies only used during tests
13+
tempfile = "3.9.0"
14+
uuid = { version = "1.5.0", features = ["v4", "fast-rng"] }
15+
16+
[profile.release]
17+
# Levers to optimize the binary for size
18+
strip = true # Strip symbols
19+
opt-level = "z" # Size optimization
20+
lto = true # linking time optimizations
21+
22+

tools/cp-utility/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Introduction
2+
3+
This copy utility is intended to be used as a base image for OpenTelemetry Operator
4+
autoinstrumentation images. The copy utility will allow the ADOT Java agent jar to be
5+
copied from the init container to the final destination volume.
6+
7+
## Development
8+
9+
### Pre-requirements
10+
* Install rust
11+
12+
```
13+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
14+
```
15+
16+
* Install rustfmt
17+
18+
```
19+
rustup component add rustfmt
20+
```
21+
22+
### Development
23+
24+
* Auto formatting the code
25+
26+
This step is important and it might fail the build if the files are not properly
27+
formatted.
28+
29+
```
30+
cargo fmt
31+
```
32+
33+
* Testing the code
34+
```
35+
cargo test
36+
```
37+
38+
* Building the code
39+
40+
```
41+
cargo build
42+
```
43+
44+
NOTE: this will build the code for tests locally. It will not statically link the libc used by it.
45+
46+
47+
* Building the code statically linked
48+
49+
```
50+
cargo build --target x86_64-unknown-linux-musl
51+
```
52+
53+
54+
### Docker image
55+
56+
In the root of this project, there is a Dockerfile that is supposed to be used during release.
57+
This Dockerfile can be used with buildx to generate images for the arm64 and x86_64 platforms.

0 commit comments

Comments
 (0)