From 45ac1e43d69bf7bd52101d5786cbcc6f60dd11b9 Mon Sep 17 00:00:00 2001
From: Vivek Kumar Dutta <vivek.dutta@iopsys.eu>
Date: Wed, 21 Jun 2023 13:48:56 +0000
Subject: [PATCH] example: iowrt oci container with self code

---
 examples/iowrt/Dockerfile   |  9 +++++++++
 examples/iowrt/Makefile     |  7 +++++++
 examples/iowrt/config       | 37 +++++++++++++++++++++++++++++++++++++
 examples/iowrt/src/Makefile |  7 +++++++
 examples/iowrt/src/hello.c  |  7 +++++++
 5 files changed, 67 insertions(+)
 create mode 100644 examples/iowrt/config
 create mode 100644 examples/iowrt/src/Makefile
 create mode 100644 examples/iowrt/src/hello.c

diff --git a/examples/iowrt/Dockerfile b/examples/iowrt/Dockerfile
index f4efd22..91b4f63 100644
--- a/examples/iowrt/Dockerfile
+++ b/examples/iowrt/Dockerfile
@@ -33,6 +33,10 @@ RUN \
     make -j2 && \
     make install
 
+# Integrate own applications
+COPY src src
+RUN make -C /src
+
 # Final image
 FROM alpine:latest
 
@@ -45,6 +49,11 @@ LABEL vendor=IOPSYS \
 
 RUN apk add --no-cache json-c libxml2 mosquitto mosquitto-clients
 
+# Install own application
+COPY --from=builder \
+      /src/hello \
+      /usr/bin/hello
+
 COPY --from=builder \ 
       /usr/lib/libuci.so \
       /usr/lib/libblobmsg_json.so \
diff --git a/examples/iowrt/Makefile b/examples/iowrt/Makefile
index 37e3fcd..78031c4 100644
--- a/examples/iowrt/Makefile
+++ b/examples/iowrt/Makefile
@@ -7,5 +7,12 @@ all:
 	tar cf iowrt.tar rootfs config.json
 	rm -rf tmp.tar rootfs
 
+lxc:
+	mkdir -p rootfs
+	docker buildx build --platform ${PLATFORM} -o type=tar,dest=tmp.tar .
+	tar xf tmp.tar -C rootfs/
+	tar cf iowrt.tar rootfs config
+	rm -rf tmp.tar rootfs
+
 clean:
 	- rm -rf tmp.tar rootfs iowrt.tar
diff --git a/examples/iowrt/config b/examples/iowrt/config
new file mode 100644
index 0000000..bbc890b
--- /dev/null
+++ b/examples/iowrt/config
@@ -0,0 +1,37 @@
+lxc.net.0.type = veth
+lxc.net.0.link = lxcbr0
+lxc.net.0.flags = up
+lxc.net.0.hwaddr = 00:16:3e:8e:25:2d
+
+lxc.rootfs.path = dir:/tmp/lxc/test/rootfs
+lxc.uts.name = "test"
+
+lxc.cap.drop = mac_admin
+lxc.cap.drop = mac_override
+lxc.cap.drop = sys_admin
+lxc.cap.drop = sys_boot
+lxc.cap.drop = sys_module
+lxc.cap.drop = sys_nice
+lxc.cap.drop = sys_pacct
+lxc.cap.drop = sys_ptrace
+lxc.cap.drop = sys_rawio
+lxc.cap.drop = sys_resource
+lxc.cap.drop = sys_time
+lxc.cap.drop = sys_tty_config
+lxc.cap.drop = syslog
+lxc.cap.drop = wake_alarm
+
+lxc.autodev = 1
+lxc.console.buffer.size = auto
+lxc.tty.max = 5
+lxc.pty.max = 5
+lxc.mount.auto = cgroup:mixed proc:mixed sys:mixed
+
+lxc.net.0.type = veth
+lxc.net.0.flags = up
+lxc.net.0.link = br-lan
+lxc.net.0.name = eth0
+lxc.net.0.mtu = 1500
+
+lxc.mount.entry = /lib lib none ro,bind 0 0
+lxc.mount.entry = /sys/kernel/security sys/kernel/security none ro,bind,optional 0 0
diff --git a/examples/iowrt/src/Makefile b/examples/iowrt/src/Makefile
new file mode 100644
index 0000000..76ea9a8
--- /dev/null
+++ b/examples/iowrt/src/Makefile
@@ -0,0 +1,7 @@
+PROG:=hello
+
+all: *.c
+	gcc -o ${PROG} *.c
+
+clean:
+	-@rm ${PROG}
diff --git a/examples/iowrt/src/hello.c b/examples/iowrt/src/hello.c
new file mode 100644
index 0000000..89be92d
--- /dev/null
+++ b/examples/iowrt/src/hello.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+	printf("Hello! OCI container.....\n");
+	return 0;
+}
-- 
GitLab