thiagoralves / OpenPLC_Editor

OpenPLC Editor - IDE capable of creating programs for the OpenPLC Runtime
GNU General Public License v2.0
387 stars 191 forks source link

Docker image to handle the old Python #19

Open dcihlar opened 3 years ago

dcihlar commented 3 years ago

On the newer systems the old Python 2 is now completely gone, so installing the current OpenPLC Editor is a hassle.

I propose a Docker image as a workaround until the editor is ported to Python 3:

FROM debian:buster

RUN apt-get update && \
    apt-get install -y \
        sudo curl python-pip apt-utils coreutils vim-gtk dbus-x11 bash-completion \
        build-essential pkg-config bison flex autoconf automake libtool make git \
        libssl-dev python2 python-wxgtk3.0 python2-dev libpng-dev libfreetype6-dev

# password = user
RUN mkdir -p /etc/skel/.local/share/applications && \
    mkdir -p /root/.local/share/applications && \
    useradd user --uid 1000 -p aaBrLCcg4bKmQ --groups sudo --create-home

RUN git clone --depth 1 --single-branch https://github.com/thiagoralves/OpenPLC_Editor.git && \
    cd OpenPLC_Editor && \
    ./install.sh && \
    mv openplc_editor.sh /usr/local/bin/openplc-editor

USER user
ENV HOME=/home/user
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user/.local/bin
ENV LANG=en_US.utf8
WORKDIR /home/user

CMD openplc-editor

Build it with:

docker build -t openplc .

And run with:

#!/bin/bash
mkdir -p data # this is where projects can be saved
docker run \
    --env="DISPLAY" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    --volume="$(pwd)/data:/home/user/data" \
    openplc
ALTracer commented 2 years ago

@dcihlar, can you please rewrite the Dockerfile to use multi-stage builds?

Target image should not have to carry build dependencies (autotools, git, python2-dev, libfreetype6-dev, libpng-dev) once the builder image completed installing the runtime dependencies. While FROM debian:buster is 110MB, the very next RUN adds 880MB of packages (without issuing apt-get clean), and RUN install.sh adds some 360MB more. The resulting build is 1.36 GB for a single tool (Beremiz/wxpython+matiec+gcc)

My Docker-fu is not strong enough :smile:

ALTracer commented 2 years ago

Okay, I rewrote it myself. Dropped 1.36GiB to 1.18GiB image on latest debian:buster by removing a bunch of -dev packages. Multi-stage builds are not an option since install.sh uses pip to build some packages and OpenPLC requires gcc at runtime.

Looks working on my machine (GUI, PLC compilation, local debugging). The bulid and run commands are the same.

FROM debian:buster

RUN apt-get update && apt-get install -y --no-install-recommends \
        apt-utils coreutils curl bash-completion git python2 sudo
# Compilers for matiec and pip
RUN apt-get install -y --no-install-recommends \
        build-essential pkg-config bison flex autoconf automake libtool \
        gcc make libc-dev
# Python -dev and pip
RUN apt-get install -y --no-install-recommends \
        python-pip python2-dev python-all-dev python-setuptools python-wheel \
        libssl-dev libxml2-dev libxslt1-dev libssl1.1 libxml2 libxslt1.1
# Graphics
RUN apt-get install -y --no-install-recommends \
        python-wxgtk3.0 dbus-x11 libpng16-16 \
        libpng-dev libfreetype6-dev

# password = user
RUN mkdir -p /etc/skel/.local/share/applications && \
    mkdir -p /root/.local/share/applications && \
    useradd user --uid 1000 -p aaBrLCcg4bKmQ --groups sudo --create-home

RUN git clone --depth 1 --single-branch https://github.com/thiagoralves/OpenPLC_Editor.git
RUN cd /OpenPLC_Editor && ./install.sh && \
    cd /OpenPLC_Editor/matiec && make mostlyclean && \
    mv /OpenPLC_Editor/openplc_editor.sh /usr/local/bin/openplc-editor

RUN apt-get remove -y \
        build-essential autoconf automake libtool bison flex pkg-config git \
        python-pip python2-dev python-all-dev \
        libssl-dev libpng-dev libfreetype6-dev && \
    apt-get autoremove -y && \
    rm -rf /var/lib/apt/lists/*

USER user
ENV HOME=/home/user
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user/.local/bin
ENV LANG=en_US.utf8
WORKDIR /home/user

CMD openplc-editor
vinimlo commented 1 year ago

Works very well!! I would love to see this dockerfile on the main branch!