-
Notifications
You must be signed in to change notification settings - Fork 41
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
fix: ensure image can be built on m1 macos #1602
fix: ensure image can be built on m1 macos #1602
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified on linux, make image/build
succeeds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified on MAC:
make image/build
docker --config=""/Users/pawelpaszki/kafka/managed-services-api/.docker"" build --pull -t "default-route-openshift-image-registry.apps-crc.testing/kas-fleet-manager-pawelpaszki/kas-fleet-manager:1677585248" .
[+] Building 92.1s (15/15) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 816B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 738B 0.0s
=> [internal] load metadata for registry.access.redhat.com/ubi9-minimal:9.1.0 2.7s
=> [builder 1/9] FROM registry.access.redhat.com/ubi9-minimal:9.1.0@sha256:61925d31338b7b41bfd5b6b8cf45eaf80753d415b0269fc03613c5c5049b879e 6.2s
=> => resolve registry.access.redhat.com/ubi9-minimal:9.1.0@sha256:61925d31338b7b41bfd5b6b8cf45eaf80753d415b0269fc03613c5c5049b879e 0.0s
=> => sha256:43246102cf37b0825786ca78e9a6e153c26d1a4241ddf53092e5b0ac18fe77bf 429B / 429B 0.0s
=> => sha256:3135bd90aad672f44305a68c1d7e1ab1b894ec6e0c6964d5ab40295af1920437 6.26kB / 6.26kB 0.0s
=> => sha256:ba958a445f00d91e4019b520c467e36e7f5bc07da02f2a87e9ccefbe4a70ff6d 37.85MB / 37.85MB 4.5s
=> => sha256:61925d31338b7b41bfd5b6b8cf45eaf80753d415b0269fc03613c5c5049b879e 1.47kB / 1.47kB 0.0s
=> => extracting sha256:ba958a445f00d91e4019b520c467e36e7f5bc07da02f2a87e9ccefbe4a70ff6d 1.5s
=> [internal] load build context 3.7s
=> => transferring context: 138.86MB 3.7s
=> [builder 2/9] RUN microdnf install -y tar gzip make which git 10.7s
=> [builder 3/9] RUN curl -O -J https://dl.google.com/go/go1.19.6.linux-amd64.tar.gz 5.3s
=> [builder 4/9] RUN tar -C /usr/local -xzf go1.19.6.linux-amd64.tar.gz 4.6s
=> [builder 5/9] RUN ln -s /usr/local/go/bin/go /usr/local/bin/go 0.2s
=> [builder 6/9] WORKDIR /workspace 0.0s
=> [builder 7/9] COPY . ./ 1.0s
=> [builder 8/9] RUN go mod vendor 18.5s
=> [builder 9/9] RUN make binary 41.7s
=> [stage-1 2/2] COPY --from=builder /workspace/kas-fleet-manager /usr/local/bin/ 0.2s
=> exporting to image 0.4s
=> => exporting layers 0.4s
=> => writing image sha256:9c55c2841661c3960dcb7aa8a9ac012600b8114d06001678d77787de16b7d08a 0.0s
=> => naming to default-route-openshift-image-registry.apps-crc.testing/kas-fleet-manager-pawelpaszki/kas-fleet-manager:1677585248 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Maybe a cleaner way would be setting the envvar if the user running the Makefile is on a mac? That way we don't need to hardcode the platform in the Dockerfile |
This could be achieved by doing something like (pseudocode, needs to be reviewed):
It should also be verified that when running in a non-mac OS that variable is not set on the docker build |
As a side note, I wonder if the same issue happens if podman is used, and also whether podman makes use of that envvar too |
I tested the suggestion with podman and docker, it works with docker but unfortunately it doesn't work with podman, seems like they don't use that env var 😞. However, the build cmd does have a
|
Let's do that. But let's call it |
2a5f67e
to
04e62b3
Compare
04e62b3
to
8062ff7
Compare
8062ff7
to
766ecf6
Compare
Makefile
Outdated
### Environment-sourced variables with defaults | ||
# Can be overriden by setting environment var before running | ||
# Example: | ||
# OCM_ENV=testing make run | ||
# export OCM_ENV=testing; make run | ||
|
||
ifeq ($(shell uname -s | tr A-Z a-z), darwin) | ||
CONTAINER_IMAGE_BUILD_PLATFORM ?= --platform linux/amd64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see some issues on the CI side.
Maybe this default value has to be quoted?
It contains dashes which mght be being interpreted as some shell flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried removing this assignment and i'm also getting the same issue.
In main, as soon as I removed these lines, I get the same issue as what's shown in the CI
Lines 165 to 169 in 738b7b8
ifeq ($(shell uname -s | tr A-Z a-z), darwin) | |
PGHOST:="127.0.0.1" | |
else | |
PGHOST:="172.18.0.22" | |
endif |
These vars never get assigned which causes the error
Lines 177 to 198 in 738b7b8
ifndef OCM_ENV | |
OCM_ENV:=integration | |
endif | |
ifndef TEST_SUMMARY_FORMAT | |
TEST_SUMMARY_FORMAT=short-verbose | |
endif | |
export GOPROXY=https://proxy.golang.org | |
export GOPRIVATE=gitlab.cee.redhat.com | |
ifndef SERVER_URL | |
SERVER_URL:=http://localhost:8000 | |
endif | |
ifndef TEST_TIMEOUT | |
ifeq ($(OCM_ENV), integration) | |
TEST_TIMEOUT=15m | |
else | |
TEST_TIMEOUT=5h | |
endif | |
endif |
Going to look into this a bit further 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JameelB I'd suggest we defer removing this onto another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the spaces inside the PGHOST ifelse are whitespaces and not tabs. Might that be causing the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing this, it seems like Makefile doesn't like var definitions between target definitions.
I've moved all of the var definitions before the target definitions starts to ensure they're set correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can identify where is the issue:
Inside ifndef
... endif
blocks it seems that the characters used to indent matters.
For example, for the TEST_VAR_4 ifndef block:
if inside the body the TEST_VAR_4 initialization is not indented then it seems to work
if inside the body the TEST_VAR_4 initialization is indented with spaces it seems to work
if inside the body the TEST_VAR_4 initialization is indented with tabs it does not seem to work
I think the issue is that by indenting with tab the Makefile interprets the indented contend with tab as part of a Makefile target's body, but in this case we are not working in a target body so that's the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that the order where var definitions appear shouldn't really matter (as long as they are defined/set before being used). The issue is another and has to do with indentation inside Makefile conditional directives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good spot, that looks like it.
Vars like OCM_ENV
which is used across multiple make targets should probably stay at the top though.
We can re-arrange some of the target specific ones like TEST_SUMMARY_FORMAT
to be grouped with the test targets if preferred. Some of the vars here are only ever used for one target as well (i.e. SERVER_URL), in that case it should probably be defined as a target variable. 🤔
There's probably more vars in there that needs to be reviewed to be removed or moved 🤔 I can create a follow on PR for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rearranging them is good for organization purposes so we can do that.
But in any case we have to fix the issues of tabs being used in conditionals that are not shell conditionals but makefile conditionals.
For this PR let's do the order reorganization and fixing the indentation for the makefile conditionals.
For another PR(s) we can review the removal or re-scoping of some of the variables.
I also suspect that some ifndefs can be just rewritten as MYVAR ?= defaultavalue or MYVAR := value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've updated this to remove the indentation from the make if statements.
I've also moved the ones in this block to group them with their related make targets but I haven't looked at any of the other var definitions outside of this.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1602 +/- ##
==========================================
- Coverage 81.81% 81.67% -0.14%
==========================================
Files 158 158
Lines 14791 14839 +48
==========================================
+ Hits 12101 12120 +19
- Misses 2266 2288 +22
- Partials 424 431 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Makefile
Outdated
export GOPRIVATE=gitlab.cee.redhat.com | ||
|
||
ifeq ($(shell uname -s | tr A-Z a-z), darwin) | ||
CONTAINER_IMAGE_BUILD_PLATFORM ?= --platform linux/amd64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we double quote the value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, note that I had to use echo for this in the image build commands to get rid of the quotes as docker build doesn't accept "--platform linux/amd64"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok then let's unquote it. It seems that Makefile doesn't really interpret single/double quotes and it considers them literally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes removed 👍
c7639ef
to
49bb9eb
Compare
When running any of the image build make targets on an m1 macos, it fails due to the following error: qemu-x87_64: Could not open '/lib64/ld-linux-x86-64.so.2 Specify platform to ensure build uses the correct architecture.
…ions with their related make targets
49bb9eb
to
3306946
Compare
Description
When running any of the image build make targets on an M1 MacOS, it fails with the following error:
More details on this error can be found in this thread.
Note that this is a temporary workaround. An issue has been created to look into how to build KFM in multiple platforms natively, see MGDSTRM-10800.
Verification Steps
Checklist (Definition of Done)
All acceptance criteria specified in JIRA have been completedUnit and integration tests added that prove the fix is effective or the feature works (tested against emulated and non-emulated OCM environment)Documentation added for the featureCI and all relevant tests are passingRequired metrics/dashboards/alerts have been added (or PR created).Required Standard Operating Procedure (SOP) is added.JIRA has been created for changes required on the client side