Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #338 from davoclavo/fix_docker
Browse files Browse the repository at this point in the history
Fix docker build
  • Loading branch information
rbaynes authored Sep 1, 2017
2 parents e1643c1 + 5b0f15f commit 1c3c1ed
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 40 deletions.
41 changes: 13 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,28 @@ RUN apt-get update && \
libboost-filesystem-dev \
libxml2-dev \
libgtest-dev
# Tell apt to read from the ROS package repository
RUN sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu jessie main" > /etc/apt/sources.list.d/ros-latest.list'
RUN wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -O - | sudo apt-key add -

RUN sudo locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8

# Create pi user
RUN useradd pi && echo 'pi:hypriot' | chpasswd && echo "pi ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && mkdir -p /home/pi && chown pi:pi /home/pi

# Give pi access to the camera device
RUN sudo usermod -a -G video pi

RUN groupadd gpio

USER pi
WORKDIR /home/pi/
# Give the pi user access to the usb drive for flashing an Arduino
RUN sudo usermod -a -G dialout pi
# Add catkin install dir (built with catkin)
# Note that you must run docker builds from ~/catkin_ws
#
# cd ~/catkin_ws
# docker build -f ./src/openag_brain/Dockerfile .
#

# We use COPY rather than ADD, as COPY is preferred for local files.
# https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#add-or-copy
COPY . /home/pi/catkin_ws
COPY . /home/pi/catkin_ws/src/openag_brain
RUN sudo chown -R pi:pi ~/catkin_ws
# Install ROS boostrapping tool
RUN sudo apt-get update && sudo apt-get install --no-install-recommends -y -q \
python-pip python-rosdep

# Install some python dependencies that there aren't ros packages for.
RUN sudo pip install -q voluptuous HTTPretty

# Install dependencies with rosdep
RUN sudo rosdep init && rosdep update && rosdep install --from-paths ~/catkin_ws/src --ignore-src --rosdistro indigo -y -r --os=debian:jessie
RUN cd ~/catkin_ws && ./src/catkin/bin/catkin_make install
# Add .bashrc
RUN echo -e '[ -z "$PS1" ] && return' >~/.bashrc
RUN echo -e 'source ~/catkin_ws/install/setup.bash' >>~/.bashrc

# Set up ROS environment vars
ENV LANG=en_US.UTF-8 ROS_DISTRO=indigo

RUN /home/pi/catkin_ws/src/openag_brain/scripts/install_dev

# Run the project
CMD ["/home/pi/catkin_ws/install/env.sh", "rosrun", "openag_brain", "main", "personal_food_computer_v2.launch"]
USER pi
2 changes: 1 addition & 1 deletion doc/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Now that openag_brain is in the catkin_build space, you can run the
install script::

cd ~/catkin_ws/src/openag_brain
./scripts/install_dev
./scripts/developer_setup

This will set up a full development environment for openag_brain and ROS.

Expand Down
42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Start Docker containers with configuration for Personal Food Computer V2.
# See http://wiki.openag.media.mit.edu/food_computer_2
version: '2'
services:
brain:
# Build from current folder
build: .

# Build from image
# image: openag/rpi_brain

# Build from git source with branch
# build: https://github.com/OpenAgInitiative/openag_brain.git#develop
container_name: brain
expose:
- 5000
devices:
- "/dev/ttyACM0:/dev/ttyACM0"
- "/dev/video0:/dev/video0"
- "/dev/ttyACM0:/dev/serial/by-id/arduino" # https://github.com/openaginitiative/openag_brain/blob/develop/nodes/arduino_handler.py#L322
command: /home/pi/catkin_ws/devel/env.sh rosrun openag_brain main personal_food_computer_v2.launch -D http://db:5984 -A http://brain:5000 --screen
depends_on:
- db
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
db:
image: dogi/rpi-couchdb
container_name: db
expose:
- 5984
ports:
- 5984:5984
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
7 changes: 7 additions & 0 deletions scripts/developer_setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# This script sets up a developer workspace. It is for a global stand-alone
# system - not for a docker setup.
set -e

~/catkin_ws/src/openag_brain/scripts/install_db || exit 1
~/catkin_ws/src/openag_brain/scripts/install_dev || exit 1
9 changes: 2 additions & 7 deletions scripts/init_dev
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ echo "Update apt"
sudo apt-get update -q
# sudo apt-get -y upgrade

# Install couchdb (couchdb is not available via rosdep -- see below)
echo "Install pip, couchdb and ROS bootstrapping tools"
sudo apt-get install -y -q couchdb python-setuptools

# Configure couchdb to do auto DB and view compaction
# (or we will run out of disk space on a 32G SD card in a few weeks).
curl -X PUT http://localhost:5984/_config/compactions/_default -d '"[{db_fragmentation, \"40%\"}, {view_fragmentation, \"30%\"}, {from, \"23:00\"}, {to, \"06:00\"}]"'
echo "Install pip and ROS bootstrapping tools"
sudo apt-get install -y -q python-setuptools

# Install pip and python bootstrapping dependencies
# We install pip with easy_install because the ARM/Debian apt package
Expand Down
1 change: 1 addition & 0 deletions scripts/install_db
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo apt-get install -y -q couchdb
4 changes: 1 addition & 3 deletions scripts/install_dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash
# This script sets up a developer workspace for openag_brain and its
# dependencies, then builds everything using `catkin_make_isolated` and
# installs it in `/opt/ros/indigo/`.
# dependencies, then builds everything using `catkin_make`.

# Make sure we exit if a failure happens.
# http://stackoverflow.com/questions/19622198/what-does-set-e-mean-in-a-bash-script
Expand All @@ -14,7 +13,6 @@ fi
~/catkin_ws/src/openag_brain/scripts/init_dev || exit 1
echo "~~~"
echo "Now building..."
echo "Location: /opt/ros/indigo"
echo "~~~"

# Install packages in system directory
Expand Down
2 changes: 1 addition & 1 deletion scripts/install_pio
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#type platformio > /dev/null 2>&1 && echo "pio is already installed" && exit
# We install platformio in a virtualenv, because platformio and rosserial
# depend on different versions of pyserial.
sudo apt-get install -y python-virtualenv
sudo pip install virtualenv
virtualenv ~/pio_env
source ~/pio_env/bin/activate
pip install platformio==3.3.0
Expand Down
7 changes: 7 additions & 0 deletions src/openag_lib/db_bootstrap/db_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def generate_config(api_url=None):
},
"query_server_config": {
"reduce_limit": "false"
},
"compactions": {
"_default": "[{db_fragmentation, \"40%\"}, {view_fragmentation, \"30%\"}, {from, \"23:00\"}, {to, \"06:00\"}]"
},
"compaction_daemon": {
"check_interval": "300",
"min_file_size": "131072"
}
}
if api_url:
Expand Down

0 comments on commit 1c3c1ed

Please sign in to comment.