diff --git a/README.md b/README.md index 19f15be..d951376 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/examples/vxc/my_package/Dockerfile b/examples/vxc/my_package/Dockerfile new file mode 100755 index 0000000..de4fe47 --- /dev/null +++ b/examples/vxc/my_package/Dockerfile @@ -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 diff --git a/examples/vxc/my_package/README.md b/examples/vxc/my_package/README.md new file mode 100644 index 0000000..2a7040a --- /dev/null +++ b/examples/vxc/my_package/README.md @@ -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 /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 : my_package docker:///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 /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 `` and `` with your actual registry username and password. Similarly, replace `` 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. diff --git a/scripts/create_vxc_container_payload.sh b/scripts/create_vxc_container_payload.sh new file mode 100755 index 0000000..45caf4e --- /dev/null +++ b/scripts/create_vxc_container_payload.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# 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 [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"} + +# 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" \ No newline at end of file