From d21f187673ac43f4a602013326a744df1b833515 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 16 Nov 2020 00:34:51 +0100 Subject: [PATCH] outposts: make docker image prefix configurable --- helm/templates/configmap.yaml | 1 + helm/values.yaml | 1 + passbook/lib/default.yml | 3 +++ passbook/outposts/controllers/docker.py | 9 +++++---- passbook/outposts/controllers/k8s/deployment.py | 6 +++--- website/docs/installation/kubernetes.md | 1 + 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml index c165bdd2d..d52565469 100644 --- a/helm/templates/configmap.yaml +++ b/helm/templates/configmap.yaml @@ -18,3 +18,4 @@ data: ERROR_REPORTING__ENVIRONMENT: "{{ .Values.config.errorReporting.environment }}" ERROR_REPORTING__SEND_PII: "{{ .Values.config.errorReporting.sendPii }}" LOG_LEVEL: "{{ .Values.config.logLevel }}" + OUTPOSTS__DOCKER_IMAGE_BASE: "{{ .Values.image.name_outposts }}" diff --git a/helm/values.yaml b/helm/values.yaml index 7bbbbc6f7..95bd92e25 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -4,6 +4,7 @@ image: name: beryju/passbook name_static: beryju/passbook-static + name_outposts: beryju/passbook # Prefix used for Outpost deployments, Outpost type and version is appended tag: 0.12.11-stable serverReplicas: 1 diff --git a/passbook/lib/default.yml b/passbook/lib/default.yml index c06f55b3c..91196b35b 100644 --- a/passbook/lib/default.yml +++ b/passbook/lib/default.yml @@ -21,6 +21,9 @@ error_reporting: environment: customer send_pii: false +outposts: + docker_image_base: "beryju/passbook" # this is prepended to -proxy:version + passbook: avatars: gravatar # gravatar or none branding: diff --git a/passbook/outposts/controllers/docker.py b/passbook/outposts/controllers/docker.py index c98be2b99..6dbce6e87 100644 --- a/passbook/outposts/controllers/docker.py +++ b/passbook/outposts/controllers/docker.py @@ -9,6 +9,7 @@ from docker.models.containers import Container from yaml import safe_dump from passbook import __version__ +from passbook.lib.config import CONFIG from passbook.outposts.controllers.base import BaseController, ControllerException from passbook.outposts.models import ( DockerServiceConnection, @@ -25,8 +26,6 @@ class DockerController(BaseController): container: Container connection: DockerServiceConnection - image_base = "beryju/passbook" - def __init__(self, outpost: Outpost, connection: DockerServiceConnection) -> None: super().__init__(outpost, connection) try: @@ -62,7 +61,8 @@ class DockerController(BaseController): return self.client.containers.get(container_name), False except NotFound: self.logger.info("Container does not exist, creating") - image_name = f"{self.image_base}-{self.outpost.type}:{__version__}" + image_prefix = CONFIG.y("outposts.docker_image_base") + image_name = f"{image_prefix}-{self.outpost.type}:{__version__}" self.client.images.pull(image_name) return ( self.client.containers.create( @@ -137,11 +137,12 @@ class DockerController(BaseController): def get_static_deployment(self) -> str: """Generate docker-compose yaml for proxy, version 3.5""" ports = [f"{x}:{x}" for _, x in self.deployment_ports.items()] + image_prefix = CONFIG.y("outposts.docker_image_base") compose = { "version": "3.5", "services": { f"passbook_{self.outpost.type}": { - "image": f"{self.image_base}-{self.outpost.type}:{__version__}", + "image": f"{image_prefix}-{self.outpost.type}:{__version__}", "ports": ports, "environment": { "PASSBOOK_HOST": self.outpost.config.passbook_host, diff --git a/passbook/outposts/controllers/k8s/deployment.py b/passbook/outposts/controllers/k8s/deployment.py index 9b87a4842..a3c66a209 100644 --- a/passbook/outposts/controllers/k8s/deployment.py +++ b/passbook/outposts/controllers/k8s/deployment.py @@ -17,6 +17,7 @@ from kubernetes.client import ( ) from passbook import __version__ +from passbook.lib.config import CONFIG from passbook.outposts.controllers.k8s.base import ( KubernetesObjectReconciler, NeedsUpdate, @@ -30,8 +31,6 @@ if TYPE_CHECKING: class DeploymentReconciler(KubernetesObjectReconciler[V1Deployment]): """Kubernetes Deployment Reconciler""" - image_base = "beryju/passbook" - outpost: Outpost def __init__(self, controller: "KubernetesController") -> None: @@ -68,6 +67,7 @@ class DeploymentReconciler(KubernetesObjectReconciler[V1Deployment]): container_ports.append(V1ContainerPort(container_port=port, name=port_name)) meta = self.get_object_meta(name=self.name) secret_name = f"passbook-outpost-{self.controller.outpost.uuid.hex}-api" + image_prefix = CONFIG.y("outposts.docker_image_base") return V1Deployment( metadata=meta, spec=V1DeploymentSpec( @@ -79,7 +79,7 @@ class DeploymentReconciler(KubernetesObjectReconciler[V1Deployment]): containers=[ V1Container( name=str(self.outpost.type), - image=f"{self.image_base}-{self.outpost.type}:{__version__}", + image=f"{image_prefix}-{self.outpost.type}:{__version__}", ports=container_ports, env=[ V1EnvVar( diff --git a/website/docs/installation/kubernetes.md b/website/docs/installation/kubernetes.md index 957b32425..cba4a5fe1 100644 --- a/website/docs/installation/kubernetes.md +++ b/website/docs/installation/kubernetes.md @@ -13,6 +13,7 @@ This installation automatically applies database migrations on startup. After th image: name: beryju/passbook name_static: beryju/passbook-static + name_outposts: beryju/passbook # Prefix used for Outpost deployments, Outpost type and version is appended tag: 0.12.11-stable serverReplicas: 1