Skip to content

Commit

Permalink
Improve Vagrant and Docker support
Browse files Browse the repository at this point in the history
o Move Vagrantfile, and support Docker on both Ubuntu and Debian
o Improve clone/build procedure for cpppo/mongrel2, and add pymodbus
  • Loading branch information
pjkundert committed Dec 18, 2013
1 parent a5e7101 commit b283f1c
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 27 deletions.
47 changes: 31 additions & 16 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,26 @@ all: help

help:
@echo "GNUmakefile for cpppo. Targets:"
@echo " help This help"
@echo " test Run unit tests under Python2/3"
@echo " install Install in /usr/local for Python2/3"
@echo " clean Remove build artifacts"
@echo " upload Upload new version to pypi (package maintainer only)"
@echo " virtualization Install all potential Vagrant virtual machines"
@echo " help This help"
@echo " test Run unit tests under Python2/3"
@echo " install Install in /usr/local for Python2/3"
@echo " clean Remove build artifacts"
@echo " upload Upload new version to pypi (package maintainer only)"
@echo " virtualization Install all potential Vagrant virtual machines"
@echo
@echo " virtualbox-* Manage VirtualBox virtual machine"
@echo " vmware-* Manage VMWare Fusion virtual machine (recommended; requires license)"
@echo " ...-up Bring up the virtual machine, configuring if necessary"
@echo " ...-halt Stop the virtual machine"
@echo " ...-destroy Discard the configured virtual machine"
@echo " virtualbox-* Manage VirtualBox virtual machine"
@echo " vmware-* Manage VMWare Fusion virtual machine (recommended; requires license)"
@echo " -debian-... Specify Debian Jessie 64-bit VM (VMware 6 compatible)"
@echo " -ubuntu-... Specify Ubuntu Precise 64-bit VM (VMware 5 compatible)"
@echo " ...-up Bring up the virtual machine, configuring if necessary"
@echo " ...-halt Stop the virtual machine"
@echo " ...-destroy Discard the configured virtual machine"
@echo
@echo " ...-ssh Establish SSH communications with the virtual machine"
@echo " ...-ssh Establish SSH communications with the virtual machine"
@echo
@echo "EXAMPLES"
@echo " vmware-debian-up Brings up Jessie VM w/ Docker capability"
@echo " vmware-debian-ssh Log in to the VM"

test:
$(PY2TEST)
Expand Down Expand Up @@ -83,11 +89,20 @@ clean:
precise64_virtualbox precise64_vmware_fusion \
raring_virtualbox

vmware-%: precise64_vmware_fusion
vagrant $* $(if $(filter up, $*), --provider=vmware_fusion,)
# The vagrant/ubuntu/Vagrantfile doesn't contain a config.vm.box_url; we must
# supply. The precise64 VMware image presently supports only VMware Fusion 5;
# if you see an error regarding hgfs kernel modules, you may be running a
# version of VMware Fusion incompatible with the VMware Tools in the image.
vmware-ubuntu-%: precise64_vmware_fusion
cd vagrant/ubuntu; vagrant $* $(if $(filter up, $*), --provider=vmware_fusion,)

virtualbox-%: precise64_virtualbox
vagrant $* $(if $(filter up, $*), --provider=virtualbox,)
virtualbox-ubuntu-%: precise64_virtualbox
cd vagrant/ubuntu; vagrant $* $(if $(filter up, $*), --provider=virtualbox,)

# The vagrant/debian/Vagrantfile contains its own config.vm.box_url image
# source. The jessie64 VMware image is compatible with VMware Fusion 6.
vmware-debian-%:
cd vagrant/debian; vagrant $* $(if $(filter up, $*), --provider=vmware_fusion,)

virtualization: vagrant_boxes

Expand Down
28 changes: 18 additions & 10 deletions docker/cpppo/mongrel2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# -*- mode: conf -*-
# cpppo/mongrel2 Dockerfile.
#
# DESCRIPTION
# Support for EtherNet/IP (via cpppo) and Modbus/TCP (via pymodbus) PLC simulation, using
# Mongrel2's ZeroMQ WebSockets protocol as the underlying transport.
#
FROM cpppo/cpppo
MAINTAINER Perry Kundert "[email protected]"
RUN apt-get install -y git
RUN mkdir src
RUN cd src; git clone git://github.com/zeromq/zeromq3-x.git; cd zeromq3-x; git checkout master
RUN cd src; git clone git://github.com/cython/cython.git; cd cython; git checkout 0.18
RUN cd src; git clone git://github.com/zeromq/pyzmq.git; cd pyzmq; git checkout v13.1.0
RUN cd src; git clone git://github.com/zedshaw/mongrel2.git; cd mongrel2; git checkout develop
RUN apt-get install -y libtool autoconf automake python-dev uuid-dev sqlite3 libsqlite3-dev build-essential

RUN pip install pymodbus

RUN apt-get install -y git libtool autoconf automake python-dev uuid-dev sqlite3 libsqlite3-dev build-essential
RUN mkdir -p src
RUN git clone --branch master git://github.com/zeromq/zeromq3-x.git src/zeromq3-x
RUN git clone --branch 0.18 git://github.com/cython/cython.git src/cython
RUN git clone --branch v13.1.0 git://github.com/zeromq/pyzmq.git src/pyzmq
RUN git clone --branch develop git://github.com/zedshaw/mongrel2.git src/mongrel2

RUN cd src/zeromq3-x; ./autogen.sh; ./configure; make V=1; make install; ldconfig
RUN cd src/cython; python setup.py install
RUN cd src/pyzmq; python setup.py configure --zmq=/usr/local; python setup.py install
RUN cd src/mongrel2; make; make install
RUN cd src/mongrel2/examples/python; python setup.py install

#EXPOSE 44818
#ENTRYPOINT [ "python", "-m", "cpppo.server.enip" ]
#CMD [ "SCADA=dint[1000]" ]
# Typically supports applications providing remote access via HTTP, Modbus/TCP and EtherNet/IP, eg:
#EXPOSE 80 502 44818
71 changes: 71 additions & 0 deletions vagrant/debian/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- mode: ruby -*-
# Download and configure a VMware instance of Debian 7 Jessie
# Configure it for Docker runtime and development of cpppo applications
#
# Instructions for creating a custom Vagrant Debian box:
# - http://www.skoblenick.com/vagrant/creating-a-custom-box-from-scratch/
#
# Docker-based configurations)
Vagrant.configure("2") do |config|
config.vm.box = "jessie64"
config.vm.box_url = "http://box.hardconsulting.com/jessie64.box"
config.vm.provision "shell" do |s|
# The kernel may be different than the running kernel after the upgrade! Ubuntu Raring requires
# software-properties-common, Precise python-software-properties to supply apt-add-repository,
# but these have a docker dpkg; Debian Jessie requires manual installation of docker.
# Adding a docker group causes /var/run/docker.sock to be docker group writable.
# The initiating Vagrantfile's ../ directory is mounted on /home/vagrant/src/.
s.inline = ' \
echo -e "\
deb http://mirrors.kernel.org/debian jessie main contrib non-free\n\
deb-src http://mirrors.kernel.org/debian jessie main contrib non-free\n\
\n\
deb http://mirrors.kernel.org/debian jessie-updates main contrib non-free\n\
deb-src http://mirrors.kernel.org/debian jessie-updates main contrib non-free\n\
\n\
deb http://security.debian.org/ jessie/updates main contrib non-free\n\
deb-src http://security.debian.org/ jessie/updates main contrib non-free\n"\
> /etc/apt/sources.list \
&& apt-get update \
&& apt-get -u -y dist-upgrade \
&& apt-get install -y \
apt-show-versions python-pip python-dev \
lxc wget bsdtar curl git aufs-tools \
emacs24-nox emacs24-el screen \
multitail aspell zip \
libxml2-dev libxslt-dev zlib1g-dev libbz2-dev \
&& sudo addgroup vagrant staff \
&& echo "Installing docker..." \
&& sudo -u vagrant wget -q --output-document=/usr/local/bin/docker \
https://get.docker.io/builds/Linux/x86_64/docker-latest \
&& sudo wget -q --output-document=/etc/init.d/docker \
https://raw.github.com/dotcloud/docker/master/contrib/init/sysvinit/docker \
&& sed -e "/^DOCKER=/ s|/usr/bin/|/usr/local/bin/|" -i /etc/init.d/docker \
&& sudo chmod a+x /etc/init.d/docker \
&& sudo update-rc.d docker defaults \
&& chmod a+x /usr/local/bin/docker \
&& echo "none /sys/fs/cgroup cgroup defaults 0 0" | sudo tee -a /etc/fstab \
&& sudo mount /sys/fs/cgroup \
&& addgroup docker \
&& addgroup vagrant docker \
&& echo "Enabling IPv4 forwarding..." \
&& sed -i -e "s/#\(net.ipv4.ip_forward\)=.*/\1=1/" /etc/sysctl.conf \
&& sudo sysctl -w net.ipv4.ip_forward=1 \
&& service docker restart \
&& echo "Installing cpppo..." \
&& pip install cpppo pymodbus pytest netifaces lxml web.py wsgilog \
&& echo && echo "Login w/ vagrant ssh" \
'
end
config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
# Mount the directory containing the cpppo image on ~/src/
config.vm.synced_folder "../../..", "/home/vagrant/src"
config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = "2048"
v.vmx["numvcpus"] = "1"
v.gui = true
end
config.vm.provider "virtualbox" do |v|
v.gui = true
end
end
2 changes: 1 addition & 1 deletion Vagrantfile → vagrant/ubuntu/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Vagrant.configure("2") do |config|
'
end
config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
config.vm.synced_folder "..", "/home/vagrant/src"
config.vm.synced_folder "../../..", "/home/vagrant/src"
config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = "2048"
v.vmx["numvcpus"] = "2"
Expand Down

0 comments on commit b283f1c

Please sign in to comment.