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

make a docker version of the dev environment #76

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5de9793
add docker folder with dockerfile
MoralCode Mar 20, 2022
62c2e7f
copy files from kubos tools/dist repo
MoralCode Mar 31, 2022
a50675d
this deb has been removed in recent versions, so use an older version…
MoralCode Mar 31, 2022
23eda1a
add README
MoralCode Mar 31, 2022
f95cbce
add initial docker compose
MoralCode Mar 31, 2022
12dc48c
mount the current directory like the vagrant environment
MoralCode Mar 31, 2022
b7c5c7b
add instructions for moving the composefile
MoralCode Mar 31, 2022
7c8e20f
change cz domain to us
MoralCode Apr 1, 2022
cbf5e8c
bump version i guess
MoralCode Apr 1, 2022
0bda7d7
replace deprecated MAINTAINER directive
MoralCode Apr 1, 2022
cca863f
add more README
MoralCode Apr 2, 2022
d2f16df
add another dockerfile to emulate the Kubos SDK environment
MoralCode Apr 2, 2022
af6d32f
create build script for building all the dockerfiles
MoralCode Apr 2, 2022
0522305
use the new sdk image with a kubos user for the compose file
MoralCode Apr 2, 2022
688aefb
add comments detailing what to do if you want to mount other devices
MoralCode Apr 2, 2022
124fe37
update docs
MoralCode Apr 3, 2022
81b0fcc
restructure the repo a bit
MoralCode Apr 4, 2022
658da1e
seems like the cz was just a copy paste from the history
MoralCode Apr 4, 2022
edd1bc9
move python and rust installs to the build image instead of base
MoralCode Apr 4, 2022
856cfc5
have sdk inherit from base and also install python and rust dependencies
MoralCode Apr 4, 2022
cba8952
remove duplicate dependency in base img
MoralCode Apr 4, 2022
2d9deb4
add note about resolvconf (but seems irrelevant to docker???)
MoralCode Apr 4, 2022
e84db87
move user account creation and add more to it from vagrant env
MoralCode Apr 4, 2022
f78df5d
update setup of python deps from vagrant
MoralCode Apr 4, 2022
ccca4eb
install more things via apt for SDK
MoralCode Apr 4, 2022
3e4915b
add system configs for minicom and udev
MoralCode Apr 4, 2022
de2d675
update rust install to be a user install
MoralCode Apr 4, 2022
677b72f
install kubos protocol clients and python libs
MoralCode Apr 4, 2022
548751c
move configs from vagrant side and symlink them for now
MoralCode Apr 4, 2022
15d4772
rename build script
MoralCode Apr 4, 2022
417375d
update build script for new structure
MoralCode Apr 4, 2022
1af3761
make script executable
MoralCode Apr 4, 2022
fc5fab2
update Readme for building the images
MoralCode Apr 4, 2022
20fdb65
fix apt install line that had a line break
MoralCode Apr 4, 2022
7f90594
remove latex stuff for now to save space
MoralCode Apr 4, 2022
eafb503
fix paths and build process so that the aux files in bin can be copied
MoralCode Apr 4, 2022
417f6a9
fix clone path for kubos
MoralCode Apr 4, 2022
5bee013
add nano and sudo to the environment
MoralCode Apr 5, 2022
0490b29
add link to instructions for relocating vagrant drives to a new disk
MoralCode Jun 13, 2023
23605f5
update readme
MoralCode Jun 13, 2023
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## Kubos-Dev

This repo aims to contain various dev and build environment setup instructions.

It includes:
- the kubos vagrant environment mentioned in the kubos docs (`kubos-dev`)
- docker images for CI builds (`docker/kubos-build`) that have been relocated from the main repo
- a docker image that aims to be an equivalent to the vagrant image to promote reuse and space savings by deduplicating many things with the CI build image (`docker/kobos-sdk`)


------


For usage instructions checkout the official [Kubos docs](https://docs.kubos.com/latest/sdk-docs/index.html)

## Testing Vagrant Changes:
Expand Down
1 change: 1 addition & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.git/
48 changes: 48 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
This folder contains a docker environment for developing KubOS.

It consists of a couple docker containers and a script of some kind (currently docker compose) to make the experience as similar as possible to "vagrant up".

## Containers
There are three containers at play here to keep things organized:

**kubos-base** - a base image containing dependencies that must be installed from a priviliged account (root)

**kubos-build** - this image is intended to be a replica of what is currently being used for CI builds

**kubos-sdk** - this image is intended to emulate the KubOS SDK vagrant envrionment as closely as possible and installs many dependencies under a regular user account

## Setup
### Building the images

**TL;DR** to build any of the docker containers, use the command `docker build -t <image_name> -f <image_folder>/Dockerfile . ` while inside this `docker` folder. if you are just looking to build the docker container for the SDK, theres also a `build-sdk.sh` script.

This slightly different command from the usual `docker build -t <name> .` is needed because the various containers need to copy some fonfiguration files from the `bin` folder throughout the process, so this folder also needs to be part of dockers build context.

The build context is the directory passed to `docker build`, which is where it looks for the `Dockerfile` by default. Because this `bin` folder and the `Dockerfile` are in separate directories, the build context should be set to the `docker` folder and the Dockerfile needs to be manually specified because it differs from the default.

#### Image names
Most of the images rely on the `kubos-base` image, so it is recommended to keep the image names the same as the directory of their `Dockerfile` so images like `kubos-sdk` that depend on this base image are still able to build correctly.
### Configuring the container

Because the docker compose file is designed to be run from the directory you want to mount (similar to the Vagrantfile), it should be relocated there.

If you want a one-time setup, use this copy command from this directory to create or replace your docker compose in your desired location: `cp ./docker-compose.yml /path/to/your/Vagrantfile`

If you want to automatically keep things in sync, use a symlink: `ln -s /full/path/to/docker/docker-compose.yml ./path/to/your/Vagrantfile`

### Running the container
To get a shell into the container similar to vagrant ssh, use `docker-compose run --rm kubos-sdk` from the directory where you copoed the compose file to.

The docker container will auto-mount this directory into the container at the mount point /vagrant just like the KubOS Vagrant SDK.

To add additional directory mounts, such as for mounting something to `/home/kubos`, feel free to edit the `docker-compose.yml`

## Transferring data from the VM
Vagrant offers a plugin that can be used to exfiltrate the data you want to transfer to the docker environment. This can be set up using `vagrant plugin install vagrant-scp` ([source](https://stackoverflow.com/questions/16704059/easiest-way-to-copy-a-single-file-from-host-to-vagrant-guest#28359455))


## Moving the generated image to an external drive
For space-constrained host PC's, its possible to move the docker images to an external drive:
- Macos: https://stackoverflow.com/questions/38205735/store-docker-image-files-on-external-drive-in-macos#40114330
- linux:

File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions docker/build-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docker build -t kubos-base -f kubos-base/Dockerfile .
docker build -t kubos-sdk -f kubos-sdk/Dockerfile .


5 changes: 5 additions & 0 deletions docker/cargo_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.arm-unknown-linux-gnueabihf]
linker = "/usr/bin/bbb_toolchain/usr/bin/arm-linux-gcc"

[target.armv5te-unknown-linux-gnueabi]
linker = "/usr/bin/iobc_toolchain/usr/bin/arm-linux-gcc"
12 changes: 12 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.9" # optional since v1.27.0
services:
kubos-sdk:
image: kubos-sdk
volumes:
- .:/vagrant
entrypoint: "bash"
stdin_open: true
tty: true
# if you have a device you want to make available in the VM, uncomment this
# devices:
# - "/dev/ttyUSB0:/dev/FTDI"
49 changes: 49 additions & 0 deletions docker/kubos-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM ubuntu:18.04

LABEL org.opencontainers.image.authors="[email protected], [email protected]" \
version="1.20.1" \
com.example.vendor="The KubOS Community"

RUN apt-get update -y

RUN apt-get upgrade --no-install-recommends -y python3.7
RUN apt-get install --no-install-recommends -y pkg-config build-essential git cmake unzip wget sqlite3 libsqlite3-dev libssl-dev curl ssh

# Linux build dependencies
RUN apt-get install --no-install-recommends -y python file rsync bc cpio ncurses-dev libc6-i386 lib32stdc++6 lib32z1

#Tools to generate docs
RUN apt-get install --no-install-recommends -y doxygen graphviz plantuml

# resolvconf is no longer included by default as of Ubuntu 18.04
# apt-get install -y resolvconf
# rm -f /etc/resolv.conf
# # There's something wrong with the default resolv.conf symlink. This fixes it
# ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf


# Install pip for Python2 and Python3
RUN apt-get install --no-install-recommends -y python3-pip python3-setuptools

# So that we have bdist_wheel available when installing other packages
RUN pip3 install wheel

#Kubos Linux setup
RUN echo "Installing Kubos Linux Toolchain"

RUN wget https://s3.amazonaws.com/kubos-world-readable-assets/iobc_toolchain.tar.gz && tar -xf ./iobc_toolchain.tar.gz -C /usr/bin && rm ./iobc_toolchain.tar.gz

RUN wget https://s3.amazonaws.com/kubos-world-readable-assets/bbb_toolchain.tar.gz && tar -xf ./bbb_toolchain.tar.gz -C /usr/bin && rm ./bbb_toolchain.tar.gz

# Install NOS3 dependencies
RUN apt-get --no-install-recommends install -y software-properties-common
# This was originally a cz.archive domain not us.
RUN add-apt-repository 'deb http://us.archive.ubuntu.com/ubuntu xenial main universe'
RUN apt-get install -y libboost-system1.58.0 libboost-program-options1.58.0 libxerces-c3.1
RUN wget https://github.com/nasa/nos3/raw/v1_04_00/support/packages/ubuntu/itc-common-cxx11-Release_1.9.1_amd64.deb && \
apt-get install -y ./itc-common-cxx11-Release_1.9.1_amd64.deb && rm itc-common-cxx11-Release_1.9.1_amd64.deb

RUN wget https://github.com/nasa/nos3/raw/v1_04_00/support/packages/ubuntu/nos-engine-cxx11-Release_1.4.0_amd64.deb && \
apt-get install -y ./nos-engine-cxx11-Release_1.4.0_amd64.deb && rm nos-engine-cxx11-Release_1.4.0_amd64.deb

ENV PATH "$PATH:/usr/bin/iobc_toolchain/usr/bin:/usr/bin/bbb_toolchain/usr/bin"
15 changes: 15 additions & 0 deletions docker/kubos-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM kubos-base

# Install all Kubos Python dependencies
RUN git clone https://github.com/kubos/kubos --depth 1 && pip3 install -r kubos/requirements.txt && rm -r kubos

# Setup rust stuff
ENV PATH "$PATH:/root/.cargo/bin"
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && rustup toolchain uninstall stable-x86_64-unknown-linux-gnu
RUN rustup default 1.39.0 && rm -rf /root/.rustup/toolchains/*/share/doc
RUN rustup target install arm-unknown-linux-gnueabihf
RUN rustup target install armv5te-unknown-linux-gnueabi
RUN rustup component add clippy
RUN rustup component add rustfmt
RUN /root/.cargo/bin/cargo install --git https://github.com/kubos/cargo-kubos
COPY ../bin/cargo_config /root/.cargo/config
83 changes: 83 additions & 0 deletions docker/kubos-sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
FROM kubos-base

# Install more priviliged dependencies that only seem to be needed in the SDK environment

RUN apt-get install -y software-properties-common

# Install kernel additions for better USB device recognition
RUN apt-get install -y linux-image-extra-virtual

RUN apt-get install -y libffi-dev libhidapi-hidraw0 gdb ninja-build python-dev libffi-dev


# tools for user friendliness
RUN apt-get install -y sshpass nano sudo


# Documentation tools
# latex stuff takes up a fair bit of space. lets wait and see how necessary this is
# RUN apt-get install -y texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended latexmk texlive-fonts-extra

# KubOS Linux setup
# echo "Installing KubOS Linux Toolchains"

RUN apt-get install -y minicom

# Utilities for building KubOS Linux
RUN apt-get install -y mtools


# Copy configs
COPY bin/minirc.kubos /etc/minicom/minirc.kubos
COPY bin/kubos-usb.rules /etc/udev/rules.d/kubos-usb.rules

# Create user accounts
RUN useradd --create-home --shell /bin/bash kubos
RUN adduser kubos sudo
RUN adduser kubos dialout

RUN echo 'kubos:Kubos123' | chpasswd

#Vagrant commands may act funny without password-less sudo
RUN echo "kubos ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER kubos
WORKDIR /home/kubos

RUN mkdir -p /home/kubos/.kubos
# Install all Kubos Python dependencies

RUN git clone https://github.com/kubos/kubos /home/kubos/.kubos/kubos --depth 1 && pip3 install -r /home/kubos/.kubos/kubos/requirements.txt
#&& rm -r kubos
RUN chown -R kubos /home/kubos/.kubos

# Setup rust stuff
ENV PATH "$PATH:/home/kubos/.cargo/bin"
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && rustup toolchain uninstall stable-x86_64-unknown-linux-gnu
RUN rustup default 1.39.0 && rm -rf /home/kubos/.rustup/toolchains/*/share/doc
RUN rustup target install arm-unknown-linux-gnueabihf
RUN rustup target install armv5te-unknown-linux-gnueabi
RUN rustup component add clippy
RUN rustup component add rustfmt
RUN /home/kubos/.cargo/bin/cargo install --git https://github.com/kubos/cargo-kubos
COPY bin/cargo_config /home/kubos/.cargo/config


RUN /home/kubos/.cargo/bin/cargo install --bin kubos-file-client --path /home/kubos/.kubos/kubos/clients/kubos-file-client/
# Install shell-client
RUN /home/kubos/.cargo/bin/cargo install --bin kubos-shell-client --path /home/kubos/.kubos/kubos/clients/kubos-shell-client/
# Install example UART comms client
RUN /home/kubos/.cargo/bin/cargo install --bin uart-comms-client --path /home/kubos/.kubos/kubos/clients/uart-comms-client/
# Cleanup temporary build files
RUN rm -rf /home/kubos/.kubos/kubos/target

# Install app-api python module
RUN cd /home/kubos/.kubos/kubos/apis/app-api/python && python3 -m pip install .

# Install i2c python module
RUN cd /home/kubos/.kubos/kubos/hal/python-hal/i2c && python3 -m pip install .

# Install kubos-service python module
RUN cd /home/kubos/.kubos/kubos/libs/kubos-service && python3 -m pip install .


1 change: 1 addition & 0 deletions kubos-dev/bin