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

Wrong SDK version read, when building binaries via docker image (IDFGH-11223) #12389

Closed
3 tasks done
bhuvanchandra opened this issue Oct 11, 2023 · 4 comments
Closed
3 tasks done
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@bhuvanchandra
Copy link

bhuvanchandra commented Oct 11, 2023

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.1.1

Operating System used.

Linux

How did you build your project?

using idf.py build from within esp-idf docker image

If you are using Windows, please specify command line type.

None

What is the expected behavior?

when using esp_get_idf_version expected version is "v5.1.1"

What is the actual behavior?

when using esp_get_idf_version expected version is "HEAD-HASH-NOTFOUND"

Steps to reproduce.

use esp-idf docker image for building the firmware binaries and call the esp_get_idf_version method.

Build or installation Logs.

No response

More Information.

When building the firmware binaries through the CI pipeline, the ESP-IDF version read via the API is incorrect. Instead of the expected "v5.1.1", it reads "HEAD-HASH-NOTFOUND". Upon verifying, the Docker image for the esp-idf doesn't explicitly check out to the release tag, which is necessary for the API to retrieve the correct version from the git tag.

I'm using this action, v5.1.1 docker tag.

@bhuvanchandra bhuvanchandra added the Type: Bug bugs in IDF label Oct 11, 2023
@bhuvanchandra bhuvanchandra changed the title Wrong SDK version read, when building binaries in CI pipeline Wrong SDK version read, when building binaries via docker image Oct 11, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 11, 2023
@github-actions github-actions bot changed the title Wrong SDK version read, when building binaries via docker image Wrong SDK version read, when building binaries via docker image (IDFGH-11223) Oct 11, 2023
@fhrbata
Copy link
Collaborator

fhrbata commented Oct 16, 2023

Hello @bhuvanchandra ,

I've tried using the v5.1.1 docker image locally and also with the esp-idf-ci-action, but I cannot reproduce the behavior you are describing. My testing repository for this can be found here. It's the hello_world example from esp-idf with dispatch action using esp-idf-ci-action. I've downloaded the artifacts from the dispatch workflow and flash them into esp32s3.

  1. Download the artifacts from https://github.com/fhrbata/hello_world/actions/runs/6532320139
  2. Flashed with esptool.py -b 460800 --before default_reset --after hard_reset --chip esp32s3 write_flash --flash_mode dio --flash_size 2MB --flash_freq 80m 0x0 bootloader/bootloader.bin 0x8000 partition_table/partition-table.bin 0x10000 hello_world.bin
  3. check with screen that the output contains expected version screen /dev/ttyUSB0 115200

The output is contains

> esp_idf_version: v5.1.1
Restarting in 6 seconds...

TBH I'm quite not sure how the ``HEAD-HASH-NOTFOUND can get there. IIUC esp_get_idf_version returns just IDF_VER, which is defined in cmake and added to each compilation unit. This can be seen in the `build/compile_commands.json` where you should see something like `-DIDF_VER=\"v5.1.1\"`.

If I'm reading the cmake's git_describe function right, the only case where the HEAD-HASH-NOTFOUND can end up in IDF_VER is

  1. The git describe fails here
  2. the HEAD does not exists in .git dir here

Are you using the stock docker image provided by espressif espressif/idf:v5.1.1 or you have some customizations? Maybe try to double check that the IDF_PATH is actually a git working tree. Maybe you are using just a copy without .git directory in your CI . I can reproduce this if I delete the .git directory, in which case the git-describe of course fails and IDF_VER contains HEAD-HASH-NOTFOUND.

Note the v5.1.1 tag does not have to checked out for git describe to work and IMHO this is not related to your problem.

HTH, but this doesn't seem like a bug in esp-idf, v5.1.1 docker image or the esp-idf-ci-action.

Thank you

@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development and removed Status: Opened Issue is new labels Oct 16, 2023
@bhuvanchandra
Copy link
Author

Hello @fhrbata, thanks for looking into the issue.

I tried again, and the problem appears to be related to permissions. With the default root user, I can see the IDF version correctly. However, when running the docker image as a non-root user, the git describe command fails with the error: "fatal: detected dubious ownership in the repository at /opt/esp/idf/."

In my workflow, I need to run the following command to access the binary artifacts.

docker run --rm -u "$(id -u):$(id -g)" -e CCACHE_DIR=/tmp/.ccache -v $PWD:/oks_robot_connect -w /fw_app/ espressif/idf:v5.1.1 idf.py build
  cd fw_app/build
  cat version.txt
  zip fw_app.zip \
  bootloader/bootloader.bin \
  partition_table/partition-table.bin \
    ota_data_initial.bin \
    fw_app.bin \
    fw_app.elf \
    flasher_args.json

This is necessary for committing and subsequently creating a PR. It's important for me to access these binaries as a standard user, not as root. I'll review and address the permission issues in my workflow.

@fhrbata
Copy link
Collaborator

fhrbata commented Oct 17, 2023

Hello @bhuvanchandra , maybe you can look into safe.directory git config option. I think setting it for your repo might help here. Thank you

@fhrbata
Copy link
Collaborator

fhrbata commented Oct 19, 2023

Thinking about this a little more, we could probably add the idf repo as a safe one in the Docker file after it's checked out.

git config --system --add safe.directory $IDF_PATH

I will prepare a fix for this.

@espressif-bot espressif-bot added Status: In Progress Work is in progress Status: Reviewing Issue is being reviewed and removed Status: Selected for Development Issue is selected for development Status: In Progress Work is in progress labels Oct 19, 2023
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable Resolution: Done Issue is done internally and removed Status: Reviewing Issue is being reviewed Resolution: NA Issue resolution is unavailable labels Nov 1, 2023
igrr pushed a commit that referenced this issue Nov 7, 2023
In our docker docs[1] we recommend to start docker as a non-root user. This has
a side effect, because the esp-idf repo in docker image is owned by
root. Git by default refuses even to parse a config file if the repo is
owned by other than current user. As a result the version detection in
cmake fails[2] and the app version is set to "HEAD-HASH-NOTFOUND".
This adds esp-idf repo to the system git config as a safe one.

[1] https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/
    tools/idf-docker-image.html#building-a-project-with-cmake
[2] #12389 (comment)

Closes #12389

Signed-off-by: Frantisek Hrbata <[email protected]>
espressif-bot pushed a commit that referenced this issue Nov 22, 2023
In our docker docs[1] we recommend to start docker as a non-root user. This has
a side effect, because the esp-idf repo in docker image is owned by
root. Git by default refuses even to parse a config file if the repo is
owned by other than current user. As a result the version detection in
cmake fails[2] and the app version is set to "HEAD-HASH-NOTFOUND".
This adds esp-idf repo to the system git config as a safe one.

[1] https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/
    tools/idf-docker-image.html#building-a-project-with-cmake
[2] #12389 (comment)

Closes #12389

Signed-off-by: Frantisek Hrbata <[email protected]>
movsb pushed a commit to movsb/esp-idf that referenced this issue Dec 1, 2023
In our docker docs[1] we recommend to start docker as a non-root user. This has
a side effect, because the esp-idf repo in docker image is owned by
root. Git by default refuses even to parse a config file if the repo is
owned by other than current user. As a result the version detection in
cmake fails[2] and the app version is set to "HEAD-HASH-NOTFOUND".
This adds esp-idf repo to the system git config as a safe one.

[1] https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/
    tools/idf-docker-image.html#building-a-project-with-cmake
[2] espressif#12389 (comment)

Closes espressif#12389

Signed-off-by: Frantisek Hrbata <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants