Skip to content

Commit

Permalink
container-example: Align build instructions to other examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pataxis committed May 21, 2024
1 parent d134bcb commit 82fa185
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 58 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/container-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
cd $EXNAME
docker pull --platform=${{ matrix.platformarch}} alpine:$alpinetag
docker save -o alpine.tar alpine:$alpinetag
docker build --no-cache --tag $imagetag --output build .
docker build --no-cache --tag $imagetag --build-arg ARCH=${{ matrix.arch }} .
docker cp $(docker create $imagetag):/opt/app ./build
cd ..
docker image rm -f $imagetag
6 changes: 1 addition & 5 deletions container-example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG VERSION=1.14
ARG UBUNTU_VERSION=22.04
ARG REPO=axisecp

FROM ${REPO}/acap-native-sdk:${VERSION}-${ARCH}-ubuntu${UBUNTU_VERSION} AS build
FROM ${REPO}/acap-native-sdk:${VERSION}-${ARCH}-ubuntu${UBUNTU_VERSION}
ARG ARCH
COPY ./* /opt/app/

Expand All @@ -16,7 +16,3 @@ RUN <<EOF
-a alpine.tar \
-a docker-compose.yml
EOF

FROM scratch AS binaries

COPY --from=build /opt/app/*.eap /
137 changes: 85 additions & 52 deletions container-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
The purpose of this example is to demonstrate a way of using containers in a native ACAP application.

The advantage of using a native ACAP application for this, as opposed to a Computer Vision ACAP application,
is that the application can be administered via the VAPIX API and the web GUI in Axis OS. It also has
is that the application can be administered via the VAPIX API and the web GUI in AXIS OS. It also has
the advantage that the container images can be included in the .eap application file so that the entire
application is contained in this single, installable file, without any dependency on external image repositories.

Expand Down Expand Up @@ -39,84 +39,118 @@ to port 8080 on the device.

## Prerequisites

- An Axis device with edge container functionality.
- Axis OS 11.10 or later.
- The [Docker Compose ACAP][docker-compose-acap] version 3.0 or later, installed and running on the device.

## Build and extract the application for armv7hf

Navigate to the root directory of this repository and then start with setting environment variables:
- An Axis device with [container support](https://www.axis.com/support/tools/product-selector/shared/%5B%7B%22index%22%3A%5B4%2C2%5D%2C%22value%22%3A%22Yes%22%7D%5D), see more info in [Axis devices and compatibility](https://axiscommunications.github.io/acap-documentation/docs/axis-devices-and-compatibility/#acap-computer-vision-sdk-hardware-compatibility).
- AXIS OS 11.10 or later.
- The [Docker Compose ACAP][docker-compose-acap] version 3.0 or later,
installed and running on the device.
- In the settings of the application:
- `IPCSocket` must be set to `yes`.
- `TCPSocket` can be set to `no` since this example does not connect to the
Docker Daemon from outside of the device.
- However, if you do want to run with TCP Socket, TLS should be used
(`UseTLS` set to `yes`). In that case, follow the instructions in the
[Docker Compose ACAP][docker-compose-acap] for how to generate and
upload TLS certificates to the device.
- For the other settings refer to the documentation in that repo.

## Getting started

These instructions will guide you on how to execute the code. Below is the
structure and scripts used in the example:

```sh
export ARCH="armv7hf"
export PLATFORM="linux/arm/v7"
container-example
├── containerExample
├── docker-compose.yml
├── Dockerfile
├── LICENSE
├── Makefile
├── manifest.json
├── postinstall.sh
├── preuninstall.sh
└── README.md
```

Next, pull the [Alpine linux container image][alpine] for armv7hf and save it to a .tar file:
- **containerExample** - Application source code in shell script.
- **docker-compose.yml** - Docker compose file to start a container on the device.
- **Dockerfile** - Docker file with the specified Axis toolchain and API container to build the example specified.
- **LICENSE** - Text file which lists all open source licensed source code distributed with the application.
- **Makefile** - Makefile containing the build and link instructions for building the ACAP application.
- **manifest.json** - Defines the application and its configuration. This includes additional parameters.
- **postinstall.sh** - Post-install script, running at end of an application installation.
- **preuninstall.sh** - Pre-uninstall script, running before an application uninstallion.
- **README.md** - Step by step instructions on how to run the example.

```sh
docker pull --platform=$PLATFORM alpine:3.19.1
docker save -o alpine.tar alpine:3.19.1
```
### How to run the code

Finally build the application and extract the .eap file:
Below is the step by step instructions on how to execute the program. So
basically starting with the generation of the .eap file to running it on a
device.

```sh
docker buildx build --build-arg ARCH=$ARCH --output build-$ARCH .
```
#### Build the application

The .eap file can now be found in the `build-armv7hf` folder.
Standing in your working directory run the following commands:

## Build and extract the application for aarch64
> [!NOTE]
>
> Depending on the network you are connected to, you may need to add proxy settings.
> The file that needs these settings is: `~/.docker/config.json`. For reference please see
> https://docs.docker.com/network/proxy and a
> [script for Axis devices](https://axiscommunications.github.io/acap-documentation/docs/develop/build-install-run.html#configure-network-proxy-settings) in the ACAP documentation.
Navigate to the root directory of this repository and then start with setting environment variables:
##### Build the application for armv7hf

```sh
export ARCH="aarch64"
export PLATFORM="linux/arm64/v8"
```

Next, pull the [Alpine linux container image][alpine] for aarch64 and save it to a .tar file:
Pull the [Alpine linux container image][alpine] for armv7hf and save it to a
.tar file, then build the application:

```sh
docker pull --platform=$PLATFORM alpine:3.19.1
docker pull --platform="linux/arm/v7" alpine:3.19.1
docker save -o alpine.tar alpine:3.19.1
docker build --build-arg ARCH=armv7hf --tag container-example:armv7hf .
docker cp $(docker create container-example:armv7hf):/opt/app ./build-armv7hf
```

Finally build the application and extract the .eap file:
##### Build the application for aarch64

Pull the [Alpine linux container image][alpine] for aarch64 and save it to a
.tar file, then build the application:

```sh
docker buildx build --build-arg ARCH=$ARCH --output build-$ARCH .
docker pull --platform="linux/arm64/v8" alpine:3.19.1
docker save -o alpine.tar alpine:3.19.1
docker build --build-arg ARCH=aarch64 --tag container-example:aarch64 .
docker cp $(docker create container-example:aarch64):/opt/app ./build-aarch64
```

The .eap file can now be found in the `build-aarch64` folder.
##### Extract the application

## Install the application
The `build-armv7hf` and `build-aarch64` directories contain the build
artifacts, where the ACAP application is found with suffix `.eap`, depending on
which SDK architecture that was chosen, one of these files should be found:

On your Axis device, navigate to `http://<axis_device_ip>/camera/index.html#/apps`, where <axis-device-ip>
is the IP of your device. Make sure that the [Docker Compose ACAP][docker-compose-acap] application
is installed and running. In the settings of that application `IPCSocket` must be set to `yes`.
`TCPSocket` can be set to `no` since this example does not connect to the Docker Daemon from outside
of the device. However, if you do want to run with TCP Socket, TLS should be use (`UseTLS` set to `yes`).
In that case, follow the instructions in the [Docker Compose ACAP][docker-compose-acap] for how to
generate and upload TLS certificates to the device. For the other settings refer to the documentation
in that repo.
- `Container_Example_1_0_0_aarch64.eap`
- `Container_Example_1_0_0_armv7hf.eap`

Click on the `+Add app` button on the page and in the popup window that appears, select the .eap-file
that was built earlier.
#### Install your application

Alternatively, you can use `upload.cgi` in the [VAPIX Application API][VAPIX-application] to directly
upload the .eap-file from command line.
Browse to the application page of the Axis device:

## Run the application
```sh
http://<AXIS_DEVICE_IP>/#settings/apps
```

Start the application and then use a web browser to browse to
- Click on the tab `App` in the device GUI
- Click `(+)` sign to upload the application file
- Browse to the newly built ACAP application, depending on architecture:
- `Container_Example_1_0_0_aarch64.eap`
- `Container_Example_1_0_0_armv7hf.eap`
- Click `Install`
- Run the application by enabling the `Start` switch

```html
http://<axis_device_ip>:8080
```
#### The expected output

The page should display the text "Hello from an ACAP!"
Browse to `http://<AXIS_DEVICE_IP>:8080`, the page should display the text
**Hello from an ACAP!**.

## License

Expand All @@ -127,5 +161,4 @@ The page should display the text "Hello from an ACAP!"
[alpine]: https://hub.docker.com/_/alpine
[docker-compose-acap]: https://github.com/AxisCommunications/docker-compose-acap
[nc-man]: https://www.commandlinux.com/man-page/man1/nc.1.html
[VAPIX-application]: https://www.axis.com/vapix-library/subjects/T10102231/section/t10062344/display
<!-- markdownlint-enable MD034 -->

0 comments on commit 82fa185

Please sign in to comment.