Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Add the sub-image information to the child level of the services key. This is already written in the sample app, so we will explain the contents here.

  • The complete description of the web service is as follows:

    image-20240909-101606.png

  • images:
    Here you specify the image name and tag created in 3.2. If the image specified here does not exist, the app build script will fail.

  • networks:
    If you want containers to communicate with each other, they must specify the same network.

  • restart:
    Specifies how to recover when the container is terminated. In the case of ext format Docker, the main container is monitored by the camera firmware without using Docker mechanisms, so specifying "no" will restart it appropriately. On the other hand, subcontainers are not monitored by the camera firmware, so set it according to the actual operation.

  • ports:
    If the sub-image exposes a port that can be connected from outside, describe it in the format of [camera side]:[container side].

  • volumes:
    Describes volumes and bind mounts.
    Only volumes defined in this docker-compose.yaml can be specified for volume. In addition, volume names defined here must also be separately listed in the volumes: section at the top of the yaml file.
    There are restrictions on directory paths that can be bind mounted.

  • tmpfs:
    Security policies prevent writing to containers, so if there are directories under /var where apps temporarily store data, specify them here.
    In the case of nginx, it writes to /var/cache/nginx and /var/run, so these are specified as tmpfs.

  • Required parameters
    The following parameters must be added to satisfy the security policy of the i-RPO camera. Please copy and paste as is.

    Code Block
        read_only: true
        user:
          1000:1000
        cap_drop:
          - "net_raw"
        security_opt:
          - "label=type:ipro-container.process"
          - "no-new-privileges"
        labels:
          com.i-pro.app-type: "ext"
          com.i-pro.device-category: "CV5x-A"
          com.i-pro.device-vendor: "i-PRO"
  • Listing root-level volumes
    Enter the volume name in the volumes: section under the root of the yaml file.

    image-20240801-032019.png

3.4

...

Implementing your own functionality

3.4.1

...

メインイメージ・サブイメージ間や、コンテナとカメラ間でデータをやり取りするには以下の方法があります。

...

volumeを使用する。
docker-compose.yamlに記載することでvolumeをコンテナ間で共有することができますのでこの中でデータをやり取りできます。ただしこの領域はFlashROM上となり、寿命に影響がありますので大量なデータのやり取りには向きません。

共有が許可されているtmpfsを使用する。
ADAM_GetTmpDirPath() APIで取得できる領域はtmpfs上にあり、一時的なデータ保存用として利用できます。
サブコンテナからこの領域にアクセスするためには、docker-compose.yamlのサブイメージの記述内のvolumes: に以下を追加します。

...

Communication and data sharing between containers

There are the following methods to exchange data between the main image and sub-image, or between a container and a camera.

  • Use volume.
    By writing this in docker-compose.yaml, you can share volumes between containers, so you can exchange data within them. However, this area is on FlashROM, and it affects the lifespan, so it is not suitable for exchanging large amounts of data.

  • Use a tmpfs that allows sharing.
    The area obtained with the ADAM_GetTmpDirPath() API is on tmpfs and can be used to store temporary data.
    To access this area from a subcontainer, add the following to volumes: in the subimage description in docker-compose.yaml.

    Code Block
          - type: bind
            target: "/dev/shm/Adamapp"
            source: "/dev/shm/Adamapp"
            read_only: false
            consistency: default

    ただし、サブコンテナからはADAM_GetTmpDirPath()を呼ぶことができませんので、別途volumeを使う方法などでメインコンテナからパスを通知する必要があります。

  • HTTP経由で取得する。
    Dockerでは各コンテナに仮想のIPアドレスが割り当てられるため、こちらを利用して、カメラ外と同様にWebAPIを呼ぶことができます。また、docker-compose.yamlのhostnameキーでドメイン名を指定すると、この名前で通信を行うこともできます。
    メインコンテナでは、ADAMの仕組みとして、sendDataToAdamApplication WEB APIを使用して通信を行うことができます。この仕組みはカメラ本体がメインコンテナにデータを仲介する方法ですので、あて先はカメラ本体のIPアドレスとなります。
    また、同様にカメラのCGIを利用してカメラ本体の設定値などを取得することができます。

Info

コンテナ内から仮想環境上のカメラ本体のIPアドレスはコンテナ内から/etc/hostsを参照し、一番最後のエントリの最下位バイトを1にしたものとなります。

WebAPIでアクセスする際、カメラのユーザー名・パスワードの指定が必要です。

3.4.2 サンプルアプリの実装例

...

  • However, since ADAM_GetTmpDirPath() cannot be called from a subcontainer, you must notify the path from the main container using a separate volume, etc.

  • Retrieved via HTTP.
    In Docker, each container is assigned a virtual IP address, which can be used to call the WebAPI in the same way as outside the camera. Also, if you specify a domain name in the hostname key of docker-compose.yaml, you can communicate using this name.
    In the main container, communication can be performed using the sendDataToAdamApplication WEB API as an ADAM mechanism. This mechanism is a method in which the camera body mediates data to the main container, so the destination is the IP address of the camera body.
    Similarly, you can use the camera's CGI to obtain the camera's settings and other information.

Info

The IP address of the camera in the virtual environment can be found from within the container by referencing /etc/hosts from within the container and setting the least significant byte of the last entry to 1.

When accessing via WebAPI, you must specify the camera's user name and password.

3.4.2 Example implementation of sample app

The docker_multi_images sample app uses the DNS function of the inter-container network to implement sample code that sends an HTTP request from the main container to a sub-container by container name.
The response_by_html function in ${SDK_DIR}/adamapp/docker_multi_images/main.cpp の response_by_html関数内で以下の様にcurlでリクエストを行うsystem関数を呼び出しています。 ここで “web” はdocker-compose.yamlに記載されているサービス名となります。calls the system function that makes a request with curl as follows. Here, “web” is the service name written in docker-compose.yaml.

Code Block
	char cmd[256];

	snprintf( cmd, 256, "curl http://web/index.html > /tmp/local/index.html");
	if( system(cmd) != 0 ) {
		ADAM_DEBUG_PRINT(ADAM_LV_ERR, "system error (%s)\n", cmd);
	}

カメラブラウザの「ソフトウェア管理画面」に表示された、「Dockerマルチイメージ」アプリの「設定画面へ」ボタンを押下することで、このコードが呼び出され、webコンテナのindex.htmlの内容をそのままブラウザに表示します。By pressing the "Go to Settings Screen" button for the "Docker Multi-Image" app displayed on the "Software Management Screen" of the camera browser, this code will be called and the contents of index.html of the web container will be displayed directly in the browser.

3.5

...

開発環境構築については下記を参照ください。

...

Building the app

Please refer to the following for information on building a development environment.

Construct a development environment(Container AdamApp) - Technology Partner FAQ (En) - Confluence (atlassian.net)

アプリ開発方法やビルドについては下記を参照ください。

開発方法(how develop編Please see below for information on how to develop and build apps.

How to develop(Container AdamApp) - Technology Partner FAQ (En) - Confluence (atlassian.net)