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 local arm build #1157

Merged
merged 10 commits into from
Oct 14, 2022
Merged

Conversation

Efrat19
Copy link
Contributor

@Efrat19 Efrat19 commented Oct 11, 2022

Signed-off-by: Efrat19 [email protected]
Addressing #1133

Do let me know whether further changes are required
(maybe we want the makefile to choose the build method automatically based on the underlying platform?)
@jaronoff97 @pavolloffay

Signed-off-by: Efrat19 <[email protected]>
@Efrat19 Efrat19 requested a review from a team October 11, 2022 11:56
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 11, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Efrat19 / name: Efrat Levitan (d094320)

Signed-off-by: Efrat19 <[email protected]>
@jaronoff97
Copy link
Contributor

Thank you for this contribution! I think it would be great if we could have the makefile choose the build method automatically as you said in your description. If that proves to be too difficult, we can leave in this temporary solution.

Makefile Outdated
@@ -178,6 +178,11 @@ set-test-image-vars:
container:
docker build -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} .

# Build the container ARM image, used only for local dev purposes
.PHONY: container-arm-build
container-arm-build:
Copy link
Member

Choose a reason for hiding this comment

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

it says arm but the platform is linux/amd64

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Makefile Outdated
# Build the container ARM image, used only for local dev purposes
.PHONY: container-arm-build
container-arm-build:
docker buildx build --platform linux/amd64 -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} .
Copy link
Member

Choose a reason for hiding this comment

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

I have concerns about maintaining this. The command is very similar to the container target above and I fear that over time this gets outdated. I would like to find an approach to minimize duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I extracted the flags to DOCKER_BUILD_FLAGS and eliminated the extra target

@pavolloffay
Copy link
Member

@Efrat19 would the following work for you?

GOARCH ?= $(shell go env GOARCH)

# Build the container image, used only for local dev purposes
# Use buildx for arm based systems (m1/2 chips)
.PHONY: container
container:
	docker buildx build --platform linux/${GOARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION}  --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} .

I am fine using only buildx.

However the command I shared fails on my host when building other archs e.g.

GOARCH=arm64  IMG=pavolloffay/opentelemetry-operator:dev-002  make container                                                                                                                                                                                                ploffay@fedora
docker buildx build --platform linux/arm64 -t pavolloffay/opentelemetry-operator:dev-002 --build-arg VERSION_PKG="github.com/open-telemetry/opentelemetry-operator/internal/version" --build-arg VERSION="0.60.0-23-g564833d" --build-arg VERSION_DATE=2022-10-12T12:19:51Z --build-arg OTELCOL_VERSION="0.60.0" --build-arg TARGETALLOCATOR_VERSION="0.60.0" --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION="1.11.1"  --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION="0.31.0" --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION="0.34b0" --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION="0.3.1-beta.1" .
[+] Building 1.2s (11/19)                                                                                                                                                                                                                                                                                                                             
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                             0.0s
 => => transferring dockerfile: 32B                                                                                                                                                                                                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                                                                  0.0s
 => [internal] load metadata for gcr.io/distroless/static:nonroot                                                                                                                                                                                                                                                                                0.7s
 => [internal] load metadata for docker.io/library/golang:1.19                                                                                                                                                                                                                                                                                   0.8s
 => CACHED [stage-1 1/3] FROM gcr.io/distroless/static:nonroot@sha256:380318dd91fd3bea73ae5fe1eb4d795ef7923f576e6f5f8d4de6ef1ea18ed540                                                                                                                                                                                                           0.0s
 => [internal] load build context                                                                                                                                                                                                                                                                                                                0.0s
 => => transferring context: 13.62kB                                                                                                                                                                                                                                                                                                             0.0s
 => [builder  1/12] FROM docker.io/library/golang:1.19@sha256:b850621230956a6d960d6d7cfaba6a8a2e8e245b230a928ef66aa0cfd065e229                                                                                                                                                                                                                   0.0s
 => CACHED [builder  2/12] WORKDIR /workspace                                                                                                                                                                                                                                                                                                    0.0s
 => CACHED [builder  3/12] COPY go.mod go.mod                                                                                                                                                                                                                                                                                                    0.0s
 => CACHED [builder  4/12] COPY go.sum go.sum                                                                                                                                                                                                                                                                                                    0.0s
 => ERROR [builder  5/12] RUN go mod download                                                                                                                                                                                                                                                                                                    0.3s
------
 > [builder  5/12] RUN go mod download:
#0 0.258 exec /bin/sh: exec format error
------
error: failed to solve: executor failed running [/bin/sh -c go mod download]: exit code: 1
make: *** [Makefile:183: container] Error 1

@Efrat19
Copy link
Contributor Author

Efrat19 commented Oct 12, 2022

@pavolloffay Yep it also works for me on amd64 , I changed it to use buildx only
This is for contributors to be able to run the workload on their local machines so no reason to try to build a different arch than the underlying host, what do you think?

@pavolloffay
Copy link
Member

Awesome, please try if the build works.

Could you please also change container-target-allocator to use buildx?

@Efrat19
Copy link
Contributor Author

Efrat19 commented Oct 14, 2022

Sure @pavolloffay I updated container-target-allocator as well

Copy link
Member

@pavolloffay pavolloffay left a comment

Choose a reason for hiding this comment

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

e2e test failed

Makefile Outdated
.PHONY: container
container:
docker build -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} .
docker buildx build --platform linux/$(go env GOARCH) -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} .
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to have arch defined as env var in the makefile, It makes it easier to override when running the target.

Copy link
Member

@pavolloffay pavolloffay left a comment

Choose a reason for hiding this comment

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

e2e test failed

docker buildx build --platform linux/ -t local/opentelemetry-operator:e2e --build-arg VERSION_PKG="github.com/open-telemetry/opentelemetry-operator/internal/version" --build-arg VERSION="" --build-arg VERSION_DATE=2022-10-14T08:54:15Z --build-arg OTELCOL_VERSION="0.60.0" --build-arg TARGETALLOCATOR_VERSION="0.60.0" --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION="1.11.1"  --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION="0.31.0" --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION="0.34b0" --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION="0.3.1-beta.1" .
ERROR: "" is an invalid component of "linux/": platform specifier component must match "^[A-Za-z0-9_-]+$": invalid argument

the arch is not set

@Efrat19
Copy link
Contributor Author

Efrat19 commented Oct 14, 2022

I extracted $(go env GOARCH) to a var called ARCH and added a default value for the e2e runners

Makefile Outdated
@@ -10,6 +10,8 @@ AUTO_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep
AUTO_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-python | awk -F= '{print $$2}')"
AUTO_INSTRUMENTATION_DOTNET_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-dotnet | awk -F= '{print $$2}')"
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION}"
ARCH = $(shell go env GOARCH)
ARCH ?= amd64
Copy link
Member

Choose a reason for hiding this comment

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

it should be ARCH ?= $(shell go env GOARCH)

@pavolloffay pavolloffay merged commit bc32d51 into open-telemetry:main Oct 14, 2022
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
* add local arm build

Signed-off-by: Efrat19 <[email protected]>

* fix typo

Signed-off-by: Efrat19 <[email protected]>

* add automatic amd build if needed

* fix amd to arm

* use buildx only

* support arm builds in container-target-allocator

* add default ARCH for e2e

Signed-off-by: Efrat19 <[email protected]>

* fix ARCH var

Signed-off-by: Efrat19 <[email protected]>
Co-authored-by: Pavol Loffay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants