Skip to content

Commit

Permalink
Add dev container.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoppert committed Jan 3, 2023
1 parent dbc41df commit 3820c57
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 0 deletions.
98 changes: 98 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
###
### Base: base image
###

FROM ubuntu:20.04 AS base
LABEL maintainer="James Goppert <james.goppert@gmail.com>"

# Set default shell during Docker image build to bash
SHELL ["/bin/bash", "-c"]

COPY docker_clean.sh /docker_clean.sh
RUN chmod +x /docker_clean.sh

# Install base packages
RUN apt-get -y update && \
apt-get -y upgrade && \
apt-get install --no-install-recommends -y \
sudo \
locales \
&& \
/docker_clean.sh

# set locale
RUN locale-gen en_US.UTF-8

# set user as default so install scripts look the same for local host install
RUN groupadd -r -g 110 render \
&& adduser --disabled-password --gecos '' user \
&& adduser user sudo \
&& adduser user render \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER user

# initialise system locale
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
# required to allow nanopb to build on ubuntu 22.04 currently
ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
ENV XDG_RUNTIME_DIR=/tmp/runtime-docker

# install dependencies using scripts in a manner that will cache build
# when one script is modified
COPY install/base.sh /tmp/install/base.sh
RUN /tmp/install/base.sh && /docker_clean.sh

###
### Build: bare minimum to run the simulator
###
FROM base AS sim

###
### Build: bare minimum to build the binary
###
FROM base AS build

COPY install/ros.sh /tmp/install/ros.sh
RUN /tmp/install/ros.sh && /docker_clean.sh

COPY install/gazebo.sh /tmp/install/gazebo.sh
RUN /tmp/install/gazebo.sh && /docker_clean.sh

COPY install/open_vino.sh /tmp/install/open_vino.sh
RUN /tmp/install/open_vino.sh && /docker_clean.sh

COPY install/extra.sh /tmp/install/extra.sh
RUN /tmp/install/extra.sh && /docker_clean.sh

# enable apt auto-completion by deleting autoclean task
RUN sudo rm /etc/apt/apt.conf.d/docker-clean

# create setting directory for ignition gazebo
RUN mkdir -p /home/user/.ignition \
&& chown -R user:user /home/user/.ignition

# avoid .bashrc warning
RUN mkdir -p /home/user/.bash_completion.d

# create XDG runtime dir
RUN mkdir /tmp/runtime-docker && sudo chmod 700 /tmp/runtime-docker

# create src dir
RUN sudo mkdir -p /workdir && sudo chown -R user:user /workdir && mkdir -p /workdir/src

# setup .bashrc
RUN mkdir -p /home/user/.bash_completion.d && \
echo "source /home/user/ws/devel/setup.bash" >> ~/.bashrc

# enable entrypoint
ENV PATH="/home/user/bin:${PATH}"
ENV DISPLAY=${DISPLAY}

WORKDIR /workdir
COPY entrypoint.sh /
RUN sudo chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

# vim: set et fenc=utf-8 ff=unix ft=dockerfile sts=0 sw=2 ts=2 :
54 changes: 54 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "auav",

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"./docker-compose.yml"
],

// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "auav",

// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/workdir",

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],

// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",

// Uncomment the next line to run commands after the container is created - for example installing curl.
// "postCreateCommand": "apt-get update && apt-get install -y curl",

// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"

"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-azuretools.vscode-docker",
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools-themes",
"trond-snekvik.devicetree",
"trond-snekvik.kconfig-lang",
"ms-python.python",
"eamodio.gitlens",
"akiramiyakoda.cppincludeguard"
]
}
}
}
32 changes: 32 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.9"

volumes:
# remembers ignition config, downloaded models etc
ignition_config:

services:

auav:
image: jgoppert/auav_23_ros1:latest
build:
context: .
tty: true
stdin_open: true
privileged: true
hostname: auav
devices:
- /dev/net/tun:/dev/net/tun
environment:
- DISPLAY=${DISPLAY}
volumes:
- ./workdir:/workdir
- ..:/workdir/src/
- /tmp/.X11-unix:/tmp/.X11-unix:ro
- ignition_config:/home/user/.ignition:rw
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
6 changes: 6 additions & 0 deletions .devcontainer/docker_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e
sudo apt-get clean -y
sudo apt-get autoremove --purge -y
sudo rm -rf /var/lib/apt/lists/*
sudo rm -rf /tmp/*
2 changes: 2 additions & 0 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
bash
17 changes: 17 additions & 0 deletions .devcontainer/install/base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

sudo apt-get -y update
sudo apt-get -y upgrade
sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
bash-completion \
build-essential \
curl \
git \
gnupg \
lsb-release \
python3-pip \
python3-setuptools \
python3-venv \
unzip \
wget
18 changes: 18 additions & 0 deletions .devcontainer/install/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -x
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo docker run hello-world
9 changes: 9 additions & 0 deletions .devcontainer/install/extra.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

sudo apt-get -y update
sudo apt-get -y upgrade
sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
screen \
tcpdump \
vim
9 changes: 9 additions & 0 deletions .devcontainer/install/gazebo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
sudo apt-get -y update
sudo apt-get -y upgrade
sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
gazebo11
13 changes: 13 additions & 0 deletions .devcontainer/install/open_vino.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# install openvino
# source: https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_apt.html
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB && rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ACFA9FC57E6C5DBE
echo "deb https://apt.repos.intel.com/openvino/2022 focal main" | sudo tee /etc/apt/sources.list.d/intel-openvino-2022.list
sudo apt update
sudo apt install openvino libngraph0-dev
SOURCE_OPENVINO="source /opt/intel/openvino_2022/setupvars.sh"
grep -qxF "$SOURCE_OPENVINO" ~/.bashrc || echo "$SOURCE_OPENVINO" >> ~/.bashrc
source ~/.bashrc
14 changes: 14 additions & 0 deletions .devcontainer/install/ros.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e
ROS_VERSION="noetic"

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo apt-get -y update
sudo apt-get -y upgrade
sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
ros-${ROS_VERSION}-desktop-full \
python3-rosdep \
python3-catkin-tools

pip install pymavlink --user
2 changes: 2 additions & 0 deletions .devcontainer/workdir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 3820c57

Please sign in to comment.