diff --git a/MANIFEST.in b/MANIFEST.in index 9163c3d7..ac702393 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ recursive-include platypush/backend/http/webapp/dist * +recursive-include platypush/install * include platypush/plugins/http/webpage/mercury-parser.js include platypush/config/*.yaml global-include manifest.yaml diff --git a/platypush/install/docker/alpine.Dockerfile b/platypush/install/docker/alpine.Dockerfile new file mode 100644 index 00000000..4f2d0ed0 --- /dev/null +++ b/platypush/install/docker/alpine.Dockerfile @@ -0,0 +1,14 @@ +FROM alpine +ADD . /install +WORKDIR /var/lib/platypush + +RUN DOCKER_CTX=1 /install/platypush/install/scripts/alpine/install.sh +RUN cd /install && pip install -U --no-input --no-cache-dir . +RUN rm -rf /install + +EXPOSE 8008 + +VOLUME /etc/platypush +VOLUME /var/lib/platypush + +CMD /run.sh diff --git a/platypush/install/docker/debian.Dockerfile b/platypush/install/docker/debian.Dockerfile new file mode 100644 index 00000000..42e8e324 --- /dev/null +++ b/platypush/install/docker/debian.Dockerfile @@ -0,0 +1,18 @@ +FROM debian +ADD . /install +WORKDIR /var/lib/platypush + +RUN apt update +RUN DOCKER_CTX=1 /install/platypush/install/scripts/debian/install.sh +RUN cd /install && pip install -U --no-input --no-cache-dir . +RUN rm -rf /install +RUN apt autoclean -y +RUN apt autoremove -y +RUN apt clean + +EXPOSE 8008 + +VOLUME /etc/platypush +VOLUME /var/lib/platypush + +CMD /run.sh diff --git a/platypush/install/docker/ubuntu.Dockerfile b/platypush/install/docker/ubuntu.Dockerfile new file mode 100644 index 00000000..79cbca6e --- /dev/null +++ b/platypush/install/docker/ubuntu.Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu +ADD . /install +WORKDIR /var/lib/platypush + +RUN apt update +RUN DOCKER_CTX=1 /install/platypush/install/scripts/debian/install.sh +RUN cd /install && pip install -U --no-input --no-cache-dir . +RUN rm -rf /install +RUN apt autoclean -y +RUN apt autoremove -y +RUN apt clean + +EXPOSE 8008 + +VOLUME /etc/platypush +VOLUME /var/lib/platypush + +CMD /run.sh diff --git a/platypush/install/requirements/alpine.txt b/platypush/install/requirements/alpine.txt new file mode 100644 index 00000000..e9f2b477 --- /dev/null +++ b/platypush/install/requirements/alpine.txt @@ -0,0 +1,26 @@ +python3 +py3-pip +py3-alembic +py3-bcrypt +py3-dateutil +py3-docutils +py3-flask +py3-frozendict +py3-greenlet +py3-magic +py3-mypy-extensions +py3-psutil +py3-redis +py3-requests +py3-rsa +py3-sqlalchemy +py3-tornado +py3-typing-extensions +py3-tz +py3-websocket-client +py3-websockets +py3-wheel +py3-yaml +py3-zeroconf +redis +sudo diff --git a/platypush/install/requirements/arch.txt b/platypush/install/requirements/arch.txt new file mode 100644 index 00000000..cc1a45ea --- /dev/null +++ b/platypush/install/requirements/arch.txt @@ -0,0 +1,24 @@ +python +python-alembic +python-bcrypt +python-dateutil +python-docutils +python-flask +python-frozendict +python-magic +python-marshmallow +python-pip +python-psutil +python-pytz +python-redis +python-requests +python-rsa +python-sqlalchemy +python-tornado +python-websocket-client +python-websockets +python-wheel +python-yaml +python-zeroconf +redis +sudo diff --git a/platypush/install/requirements/debian.txt b/platypush/install/requirements/debian.txt new file mode 100644 index 00000000..d7fdd1aa --- /dev/null +++ b/platypush/install/requirements/debian.txt @@ -0,0 +1,28 @@ +python3 +python3-pip +python3-alembic +python3-bcrypt +python3-dateutil +python3-docutils +python3-flask +python3-frozendict +python3-greenlet +python3-magic +python3-marshmallow +python3-mypy-extensions +python3-psutil +python3-redis +python3-requests +python3-rsa +python3-sqlalchemy +python3-tornado +python3-typing-extensions +python3-typing-inspect +python3-tz +python3-websocket +python3-websockets +python3-wheel +python3-yaml +python3-zeroconf +redis +sudo diff --git a/platypush/install/requirements/ubuntu.txt b/platypush/install/requirements/ubuntu.txt new file mode 120000 index 00000000..22a908cb --- /dev/null +++ b/platypush/install/requirements/ubuntu.txt @@ -0,0 +1 @@ +debian.txt \ No newline at end of file diff --git a/platypush/install/scripts/alpine/PKGCMD b/platypush/install/scripts/alpine/PKGCMD new file mode 100644 index 00000000..eba0c3d5 --- /dev/null +++ b/platypush/install/scripts/alpine/PKGCMD @@ -0,0 +1 @@ +apk add --update --no-interactive --no-cache diff --git a/platypush/install/scripts/alpine/install.sh b/platypush/install/scripts/alpine/install.sh new file mode 120000 index 00000000..3f44f994 --- /dev/null +++ b/platypush/install/scripts/alpine/install.sh @@ -0,0 +1 @@ +../install.sh \ No newline at end of file diff --git a/platypush/install/scripts/arch/PKGCMD b/platypush/install/scripts/arch/PKGCMD new file mode 100644 index 00000000..6d32b41e --- /dev/null +++ b/platypush/install/scripts/arch/PKGCMD @@ -0,0 +1 @@ +pacman -S --noconfirm diff --git a/platypush/install/scripts/arch/install.sh b/platypush/install/scripts/arch/install.sh new file mode 120000 index 00000000..3f44f994 --- /dev/null +++ b/platypush/install/scripts/arch/install.sh @@ -0,0 +1 @@ +../install.sh \ No newline at end of file diff --git a/platypush/install/scripts/debian/PKGCMD b/platypush/install/scripts/debian/PKGCMD new file mode 100644 index 00000000..0b313dee --- /dev/null +++ b/platypush/install/scripts/debian/PKGCMD @@ -0,0 +1 @@ +DEBIAN_FRONTEND=noninteractive apt install -y diff --git a/platypush/install/scripts/debian/install.sh b/platypush/install/scripts/debian/install.sh new file mode 120000 index 00000000..3f44f994 --- /dev/null +++ b/platypush/install/scripts/debian/install.sh @@ -0,0 +1 @@ +../install.sh \ No newline at end of file diff --git a/platypush/install/scripts/docker-run.sh b/platypush/install/scripts/docker-run.sh new file mode 100755 index 00000000..9a0a81b4 --- /dev/null +++ b/platypush/install/scripts/docker-run.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# This script is used as a default entry point for Docker containers + +DOCKER_CTX=1 platypush \ + --start-redis \ + --config /etc/platypush/config.yaml \ + --workdir /var/lib/platypush diff --git a/platypush/install/scripts/install.sh b/platypush/install/scripts/install.sh new file mode 100755 index 00000000..106745a5 --- /dev/null +++ b/platypush/install/scripts/install.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# This script parses the system requirements for a specific OS and it runs the +# appropriate package manager command to install them. + +# This script is usually symlinked in the folders of the individual operating +# systems, and it's not supposed to be invoked directly. +# Instead, it will be called either by the root install.sh script or by a +# Dockerfile. + +SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +OS="$(basename "$SCRIPT_PATH")" +CMD="$(cat "${SCRIPT_PATH}/PKGCMD")" +REQUIREMENTS="$(cat "${SCRIPT_PATH}/../../requirements/${OS}.txt" | tr '\n' ' ')" +SUDO= + +# If we are running in a Docker context then we want to copy the docker-run.sh +# script where we can easily find it. +if [ -n "$DOCKER_CTX" ]; then + cp -v /install/platypush/install/scripts/docker-run.sh /run.sh +fi + +# If we aren't running in a Docker context, or the user is not root, we should +# use sudo to install system packages. +if [[ "$(id -u)" != "0" ]] || [ -z "$DOCKER_CTX" ]; then + if ! type sudo >/dev/null; then + echo "sudo executable not found, I can't install system packages" >&2 + exit 1 + fi + + SUDO="sudo" +fi + +${SUDO_ARGS} ${CMD} ${REQUIREMENTS} diff --git a/platypush/install/scripts/ubuntu b/platypush/install/scripts/ubuntu new file mode 120000 index 00000000..b2f7fd3e --- /dev/null +++ b/platypush/install/scripts/ubuntu @@ -0,0 +1 @@ +debian \ No newline at end of file diff --git a/platypush/platydock/__init__.py b/platypush/platydock/__init__.py index 2f49d3cb..084b9956 100755 --- a/platypush/platydock/__init__.py +++ b/platypush/platydock/__init__.py @@ -21,6 +21,7 @@ class BaseImage(Enum): """ ALPINE = 'alpine' + DEBIAN = 'debian' UBUNTU = 'ubuntu' def __str__(self) -> str: @@ -30,6 +31,7 @@ class BaseImage(Enum): return self.value +# pylint: disable=too-few-public-methods class DockerfileGenerator: """ Generate a Dockerfile from on a configuration file. @@ -40,6 +42,7 @@ class DockerfileGenerator: _pkg_manager_by_base_image = { BaseImage.ALPINE: PackageManagers.APK, + BaseImage.DEBIAN: PackageManagers.APT, BaseImage.UBUNTU: PackageManagers.APT, } @@ -54,6 +57,8 @@ class DockerfileGenerator: :param cfgfile: Path to the configuration file. :return: The content of the generated Dockerfile. """ + import platypush + Config.init(self.cfgfile) new_file_lines = [] ports = self._get_exposed_ports() @@ -66,7 +71,8 @@ class DockerfileGenerator: is_after_expose_cmd = False base_file = os.path.join( - str(pathlib.Path(inspect.getfile(Config)).parent), + str(pathlib.Path(inspect.getfile(platypush)).parent), + 'install', 'docker', f'{self.image}.Dockerfile', )