Correct usage of targetfiles and how to navigate to the right folder?

Colibri iMX6 512MB IT
Colibri Evaluation Board
Visual Studio Code (VS Code) Toradex Torizon Support

I want to copy over some config files to my target.
I know I must use the toradex Torizon Support Extension and go under Configurations to add my files to the targetfiles setting.

The command in targetfiles seems like it should be of the form:
COPY source dest

But where should I place my source files? what is the working directory?
Is the working directory a folder in Windows, or in the development environment container?

One I figure out where to put these files, how should I best move my (windows) files there?
Will these files be still under version control using git? i.e. is there a way to COPY from my source controlled folder?

I would also like to chmod one of these files (a script) to be executable…
Another file is a service that I intend to run using the command:

sudo sytemctl enable Myservice.service

How will i use the password to invoke this command? Is this even possible?

I have been also recommended to use a docker-compose file. Maybe this would be the right approach, but for now lets handle this method first, since I think it can get me up and running faster.

Thanks

Hi @leighjboyd ,

Regarding targetfiles you can place the COPY source file/directory in <path-to-your-vscode-project>/appconfig_0/.

Keep in mind the source files will be copied to the container that will be deployed, not directly to the module filesystem.

If you want to have version control in your source files you should put the version controlled directory inside <path-to-your-vscode-project>/appconfig_0/.
For instance, suppose you have a git enabled folder named git_dir, which has all your version controlled files. This directory path is <path-to-your-vscode-project>/appconfig_0/git_dir/.

To copy the files to your container targetfiles should have the following value:

  • If copying only one file: COPY git_dir/<file name> <container destination>;
  • If copying all files: COPY git_dir <container destination>.

About running a script, where do you want to execute it? Inside the container or on TorizonCore directly?

If running directly you can run a script on startup by putting a script in <path-to-your-vscode-project>/appconfig_0/ and put the script name as value in the startupscript field. In this case you don’t need to chmod the script.

I assume you want to run the systemctl enable command on TorizonCore, as containers don’t usually have systemd installed. If you really need to run commands with sudo in a script this page has some methods to do it: shell - sudo with password in one command line? - Super User. I’d advise caution as your sudo password can be exposed.

Let me know if this answers your questions.

Best regards,
Lucas Akira

Keep in mind the source files will be copied to the container that will be deployed, not directly to the module filesystem.

Okay, how would I get them into the module filesystem then? I figured if the particular folder was mounted (in my case under home/torizon/config) then it should be automatically in the module as well, no? Maybe I am going about this all wrong and should just learn about the docker-compose file method… but it seems like my version control is better suited to managing my files if they are located here in appconfig_0 as you say. ( I may change the way config files are formatted, then then it will be hard to manage different config file formats with different code versions)

I can see that the targetfiles command was not returning an error anymore, and generated my COPY command, but I still didn’t see the file in my file system, as you said…

FROM --platform=linux/arm torizon/debian:2-bullseye

# GDB-remote (we can use any port there)
EXPOSE 6502

ARG SSHUSERNAME=root

# Make sure we don't get notifications we can't answer during building.
ENV DEBIAN_FRONTEND="noninteractive"

# commands that should be run before installing packages (ex: to add a feed or keys)

# your regular RUN statements here
# Install required packages
RUN apt-get -q -y update \
    && apt-get -q -y install \
    gdbserver \
    procps \
    && rm -rf /var/lib/apt/lists/*

RUN if [ ! -z "iproute2 can-utils python3-can python3-pexpect libgpiod2" ]; then \
    apt-get -q -y update \
    && apt-get -q -y install iproute2 can-utils python3-can python3-pexpect libgpiod2 \
    && rm -rf /var/lib/apt/lists/* ; \
    fi

RUN usermod -a -G gpio,dialout torizon

COPY config.csv /home/torizon/config/config.csv

USER root

WORKDIR /EmeraBlockEnergyBox

CMD stdbuf -oL -eL gdbserver 0.0.0.0:6502 /EmeraBlockEnergyBox/EmeraBlockEnergyBox

I also checked the container’s own filesystem:

colibri-imx6-10866289:~/config$ docker ps
CONTAINER ID        IMAGE                                                                                             COMMAND                  CREATED             STATUS              PORTS               NAMES
dd6952e67d5e        emerablockenergybox_arm32v7-debian-no-ssh_bullseye_release_69ac5093-51e4-4f03-8827-ec9f9390dfe3   "/bin/sh -c /EmeraBl…"   4 days ago          Up 4 days                               inspiring_franklin

colibri-imx6-10866289:~/config$ docker run --privileged --rm -it -v /var/run/dbus:/var/run/dbus -v /dev:/dev emerablockenergybox_arm32v7-debian-no-ssh_bullseye_release_69ac5093-51e4-4f03-8827-ec9f9390dfe3 bash

root@8267fc1ca157:/# ls
EmeraBlockEnergyBox  bin  boot  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@8267fc1ca157:/# cd home
root@8267fc1ca157:/home# cd torizon
root@8267fc1ca157:/home/torizon# ls
root@8267fc1ca157:/home/torizon#

Although, to be honest, I am not sure if I am even in the right container…

BTW, How would I COPY multiple files with this approach? Can I chain commands together with && like in Linux?

Okay, how would I get them into the module filesystem then? I figured if the particular folder was mounted (in my case under home/torizon/config) then it should be automatically in the module as well, no?

If you mount a particular folder from the module, all its contents will be accessible in the container. But the Dockerfile COPY command doesn’t mount files, it copies them to your container image.

If you want the files in the module filesystem you can run scp <file> torizon@<module-local-ip>:/dest/path on your host PC terminal.

About you not finding your config file in the container: Are you rebuilding and redeploying the release container to the module? The generated Dockefile you showed is the debug one, whereas you tried to run the release container.

I just tested here with a sample project and I was able to see my copied file inside the container.

BTW, How would I COPY multiple files with this approach?

You would do like this: COPY config_dir /home/torizon/config/, where config_dir is a directory. According to Docker documentation, config_dir itself won’t be copied to the container, but all of its contents will.

Try doing the above and see if it helps you.

Best regards,
Lucas Akira

Thanks for pointing out the difference between release and debug. I didn’t spot that.

As for multiple files, your solution is good if all of the files I want to copy are config files, and all going to the same ~/config folder, but what about other files, in other folders?

I am namely trying to set up a script called Autostartup.sh which in turn tries to call
systemctl enable Autostartup.service

Also, I seem to not be understanding a basic thing:
when I update the configuration in the Torizon Extension tab,
when will the changes be evident in the dockerfile.release or dockerfile.debug.
I get that I need to press:

F1: build release container for the application, followed by
F1: torizon deploy release container
which will automatically update the appconfig_0/work/dockerfile.release file

but how about the dockerfile.debug file? how/when is that updated?
will it not copy my files to the target?

As for multiple files, your solution is good if all of the files I want to copy are config files, and all going to the same ~/config folder, but what about other files, in other folders?

The only way to do that would be to use multiple COPY commands in a single config, which unfortunately it is not possible to do so with the extension. You can however put a COPY command in more than one config option, like preinstallcommands, buildcommands, buildfiles and targetfiles.

I am namely trying to set up a script called Autostartup.sh which in turn tries to call
systemctl enable Autostartup.service

Do you want to run systemctl inside the container? That probably won’t work, as it doesn’t have systemd installed. You can run Autostartup.sh on TorizonCore everytime before the container is started by passing it in the startupscript field of the extension.

Also, I seem to not be understanding a basic thing:
when I update the configuration in the Torizon Extension tab,
when will the changes be evident in the dockerfile.release or dockerfile.debug.
I get that I need to press:
F1: build release container for the application, followed by
F1: torizon deploy release container
which will automatically update the appconfig_0/work/dockerfile.release file
but how about the dockerfile.debug file? how/when is that updated?

The changes you made to the Extension configs will be reflected when you build and deploy each type of container. As you said when you build the release container that’s the one that will be updated. Likewise, if you do F1 -> Torizon: Build debug container or simply press F5 it’s the debug container that will change.

will it not copy my files to the target?

The files should be copied to the container if you changed the configs to do so. The container being debug or release shouldn’t affect this.

Best regards,
Lucas Akira

Okay, I see what I was doing wrong now…

I was trying to copy files from my pc dev env to the target, but not just to the target container filesystem but to a volume. This is because I wanted the file to stay after the container was destroyed.

Unfortunately, however, the COPY command occurs during deployment but the VOLUMES dont get created until after the container gets created, (regardless of what order the commands occur in in the dockerfile!)

So I needed to copy the files to a directory which already exists in the container (i.e. before any volumes are created), then copy these files to the right place at run time.

Trying to copy from PC directly to a VOLUME using dockerfile instructions alone is pretty much impossible since when the VOLUME is created, you can think of it like its writing over the containers files with whatever files were already in the host directory.

(Impossible for a newbie like me, but apparently there are some nifty ways to get around it by creating a temporary container just for this purpose… but this is left as an excercise to the reader :slight_smile: