Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fboss-image/examples/demo_container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This example shows how to build a docker container to be run on a device inside the Distro Image.
13 changes: 13 additions & 0 deletions fboss-image/examples/demo_container/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -e

dnf builddep -y --spec rpmbuild/SPECS/demo_container.spec

rpmdir=$(pwd)/rpmbuild
mkdir -p ${rpmdir}/{RPMS,SRPMS,BUILD,BUILDROOT}

rpmbuild -bb --define "_topdir ${rpmdir}" ${rpmdir}/SPECS/demo_container.spec

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
mkdir -p ${SCRIPT_DIR}/dist
cp ${rpmdir}/RPMS/*/*.rpm ${SCRIPT_DIR}/dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:alpine

RUN mkdir /output

RUN pip install cowsay

COPY time.py /time.py

CMD ["python", "/time.py"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# /usr/lib/systemd/system/demo_container.service
[Unit]
Description=Demo Container
After=network.target

[Service]
Type=simple
Restart=on-failure
TimeoutStartSec=180s
TimeoutStopSec=10s
ExecStart=/usr/bin/docker run --rm --name demo_container -v /var/clock:/output --net none demo_container
ExecStop=/usr/bin/docker stop demo_container

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions fboss-image/examples/demo_container/rpmbuild/SOURCES/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python3
import cowsay
import time

while True:
time.sleep(1)

s = cowsay.get_output_string("trex", "Current time is " + time.ctime()) + "\n"
with open("/output/time.txt", "w") as f:
f.write(s)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Name: demo_container
Version: 1.0
Release: 1
Summary: Demo Container
License: GPL
BuildRequires: podman-docker
Requires: podman-docker

%description
Demo building, installing, and running a container on a device inside the Distro Image.

%prep
cp %{_sourcedir}/Dockerfile .
cp %{_sourcedir}/time.py .

%build
docker build . -t demo_container
rm -f demo_container.tar
docker save demo_container -o demo_container.tar

%install
%{__install} -D -m 644 demo_container.tar %{buildroot}/usr/share/demo_container/demo_container.tar
%{__install} -D -m 644 %{_sourcedir}/demo_container.service %{buildroot}/usr/lib/systemd/system/demo_container.service
mkdir -p %{buildroot}/var/clock

%files
%defattr(-,root,root,-)
/var/clock
%config(missingok) /usr/share/demo_container/demo_container.tar
/usr/lib/systemd/system/demo_container.service

%post
docker load -i /usr/share/demo_container/demo_container.tar
rm -rf /usr/share/demo_container
systemctl enable demo_container.service
Loading