Skip to content

Commit

Permalink
[#49457] server: Add server-device integration demo using RDFM client…
Browse files Browse the repository at this point in the history
… in Docker
  • Loading branch information
lkedziora authored and mleonowicz committed Sep 13, 2024
1 parent c2d5e22 commit 0e0ecf5
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
9 changes: 9 additions & 0 deletions devices/linux-client/Dockerfile.demo-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM antmicro/rdfm-client-builder:latest

# Copy all sources
COPY . /rdfm-client/
WORKDIR /rdfm-client/
# Install the RDFM client
RUN make install

CMD [ "/rdfm-client/scripts/test-docker/docker-entrypoint.sh" ]
11 changes: 11 additions & 0 deletions devices/linux-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ VERSION = $(shell git describe --tags --dirty --exact-match 2>/dev/null || git r
GO_LDFLAGS = \
-ldflags "-X github.com/antmicro/rdfm/conf.Version=$(VERSION)"

BUILDER_IMAGE_TAG = antmicro/rdfm-client-builder:latest
DEMO_CLIENT_TAG = antmicro/rdfm-linux-demo-client:latest

ifeq ($(V),1)
BUILDV = -v
endif
Expand All @@ -42,6 +45,12 @@ build:

rdfm: build

docker-builder:
docker build -f Dockerfile -t $(BUILDER_IMAGE_TAG) .

docker-demo-client: docker-builder
docker build -f Dockerfile.demo-client -t $(DEMO_CLIENT_TAG) .

install: install-bin \
install-conf

Expand Down Expand Up @@ -72,6 +81,8 @@ test:
$(GO) test $(BUILDV) $(PKGS)

.PHONY: build
.PHONY: docker-builder
.PHONY: docker-demo-client
.PHONY: clean
.PHONY: test
.PHONY: install
Expand Down
22 changes: 22 additions & 0 deletions devices/linux-client/docker-compose.demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'

services:
demo-client:
image: antmicro/rdfm-linux-demo-client:latest
network_mode: host
restart: unless-stopped
environment:
# Device type reported to the server
RDFM_CLIENT_DEVTYPE: x86_64
# Example: plain HTTP server connection
RDFM_CLIENT_SERVER_URL: http://127.0.0.1:5000/
# Example: HTTPS server connection
# Remember to update the URL to use HTTPS!
# RDFM_CLIENT_SERVER_URL: https://127.0.0.1:5000/
# RDFM_CLIENT_SERVER_CERT: /var/lib/rdfm/CA.crt
volumes:
# Simulate a persistent "partition" for the configuration
- data:/var/lib/rdfm/

volumes:
data:
42 changes: 42 additions & 0 deletions devices/linux-client/scripts/test-docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
set -e

# This is the entrypoint for the Dockerized demo client
# This can be used to test basic integration with the RDFM server

# Environment variable overrides
SERVER_URL="${RDFM_CLIENT_SERVER_URL:-http://127.0.0.1:5000/}"
SERVER_CERT="${RDFM_CLIENT_SERVER_CERT:-/dev/zero}"
PART_A="${RDFM_CLIENT_PART_A:-/dev/zero}"
PART_B="${RDFM_CLIENT_PART_B:-/dev/zero}"
DEVICE_TYPE="${RDFM_CLIENT_DEVTYPE:-x86_64}"

# Generate a valid configuration
cat >/etc/rdfm/artifact_info << EOF
artifact_name=unknown
EOF

cat >/var/lib/rdfm/device_type << EOF
device_type=${DEVICE_TYPE}
EOF

cat >/etc/rdfm/rdfm.conf << EOF
{
"RootfsPartA": "${PART_A}",
"RootfsPartB": "${PART_B}"
}
EOF

cat >/var/lib/rdfm/rdfm.conf <<EOF
{
"ServerURL": "${SERVER_URL}",
"ServerCertificate": "${SERVER_CERT}"
}
EOF

# Creating an entry in /etc/hosts for the server
IP=$(echo $SERVER_URL | awk -F"://|:" '{print $2}')
echo "$IP rdfm-server" >> /etc/hosts

# Start daemonized RDFM device client
exec rdfm daemonize ${CLIENT_ARGS}
26 changes: 26 additions & 0 deletions documentation/source/rdfm_linux_device_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ cd data/devices/linux-client
make
```

## Testing server-device integration with a demo Linux device client

For development purposes, it's often necessary to test server integration with an existing device client.
To do this, it is possible to use the [RDFM Linux device client](rdfm_linux_device_client.md), without having to build a compatible system image utilizing the Yocto [meta-rdfm layer](https://github.com/antmicro/meta-antmicro/tree/master/meta-rdfm).
First, build the demo container image:

```
cd devices/linux-client/
make docker-demo-client
```

You can then start a demo Linux client by running the following:
```
docker-compose -f docker-compose.demo.yml up
```

If required, the following environment variables can be changed in the above `docker-compose.demo.yml` file:

- `RDFM_CLIENT_SERVER_URL` - URL to the RDFM Management Server, defaults to `http://127.0.0.1:5000/`.
- `RDFM_CLIENT_SERVER_CERT` **(optional)** - path (within the container) to the CA certificate to use for verification of the connection to the RDFM server. When this variable is set, the server URL must also be updated to use HTTPS instead of HTTP.
- `RDFM_CLIENT_DEVTYPE` - device type that will be advertised to the RDFM server; used for determining package compatibility, defaults to `x86_64`.
- `RDFM_CLIENT_PART_A`, `RDFM_CLIENT_PART_B` **(optional)** - specifies path (within the container) to the rootfs A/B partitions that updates will be installed to. They do not need to be specified for basic integration testing; any updates that are installed will go to `/dev/zero` by default.

The demo client will automatically connect to the specified RDFM server and fetch any available packages.
To manage the device and update deployment, you can use the [RDFM Manager utility](rdfm_manager.md).

## Developer Guide

### Running tests
Expand Down

0 comments on commit 0e0ecf5

Please sign in to comment.