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

In Pillar, add new Makefile targets for Docker dev builds and shell access. #3575

Merged

Conversation

OhmSpectator
Copy link
Member

The Makefile has been updated to include two new targets: build-docker-dev and enter-docker-dev. These targets are designed to facilitate the evaluation of the codebase's state during the build process.

The build-docker-dev target constructs a Docker image up to the 'build' stage, enabling developers to assess the intermediate state of the code, particularly useful when applying patches that might only be present in temporary containers and are difficult to inspect otherwise.

Following the build, the enter-docker-dev target allows for immediate shell access within this intermediate Docker container, streamlining the process for developers to interact with the code and build environment directly.

The Makefile has been updated to include two new targets: `build-docker-dev`
and `enter-docker-dev`. These targets are designed to facilitate the evaluation
of the codebase's state during the build process.

The `build-docker-dev` target constructs a Docker image up to the 'build'
stage, enabling developers to assess the intermediate state of the code,
particularly useful when applying patches that might only be present in
temporary containers and are difficult to inspect otherwise.

Following the build, the `enter-docker-dev` target allows for immediate shell
access within this intermediate Docker container, streamlining the process
for developers to interact with the code and build environment directly.

Signed-off-by: Nikolay Martyanov <nikolay@zededa.com>
@OhmSpectator
Copy link
Member Author

Here is an example, where it can be useful: #3568 (comment)

@OhmSpectator OhmSpectator requested a review from rouming November 9, 2023 18:16
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b1fd32d) 19.46% compared to head (041734c) 19.47%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3575      +/-   ##
==========================================
+ Coverage   19.46%   19.47%   +0.01%     
==========================================
  Files         231      231              
  Lines       50211    50211              
==========================================
+ Hits         9774     9780       +6     
+ Misses      39722    39714       -8     
- Partials      715      717       +2     

see 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rouming
Copy link
Contributor

rouming commented Nov 9, 2023

I delegate the review to @christoph-zededa. He is the docker-pocker expert.

docker build $(DOCKER_ARGS) -t $(DOCKER_TAG) . --target build

enter-docker-dev: build-docker-dev
docker run -it --rm --entrypoint /bin/sh $(DOCKER_TAG)
Copy link
Contributor

Choose a reason for hiding this comment

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

I normally add:

 -v $(pwd):$(pwd) 

this way I don't have to rebuild the container if I changed a file

Copy link
Member Author

Choose a reason for hiding this comment

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

And how do you use it then? As far as I understand it will mount the host dir /pkg/pillar to / in the container, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

it mounts it to the same path in the container, f.e. for me it is: /home/christoph/projects/eve/pkg/pillar; then I do:

cd /path/to/mapped/directory
go test ./...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm... In this case, will the host files in ${EVE_ROOT}/pkg/pillar replaced by the ones in the container?
If that's the case, I'm concerned that IDEs detecting disk changes might go haywire trying to reindex the directory structure that has been modified. Do you have any suggestions on how we could make this process more convenient for the developers?

Copy link
Contributor

@christoph-zededa christoph-zededa Nov 10, 2023

Choose a reason for hiding this comment

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

nothing will be replaced, it is just a bind-mount

Do you have any suggestions on how we could make this process more convenient for the developers?

Use a proper IDE? ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a fan of the "works for me" approach. I would prefer a solution suitable for more people...

Even with bind-mount - will it look like "replacing" the directory with that one from the container? I'm always confused with the order and priorities of these mounts...

Copy link
Contributor

Choose a reason for hiding this comment

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

It will replace it, but I guess the normal container image has nothing in /home/user/....

I'm not a fan of the "works for me" approach. I would prefer a solution suitable for more people...

Then we should perhaps start first with investigating which IDEs have that problem and where exactly they fail.

P.S.: just feel free to ignore this discussion - you already have the approval from me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, sure, I hope we can merge the current simple solution.
Let's just use this thread to discuss what could the better solution look like.

So you say you mount ${HOST_EVE_ROOT}/pkg/pillar into ${HOST_EVE_ROOT}/pkg/pillar inside the container, right? In this case, you have 2 copies of source code in the container: 1 - /pillar/ - preprocessed code with the patches applied, 2 - ${HOST_EVE_ROOT}. Right? But in this case, if you change a file on your host - it will be visible only in the second path. So, the patched files are still invisible from the host and the tools/IDEs running there. Right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I normally do it from the eve directory, not pkg/pillar, but the consequences are the same, that I have the code twice in the container.
Yes, it will be only visible in the second path.
Yes, the patched files are invisible from the host and therefore also invisible for the IDEs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, sure, I hope we can merge the current simple solution.

Fine from my side.

@christoph-zededa
Copy link
Contributor

I delegate the review to @christoph-zededa. He is the docker-pocker expert.

LGTM

@@ -76,6 +76,12 @@ build-docker-$(APPS): $(DISTDIR)
build-docker:
docker build $(DOCKER_ARGS) -t $(DOCKER_TAG) .

build-docker-dev:
docker build $(DOCKER_ARGS) -t $(DOCKER_TAG) . --target build
Copy link
Contributor

Choose a reason for hiding this comment

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

@OhmSpectator , I liked these targets, but unfortunately, they don't consider architecture, as the whole Makefile. In a nutshell, I cannot run enter-docker-dev for ARM.... You don't need to add it in this PR, but it would be good to have architecture support in the future, maybe we could create an issue/ticket for that...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm... Good point. And just a question of curiosity, how do you make ARCH-specific steps for building Pillar now? Is there anything build-time specific in general?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's handled inside the Dockerfile to setup corresponding GO variables and cross-compilers (when needed): https://github.com/lf-edge/eve/blob/master/pkg/pillar/Dockerfile#L86

Copy link
Member Author

Choose a reason for hiding this comment

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

So, the problem is that TARGETARCH is not set from Makefile, yeah?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes for go build ... commands, but in case of docker commands, it should be platform, like: --platform linux/arm64

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the only remaining comment before this can be merged.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I tried to devise a quick fix, but it did not work as expected. I'll come up with another solution and push it here. Meanwhile, switching the PR into Draft.

Copy link
Member Author

Choose a reason for hiding this comment

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

@eriknordmark, as the new targets are not the only ones that lack multi-arch support, I would prefer to address this issue in the scope of a dedicated task, not blocking the PR. I'll create a ticket for that shortly.

@OhmSpectator OhmSpectator marked this pull request as draft November 14, 2023 09:27
@OhmSpectator OhmSpectator changed the title In Pillar, add new Makefile targets for Docker dev builds and shell access. [WIP] In Pillar, add new Makefile targets for Docker dev builds and shell access. Nov 14, 2023
@OhmSpectator OhmSpectator changed the title [WIP] In Pillar, add new Makefile targets for Docker dev builds and shell access. In Pillar, add new Makefile targets for Docker dev builds and shell access. Nov 17, 2023
@OhmSpectator OhmSpectator marked this pull request as ready for review November 17, 2023 10:33
@eriknordmark eriknordmark requested a review from rene November 17, 2023 17:25
Copy link
Contributor

@eriknordmark eriknordmark left a comment

Choose a reason for hiding this comment

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

LGTM but let's have @rene agree we can add arm64 support to the targets later.

@eriknordmark eriknordmark merged commit ae407a8 into lf-edge:master Nov 20, 2023
71 of 84 checks passed
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.

5 participants