Deploy python3 virtualenvs only.

This commit is contained in:
Antoine Nguyen
2019-12-06 12:18:01 +01:00
parent 851a0f2bb1
commit 63c29c34b9
8 changed files with 25 additions and 13 deletions

View File

@@ -46,7 +46,7 @@ class DEBPackage(Package):
def install_many(self, names): def install_many(self, names):
"""Install many packages.""" """Install many packages."""
self.update() self.update()
utils.exec_cmd("apt-get install --quiet --assume-yes {}".format( return utils.exec_cmd("apt-get install --quiet --assume-yes {}".format(
" ".join(names))) " ".join(names)))
def get_installed_version(self, name): def get_installed_version(self, name):
@@ -76,7 +76,7 @@ class RPMPackage(Package):
def install_many(self, names): def install_many(self, names):
"""Install many packages.""" """Install many packages."""
utils.exec_cmd("yum install -y --quiet {}".format(" ".join(names))) return utils.exec_cmd("yum install -y --quiet {}".format(" ".join(names)))
def get_installed_version(self, name): def get_installed_version(self, name):
"""Get installed package version.""" """Get installed package version."""

View File

@@ -60,8 +60,8 @@ def setup_virtualenv(path, sudo_user=None, python_version=2):
packages.append("virtualenv") packages.append("virtualenv")
else: else:
if utils.dist_name().startswith("centos"): if utils.dist_name().startswith("centos"):
python_binary = "python36" python_binary = "python3"
packages = ["python36"] packages = ["python3"]
else: else:
python_binary = "python3" python_binary = "python3"
packages = ["python3-venv"] packages = ["python3-venv"]

View File

@@ -55,7 +55,8 @@ class Automx(base.Installer):
def _setup_venv(self): def _setup_venv(self):
"""Prepare a python virtualenv.""" """Prepare a python virtualenv."""
python.setup_virtualenv(self.venv_path, sudo_user=self.user) python.setup_virtualenv(
self.venv_path, sudo_user=self.user, python_version=3)
packages = [ packages = [
"future", "lxml", "ipaddress", "sqlalchemy", "python-memcached", "future", "lxml", "ipaddress", "sqlalchemy", "python-memcached",
"python-dateutil", "configparser" "python-dateutil", "configparser"

View File

@@ -1,6 +1,7 @@
"""Base classes.""" """Base classes."""
import os import os
import sys
from .. import database from .. import database
from .. import package from .. import package
@@ -107,7 +108,10 @@ class Installer(object):
packages = self.get_packages() packages = self.get_packages()
if not packages: if not packages:
return return
package.backend.install_many(packages) exitcode, output = package.backend.install_many(packages)
if exitcode:
utils.printcolor("Failed to install dependencies", utils.RED)
sys.exit(1)
def get_config_files(self): def get_config_files(self):
"""Return the list of configuration files to copy.""" """Return the list of configuration files to copy."""

View File

@@ -1,7 +1,7 @@
[uwsgi] [uwsgi]
uid = %app_user uid = %app_user
gid = %app_user gid = %app_user
plugins = python plugins = %uwsgi_plugin
home = %app_venv_path home = %app_venv_path
chdir = %app_instance_path chdir = %app_instance_path
module = automx_wsgi module = automx_wsgi

View File

@@ -1,7 +1,7 @@
[uwsgi] [uwsgi]
uid = %app_user uid = %app_user
gid = %app_user gid = %app_user
plugins = python plugins = %uwsgi_plugin
home = %app_venv_path home = %app_venv_path
chdir = %app_instance_path chdir = %app_instance_path
module = instance.wsgi:application module = instance.wsgi:application
@@ -12,3 +12,4 @@ no-default-app = true
socket = %uwsgi_socket_path socket = %uwsgi_socket_path
chmod-socket = 660 chmod-socket = 660
vacuum = true vacuum = true
single-interpreter = True

View File

@@ -22,12 +22,12 @@ class Modoboa(base.Installer):
no_daemon = True no_daemon = True
packages = { packages = {
"deb": [ "deb": [
"build-essential", "python-dev", "libxml2-dev", "libxslt-dev", "build-essential", "python3-dev", "libxml2-dev", "libxslt-dev",
"libjpeg-dev", "librrd-dev", "rrdtool", "libffi-dev", "cron", "libjpeg-dev", "librrd-dev", "rrdtool", "libffi-dev", "cron",
"libssl-dev" "libssl-dev"
], ],
"rpm": [ "rpm": [
"gcc", "gcc-c++", "python-devel", "libxml2-devel", "libxslt-devel", "gcc", "gcc-c++", "python3-devel", "libxml2-devel", "libxslt-devel",
"libjpeg-turbo-devel", "rrdtool-devel", "rrdtool", "libffi-devel", "libjpeg-turbo-devel", "rrdtool-devel", "rrdtool", "libffi-devel",
] ]
} }
@@ -67,7 +67,8 @@ class Modoboa(base.Installer):
def _setup_venv(self): def _setup_venv(self):
"""Prepare a dedicated virtualenv.""" """Prepare a dedicated virtualenv."""
python.setup_virtualenv(self.venv_path, sudo_user=self.user) python.setup_virtualenv(
self.venv_path, sudo_user=self.user, python_version=3)
packages = ["rrdtool"] packages = ["rrdtool"]
version = self.config.get("modoboa", "version") version = self.config.get("modoboa", "version")
if version == "latest": if version == "latest":

View File

@@ -16,8 +16,8 @@ class Uwsgi(base.Installer):
appname = "uwsgi" appname = "uwsgi"
packages = { packages = {
"deb": ["uwsgi", "uwsgi-plugin-python"], "deb": ["uwsgi", "uwsgi-plugin-python3"],
"rpm": ["uwsgi", "uwsgi-plugin-python2"], "rpm": ["uwsgi", "uwsgi-plugin-python36"],
} }
def get_socket_path(self, app): def get_socket_path(self, app):
@@ -29,12 +29,17 @@ class Uwsgi(base.Installer):
def get_template_context(self, app): def get_template_context(self, app):
"""Additionnal variables.""" """Additionnal variables."""
context = super(Uwsgi, self).get_template_context() context = super(Uwsgi, self).get_template_context()
if package.backend.FORMAT == "deb":
uwsgi_plugin = "python3"
else:
uwsgi_plugin = "python36"
context.update({ context.update({
"app_user": self.config.get(app, "user"), "app_user": self.config.get(app, "user"),
"app_venv_path": self.config.get(app, "venv_path"), "app_venv_path": self.config.get(app, "venv_path"),
"app_instance_path": ( "app_instance_path": (
self.config.get(app, "instance_path")), self.config.get(app, "instance_path")),
"uwsgi_socket_path": self.get_socket_path(app), "uwsgi_socket_path": self.get_socket_path(app),
"uwsgi_plugin": uwsgi_plugin,
}) })
return context return context