Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

my_package oci #75

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ Process 'python3' (process Id = 0xffff80000036cb10) launched.
Hello World!
```

5. Create `my_package` VxWorks 7 OCI container image

Follow the instructions [here](/examples/vxc/my_package/README.md)

## Legal Notices

All product names, logos, and brands are property of their respective owners. All company,
Expand Down
16 changes: 16 additions & 0 deletions examples/vxc/my_package/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM scratch

WORKDIR /lib

COPY rootfs/lib /lib

WORKDIR /usr

COPY rootfs/usr/bin /usr/bin

CMD ["/usr/bin/my_package"]

LABEL com.windriver.vxworks.rtp.rtpStackSize 0x10000000
LABEL com.windriver.vxworks.rtp.rtpPriority 50
LABEL com.windriver.vxworks.rtp.rtpOptions 0x80
LABEL com.windriver.vxworks.rtp.rtpTaskOption 0x1000000
85 changes: 85 additions & 0 deletions examples/vxc/my_package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Building VxWorks Container Image for `my_package` Example

This document provides a guide for creating a container image for the "my_package" example. This image is designed to run on VxWorks 7.

This container can be used in several ways:
- As a standalone deployment unit, which can be shared either publicly or within a team.
- It can be stored on one of the following registries:
- Docker Hub registry
- Amazon Elastic Container Registry (Amazon ECR)
- Harbor registry

## Prerequisites

Before proceeding with the container creation, make sure you have the following:

- The `my_package` ROS2 package has been created and cross-compiled. Follow the instructions [here](../../../README.md#vxworks-ros-2-development).
- VSB and VIP have been configured to support containers.

More information can be found in the [official documentation](https://docs.windriver.com/bundle/vxworks_container_programmers_guide_23_03/page/orf1603893608622.html).

## Building the my_package.oci VxWorks Container Image

Execute the following commands to build the container image:

```bash
# This script creates the my_package container
./scripts/create_vxc_container_payload.sh

# This command builds the my_package Docker image
sudo buildah bud -f examples/vxc/my_package/Dockerfile -t my_package --platform vxworks/amd64 my_package.build

# This command tags the my_package image with the registry information
sudo buildah tag my_package <registry-username>/my_package:vxworks7

# This command pushes the my_package image to the local OCI directory
sudo buildah push my_package oci:my_package.oci

# This command pushes the my_package image to the specified registry
sudo buildah push --creds <registry-username>:<password> my_package docker://<registry-username>/my_package.oci:vxworks7
```

## Pull, unpack and run my_package.oci VxWorks container image

```bash
# This command pulls the my_package image from the registry
vxc pull <registry-username>/my_package.oci:vxworks7

# This command unpacks the my_package image into a layered file system
vxc unpack --image ./my_package.oci --rootfs layered /home/my_package

# This command creates a new container from the my_package image
vxc create --bundle /home/my_package my_package

# This command starts the my_package container
vxc start my_package
```

## Kill, delete, and relaunch my_package.oci VxWorks container image

```bash
# This command kills the my_package container
vxc kill my_package

# This command deletes the my_package container
vxc delete my_package
```

Then you can relaunch the container by running:
```bash
# This command runs the my_package container
vxc run --bundle /home/my_package my_package
```

or,
```bash
# This command creates a new container from the my_package image
vxc create --bundle /home/my_package my_package

# This command starts the my_package container
vxc start my_package
```

Please replace the placeholders `<registry-username>` and `<password>` with your actual registry username and password. Similarly, replace `<path-to-wrsdk>` with the actual path to your wrsdk directory.

For testing purposes one can simply pull [this image](https://hub.docker.com/repository/docker/mkrunic/my_package.oci) that is build for amd64 target platform and VxWorks 7 OS.
57 changes: 57 additions & 0 deletions scripts/create_vxc_container_payload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

razr marked this conversation as resolved.
Show resolved Hide resolved
# Copyright (c) 2023 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

# Validate number of arguments
if [ $# -gt 3 ]; then
echo "Usage: $0 <SDK_DIR> <OCI_IMG_DIR> [PACKAGE_BIN]"
echo " eg. $0 /opt/wrsdk/wrsdk-vxworks7-raspberrypi4b-1.2 helloworld.build"
exit 1
fi

SDK_DIR=${1:-"/home/$USER/Downloads/wrsdk"}
OCI_IMG_DIR=${2:-"./my_package.build"}
PACKAGE_BIN=${3:-"build/ros2/ros2_ws/build/my_package/my_package"}

mkrunic-windriver marked this conversation as resolved.
Show resolved Hide resolved
# Make sure the package directory exists
if [ ! -f "$PACKAGE_BIN" ]; then
echo "File not found: $PACKAGE_BIN"
exit 1
fi

DEPLOY_DIR="$SDK_DIR/vxsdk/sysroot/usr/3pp/deploy"

# Make sure the deploy directory exists
if [ ! -d "$DEPLOY_DIR" ]; then
echo "Directory not found: $DEPLOY_DIR"
exit 1
fi

echo "building $OCI_IMG_DIR in $SDK_DIR"

# Create and check if the target directory exists
mkdir -p "$OCI_IMG_DIR/rootfs"
if [ ! -d "$OCI_IMG_DIR/rootfs" ]; then
echo "Failed to create directory: $OCI_IMG_DIR/rootfs"
exit 1
fi

# Copy the deploy directory
cp -av "$DEPLOY_DIR/"* "$OCI_IMG_DIR/rootfs/"

# Copy the package binary
cp "$PACKAGE_BIN" "$OCI_IMG_DIR/rootfs/usr/bin"