Docker image problem on Bitbucket

Hi devzone,

I'm working on the nRF54L05, having an application and the mcuboot generated correctly on my host computer.
Now we want to generate the binaries on Bitbucket pipelines. I tried to follow the "nRF Connect SDK toolchain Docker image" section (docs.nordicsemi.com/.../README.html), first locally on my computer and then on Bitbucket.

LOCALLY:
Using the command proposed on the guide I was getting the same error all the time, and the container was never created:

docker run -ti ghcr.io/nrfconnect/sdk-nrf-toolchain:v3.0.2 -v /dev:/dev --privileged -e ACCEPT_JLINK_LICENSE=1 bash
Error:
--privileged: line 1: /dev:/dev: No such file or directory

After some investigation I found the command was wrong. Maybe an experimented docker user can find the error fast but for me, without much docker experience, it was difficult to see. This is only a suggestion to fix this typo.

Right command:
docker run -ti -v /dev:/dev --privileged -e ACCEPT_JLINK_LICENSE=1 ghcr.io/nrfconnect/sdk-nrf-toolchain:v3.0.2 bash


Now the docker container is running and I can see:
root@e59e2b371140:~# west --version
West version: v1.2.0


But executing "echo $ZEPHYR_BASE" I don't have any output. I think that's why I cannot build my application either (previously mounted to /home).
root@d19f76caefd7:/home# west build -b nrf54l15dk/nrf54l05/cpuapp -p always
usage: west [-h] [-z ZEPHYR_BASE] [-v] [-V] <command> ...
west: unknown command "build"; do you need to run this inside a workspace?
root@d19f76caefd7:/home# west update
FATAL ERROR: no west workspace found from "/home"; "west update" requires one.
Things to try:
  - Change directory to somewhere inside a west workspace and retry.
  - Set ZEPHYR_BASE to a zephyr repository path in a west workspace.
  - Run "west init" to set up a workspace here.
  - Run "west init -h" for additional information.


Question 1. How can I build my application locally using this docker image? I'm sure I'm missing something.

IN CI:
My bitbucket-pipeliens.yml is:

image: ghcr.io/nrfconnect/sdk-nrf-toolchain:v3.0.2
pipelines:
  default:
    - step:
        name: Build
        script:
          - export ACCEPT_JLINK_LICENSE=1
          - west update
          - echo "Running west --version in the container"
          - west --version


This method is not working because the pipeline is blocked printing: input. Please use y/n
This means the "export ACCEPT_JLINK_LICENSE=1" is not working. I tried adding the ACCEPT_JLINK_LICENSE on the "Repository Settings->Pipelines->Repository variables" and "- echo 'y' | west update" but the result is the same.

Question2. How can I use this docker image on bitbucket pipeline?

Thanks in advance.

Parents
  • Hi,

    After some investigation I found the command was wrong. Maybe an experimented docker user can find the error fast but for me, without much docker experience, it was difficult to see. This is only a suggestion to fix this typo.

    Sorry, It indeed looks like we did a typo there. The right docker command should be :

    docker run -ti -v /dev:/dev -v /run/udev:/run/udev:ro --privileged -e ACCEPT_JLINK_LICENSE=1 ghcr.io/nrfconnect/sdk-nrf-toolchain:<TAG> bash

    But executing "echo $ZEPHYR_BASE" I don't have any output. I think that's why I cannot build my application either (previously mounted to /home).

    What application type are you using ? If you are using a freestanding application, you will have to input "ZEPHYR_BASE" manually or via a script. The recommended application type is the workspace application. It has a more complicated structure, but is better to work with for big projects and CI.

    Question 1. How can I build my application locally using this docker image? I'm sure I'm missing something.

    If you have a freestanding application (which I suppose you have), you have to give access or install your wanted SDK in the docker. After that you can set your "ZEPHYR_BASE" environment variable to point to your SDK and after that you should be able to build your project.

    If you have a workspace application, you just have to go to your application folder, and you should be able to build it directly.

    Question2. How can I use this docker image on bitbucket pipeline?

    I will let one of my colleague comment on that, as I am not really knowledgeable with Bitbucket.

    Best regards,

    Simon D-M

Reply
  • Hi,

    After some investigation I found the command was wrong. Maybe an experimented docker user can find the error fast but for me, without much docker experience, it was difficult to see. This is only a suggestion to fix this typo.

    Sorry, It indeed looks like we did a typo there. The right docker command should be :

    docker run -ti -v /dev:/dev -v /run/udev:/run/udev:ro --privileged -e ACCEPT_JLINK_LICENSE=1 ghcr.io/nrfconnect/sdk-nrf-toolchain:<TAG> bash

    But executing "echo $ZEPHYR_BASE" I don't have any output. I think that's why I cannot build my application either (previously mounted to /home).

    What application type are you using ? If you are using a freestanding application, you will have to input "ZEPHYR_BASE" manually or via a script. The recommended application type is the workspace application. It has a more complicated structure, but is better to work with for big projects and CI.

    Question 1. How can I build my application locally using this docker image? I'm sure I'm missing something.

    If you have a freestanding application (which I suppose you have), you have to give access or install your wanted SDK in the docker. After that you can set your "ZEPHYR_BASE" environment variable to point to your SDK and after that you should be able to build your project.

    If you have a workspace application, you just have to go to your application folder, and you should be able to build it directly.

    Question2. How can I use this docker image on bitbucket pipeline?

    I will let one of my colleague comment on that, as I am not really knowledgeable with Bitbucket.

    Best regards,

    Simon D-M

Children
  • Hi, I'm sorry for the late response. I had to work on other things.

    For now, we would consider as the last option to change our freestanding application to a workspace one.

    What do you mean with "give access or install your wanted SDK"? the SDK comes pre-installed with the docker image when we select the <TAG> option, isn't it?

    Where to point the "ZEPHYR_BASE" variable once running the docker image? I cound't find a folder structure like "ncs/zephyr". 

  • Hi,

    Gerardo Valdovinos said:
    What do you mean with "give access or install your wanted SDK"? the SDK comes pre-installed with the docker image when we select the <TAG> option, isn't it?

    No, the SDK is not installed when the docker is built. Only the toolchain and some other utilities are installed. It is done that way because when you are making a "workspace application" the SDK is bundled with the application when you pull it. So no need to have a pre-installed SDK, it will only make the Docker heavier for no reason. The docker is used to set up the environment in which the project is built.

    If you are not familiar with "workspace application" I would recommend trying to build one of our application that uses such an application type. You can try to build the "Asset Tracker Template" or the "Serial Modem Add-on". I believe that seeing how the one of these "workspace applications" is structured might help you understand what is happening.

    Gerardo Valdovinos said:
    Where to point the "ZEPHYR_BASE" variable once running the docker image? I cound't find a folder structure like "ncs/zephyr". 

    In a workspace application, you shouldn't need to set this variable. It should be automatically detected when using west.

    Tell me if that was helpful!

    Best regards,

    Simon D-M

  • Hi, sorry again for my late response

    I was able to create a workspace app and, locally, the docker image was able to build it, after updating the west workspace (west update).

    Now I have the same problem as before. I cannot make Bitbucket to run the docker image because of the ACCEPT_JLINK_LICENSE variable. Please let me know if your colleagues know how to run this image on Bitbucket pipelines.

    I was thinking on another option, customize zephyr installation to create a new small docker image. Does Nordic have information on how to customize zephyr for building only the nRF54L05? I think I need to modify the west.yml but not sure what to add and remove.

  • Hi,

    Gerardo Valdovinos said:
    Now I have the same problem as before. I cannot make Bitbucket to run the docker image because of the ACCEPT_JLINK_LICENSE variable. Please let me know if your colleagues know how to run this image on Bitbucket pipelines.

    After a bit of searching on the internet, it looks like when you put "export ACCEPT_JLINK_LICENSE=1" as a script, it invokes it after the container start. What you need to do is to actually add it to your "Repository Variables" (Repository Settings -> Pipelines -> Repository Variables). That way, the container should inherit the environment variable and skip the JLink accept dialog.

    Gerardo Valdovinos said:
    I was thinking on another option, customize zephyr installation to create a new small docker image. Does Nordic have information on how to customize zephyr for building only the nRF54L05? I think I need to modify the west.yml but not sure what to add and remove.

    There isn't really a way to customize for a specific chip. However, there are some ways to make it smaller. The easiest way to reduce the size of it is to limit the depth of "west update". Instead of pulling full git history for every repository it will only pull the latest commits. To limit the depth, you can use the following command:

    west update --depth 1 --narrow

    Now, you can also shave off quite a bit of size by cherry-picking which repository you want to pull with the west.yml. This method is probably the one that gives to most control, but it requires to already be quite familiar with west / Zephyr / NCS. I can't really recommend you to go into that as it might not be worth the effort.

    If you still want to try playing with west.yml, feel free to reach out again for help. But before trying to optimize anything. Please make sure that the basic setup works.

    Best regards,

    Simon D-M

Related