From cf5feaea8ac51e8efb106f7d420f74420b33f395 Mon Sep 17 00:00:00 2001 From: T Date: Thu, 31 Jan 2019 17:04:29 +0100 Subject: [PATCH 1/3] add Dockerfile --- Dockerfile | 8 ++++++ install.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3733d91 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:18.04 + +RUN apt-get update && apt-get install -y build-essential pkg-config bison flex autoconf automake libtool make git python2.7 python-pip sqlite3 cmake git +RUN pip install flask flask-login pyserial +COPY . /workdir +RUN cd /workdir && ./install.sh docker +WORKDIR /workdir +ENTRYPOINT ["./start_openplc.sh"] diff --git a/install.sh b/install.sh index f820e2c..cf67bcd 100755 --- a/install.sh +++ b/install.sh @@ -220,6 +220,88 @@ WantedBy=multi-user.target" >> openplc.service cp ./start_openplc.sh ../../ +elif [ "$1" == "docker" ]; then + echo "Installing OpenPLC on Linux inside Docker" + + echo "" + echo "[MATIEC COMPILER]" + cd utils/matiec_src + autoreconf -i + ./configure + make + cp ./iec2c ../../webserver/ + if [ $? -ne 0 ]; then + echo "Error compiling MatIEC" + echo "OpenPLC was NOT installed!" + exit 1 + fi + cd ../.. + + echo "" + echo "[ST OPTIMIZER]" + cd utils/st_optimizer_src + g++ st_optimizer.cpp -o st_optimizer + cp ./st_optimizer ../../webserver/ + if [ $? -ne 0 ]; then + echo "Error compiling ST Optimizer" + echo "OpenPLC was NOT installed!" + exit 1 + fi + cd ../.. + + echo "" + echo "[GLUE GENERATOR]" + cd utils/glue_generator_src + g++ glue_generator.cpp -o glue_generator + cp ./glue_generator ../../webserver/core + if [ $? -ne 0 ]; then + echo "Error compiling Glue Generator" + echo "OpenPLC was NOT installed!" + exit 1 + fi + cd ../.. + + echo "" + echo "[OPEN DNP3]" + cd utils/dnp3_src + echo "creating swapfile..." + dd if=/dev/zero of=swapfile bs=1M count=1000 + mkswap swapfile + swapon swapfile + cmake ../dnp3_src + make + make install + if [ $? -ne 0 ]; then + echo "Error installing OpenDNP3" + echo "OpenPLC was NOT installed!" + exit 1 + fi + ldconfig + echo "removing swapfile..." + swapoff swapfile + rm -f ./swapfile + cd ../.. + + echo "" + echo "[LIBMODBUS]" + cd utils/libmodbus_src + ./autogen.sh + ./configure + make install + if [ $? -ne 0 ]; then + echo "Error installing Libmodbus" + echo "OpenPLC was NOT installed!" + exit 1 + fi + ldconfig + cd ../.. + + echo "" + echo "[FINALIZING]" + cd webserver/scripts + ./change_hardware_layer.sh blank_linux + ./compile_program.sh blank_program.st + cp ./start_openplc.sh ../../ elif [ "$1" == "rpi" ]; then echo "Installing OpenPLC on Raspberry Pi" From 6a95336a9deb446a083b552b2a656230816d45c1 Mon Sep 17 00:00:00 2001 From: T Date: Thu, 31 Jan 2019 23:38:16 +0100 Subject: [PATCH 2/3] Tested with Dockerfile --- Dockerfile | 4 ++-- README.md | 29 ++++++++++++------------ install.sh | 65 +++++++++++++++++++++++++++--------------------------- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3733d91..53a7043 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM ubuntu:18.04 +FROM debian -RUN apt-get update && apt-get install -y build-essential pkg-config bison flex autoconf automake libtool make git python2.7 python-pip sqlite3 cmake git +RUN apt-get update && apt-get install -y build-essential pkg-config bison flex autoconf automake libtool make git python2.7 python-pip sqlite3 cmake git RUN pip install flask flask-login pyserial COPY . /workdir RUN cd /workdir && ./install.sh docker diff --git a/README.md b/README.md index 7e8faf8..9d169c8 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,22 @@ The OpenPLC Project consists of three sub-projects: 1. [Runtime](https://github.com/thiagoralves/OpenPLC_v3) 2. [Programming editor](http://www.openplcproject.com/plcopen-editor) 3. [HMI builder](http://www.openplcproject.com/reference-installing-scadabr) -
+ To install: -
+```bash git clone https://github.com/thiagoralves/OpenPLC_v3.git -
cd OpenPLC_v3 -
./install.sh [platform] -
-where [platform] can be: -
-win - Install OpenPLC on Windows over Cygwin -
-linux - Install OpenPLC on a Debian-based Linux distribution -
-rpi - Install OpenPLC on a Raspberry Pi -
-custom - Skip all specific package installation and tries to install OpenPLC assuming your system already has all dependencies met. This option can be useful if you're trying to install OpenPLC on an unsuported Linux platform or had manually installed all the dependency packages before. +``` + +Where `[platform]` can be: + +`win` - Install OpenPLC on Windows over Cygwin + +`linux` - Install OpenPLC on a Debian-based Linux distribution + +`docker` - Used by the `Dockerfile` (i.e. doesn't invoke `sudo`) + +`rpi` - Install OpenPLC on a Raspberry Pi + +`custom` - Skip all specific package installation and tries to install OpenPLC assuming your system already has all dependencies met. This option can be useful if you're trying to install OpenPLC on an unsuported Linux platform or had manually installed all the dependency packages before. diff --git a/install.sh b/install.sh index cf67bcd..462b2c9 100755 --- a/install.sh +++ b/install.sh @@ -6,6 +6,7 @@ if [ $# -eq 0 ]; then echo "Usage: ./install.sh [platform] where [platform] can be" echo " win Install OpenPLC on Windows over Cygwin" echo " linux Install OpenPLC on a Debian-based Linux distribution" + echo " docker Install OpenPLC in a Docker container" echo " rpi Install OpenPLC on a Raspberry Pi" echo " neuron Install OpenPLC on a UniPi Neuron PLC" echo " custom Skip all specific package installation and tries to install" @@ -22,7 +23,7 @@ if [ "$1" == "win" ]; then cp ./utils/apt-cyg/apt-cyg ./ cp ./utils/apt-cyg/wget.exe /bin install apt-cyg /bin - apt-cyg install lynx + apt-cyg install lynx rm -f /bin/wget.exe apt-cyg install wget gcc-core gcc-g++ git pkg-config automake autoconf libtool make python2 python2-pip sqlite3 lynx -source https://bootstrap.pypa.io/get-pip.py > get-pip.py @@ -30,7 +31,7 @@ if [ "$1" == "win" ]; then pip install flask pip install flask-login pip install pyserial - + echo "" echo "[MATIEC COMPILER]" cp ./utils/matiec_src/bin_win32/*.* ./webserver/ @@ -39,7 +40,7 @@ if [ "$1" == "win" ]; then echo "OpenPLC was NOT installed!" exit 1 fi - + echo "" echo "[ST OPTIMIZER]" cd utils/st_optimizer_src @@ -51,7 +52,7 @@ if [ "$1" == "win" ]; then exit 1 fi cd ../.. - + echo "" echo "[GLUE GENERATOR]" cd utils/glue_generator_src @@ -63,7 +64,7 @@ if [ "$1" == "win" ]; then exit 1 fi cd ../.. - + echo "" echo "[OPEN DNP3]" cd webserver/core @@ -80,7 +81,7 @@ if [ "$1" == "win" ]; then exit 1 fi cd ../.. - + echo "" echo "[LIBMODBUS]" cd utils/libmodbus_src @@ -93,14 +94,14 @@ if [ "$1" == "win" ]; then exit 1 fi cd ../.. - + echo "" echo "[FINALIZING]" cd webserver/scripts ./change_hardware_layer.sh blank ./compile_program.sh blank_program.st cp ./start_openplc.sh ../../ - + elif [ "$1" == "linux" ]; then @@ -140,7 +141,7 @@ elif [ "$1" == "linux" ]; then exit 1 fi cd ../.. - + echo "" echo "[GLUE GENERATOR]" cd utils/glue_generator_src @@ -152,7 +153,7 @@ elif [ "$1" == "linux" ]; then exit 1 fi cd ../.. - + echo "" echo "[OPEN DNP3]" cd utils/dnp3_src @@ -173,7 +174,7 @@ elif [ "$1" == "linux" ]; then sudo swapoff swapfile sudo rm -f ./swapfile cd ../.. - + echo "" echo "[LIBMODBUS]" cd utils/libmodbus_src @@ -187,7 +188,7 @@ elif [ "$1" == "linux" ]; then fi sudo ldconfig cd ../.. - + echo "" echo "[OPENPLC SERVICE]" WORKING_DIR=$(pwd) @@ -218,8 +219,8 @@ WantedBy=multi-user.target" >> openplc.service ./change_hardware_layer.sh blank_linux ./compile_program.sh blank_program.st cp ./start_openplc.sh ../../ - - + + elif [ "$1" == "docker" ]; then echo "Installing OpenPLC on Linux inside Docker" @@ -248,7 +249,7 @@ elif [ "$1" == "docker" ]; then exit 1 fi cd ../.. - + echo "" echo "[GLUE GENERATOR]" cd utils/glue_generator_src @@ -260,7 +261,7 @@ elif [ "$1" == "docker" ]; then exit 1 fi cd ../.. - + echo "" echo "[OPEN DNP3]" cd utils/dnp3_src @@ -314,7 +315,7 @@ elif [ "$1" == "rpi" ]; then sudo -H pip install flask sudo -H pip install flask-login sudo -H pip install pyserial - + echo "" echo "[MATIEC COMPILER]" cd utils/matiec_src @@ -340,7 +341,7 @@ elif [ "$1" == "rpi" ]; then exit 1 fi cd ../.. - + echo "" echo "[GLUE GENERATOR]" cd utils/glue_generator_src @@ -352,7 +353,7 @@ elif [ "$1" == "rpi" ]; then exit 1 fi cd ../.. - + echo "" echo "[OPEN DNP3]" cd utils/dnp3_src @@ -373,7 +374,7 @@ elif [ "$1" == "rpi" ]; then sudo swapoff swapfile sudo rm -f ./swapfile cd ../.. - + echo "" echo "[LIBMODBUS]" cd utils/libmodbus_src @@ -387,7 +388,7 @@ elif [ "$1" == "rpi" ]; then fi sudo ldconfig cd ../.. - + echo "" echo "[OPENPLC SERVICE]" WORKING_DIR=$(pwd) @@ -458,7 +459,7 @@ elif [ "$1" == "neuron" ]; then exit 1 fi cd ../.. - + echo "" echo "[GLUE GENERATOR]" cd utils/glue_generator_src @@ -470,7 +471,7 @@ elif [ "$1" == "neuron" ]; then exit 1 fi cd ../.. - + echo "" echo "[OPEN DNP3]" cd utils/dnp3_src @@ -491,7 +492,7 @@ elif [ "$1" == "neuron" ]; then sudo swapoff swapfile sudo rm -f ./swapfile cd ../.. - + echo "" echo "[LIBMODBUS]" cd utils/libmodbus_src @@ -505,16 +506,16 @@ elif [ "$1" == "neuron" ]; then fi sudo ldconfig cd ../.. - + echo "" - echo "[DISABLING UNIPI SERVICES]" + echo "[DISABLING UNIPI SERVICES]" sudo systemctl stop neuronhost.service sudo systemctl disable neuronhost.service sudo systemctl stop neurontcp.service sudo systemctl disable neurontcp.service sudo systemctl stop evok.service sudo systemctl disable evok.service - + echo "" echo "[OPENPLC SERVICE]" WORKING_DIR=$(pwd) @@ -550,7 +551,7 @@ WantedBy=multi-user.target" >> openplc.service elif [ "$1" == "custom" ]; then echo "Installing OpenPLC on Custom Platform" - + echo "" echo "[MATIEC COMPILER]" cd utils/matiec_src @@ -576,7 +577,7 @@ elif [ "$1" == "custom" ]; then exit 1 fi cd ../.. - + echo "" echo "[GLUE GENERATOR]" cd utils/glue_generator_src @@ -588,7 +589,7 @@ elif [ "$1" == "custom" ]; then exit 1 fi cd ../.. - + echo "" echo "[OPEN DNP3]" cd utils/dnp3_src @@ -609,7 +610,7 @@ elif [ "$1" == "custom" ]; then sudo swapoff swapfile sudo rm -f ./swapfile cd ../.. - + echo "" echo "[LIBMODBUS]" cd utils/libmodbus_src @@ -623,7 +624,7 @@ elif [ "$1" == "custom" ]; then fi sudo ldconfig cd ../.. - + echo "" echo "[FINALIZING]" cd webserver/scripts From ae7028b6f68871308aef492deb36b48122f7f585 Mon Sep 17 00:00:00 2001 From: T Date: Thu, 31 Jan 2019 23:46:19 +0100 Subject: [PATCH 3/3] update README with Docker instructions --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d169c8..62277d0 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The OpenPLC Project consists of three sub-projects: 2. [Programming editor](http://www.openplcproject.com/plcopen-editor) 3. [HMI builder](http://www.openplcproject.com/reference-installing-scadabr) -To install: +## Installation: ```bash git clone https://github.com/thiagoralves/OpenPLC_v3.git cd OpenPLC_v3 @@ -23,3 +23,20 @@ Where `[platform]` can be: `rpi` - Install OpenPLC on a Raspberry Pi `custom` - Skip all specific package installation and tries to install OpenPLC assuming your system already has all dependencies met. This option can be useful if you're trying to install OpenPLC on an unsuported Linux platform or had manually installed all the dependency packages before. + +### Building, Installing and Running inside Docker +Make sure [`docker` is installed](https://docs.docker.com/install/linux/docker-ce/ubuntu/) + +#### Build +``` +# instead of running install.sh as stated above, run: +docker build -t openplc:v3 . +``` + +#### RUN +_Devices can be passed to the `docker` daemon using the `-v` flag (e.g. `-v /dev/ttyACM0:/dev/ttyACM0`)_ + +```bash +docker run -it --rm -p 8080:8080 openplc:v3 +``` +