outposts: fallback to known-good outpost image if configured image cannot be pulled

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-10-07 19:10:39 +02:00
parent 956382b682
commit 649abddea7
2 changed files with 16 additions and 4 deletions

View File

@ -90,14 +90,24 @@ class DockerController(BaseController):
return True return True
return False return False
def try_pull_image(self):
"""Try to pull the image needed for this outpost based on the CONFIG `outposts.docker_image_base`,
but fall back to known-good images"""
image = self.get_container_image()
try:
self.client.images.pull(image)
except DockerException:
image = f"ghcr.io/goauthentik/{self.outpost.type}:latest"
self.client.images.pull(image)
return image
def _get_container(self) -> tuple[Container, bool]: def _get_container(self) -> tuple[Container, bool]:
container_name = f"authentik-proxy-{self.outpost.uuid.hex}" container_name = f"authentik-proxy-{self.outpost.uuid.hex}"
try: try:
return self.client.containers.get(container_name), False return self.client.containers.get(container_name), False
except NotFound: except NotFound:
self.logger.info("(Re-)creating container...") self.logger.info("(Re-)creating container...")
image_name = self.get_container_image() image_name = self.try_pull_image()
self.client.images.pull(image_name)
container_args = { container_args = {
"image": image_name, "image": image_name,
"name": container_name, "name": container_name,
@ -135,11 +145,12 @@ class DockerController(BaseController):
# Check if the container is out of date, delete it and retry # Check if the container is out of date, delete it and retry
if len(container.image.tags) > 0: if len(container.image.tags) > 0:
tag: str = container.image.tags[0] tag: str = container.image.tags[0]
if tag != self.get_container_image(): should_image = self.try_pull_image()
if tag != should_image:
self.logger.info( self.logger.info(
"Container has mismatched image, re-creating...", "Container has mismatched image, re-creating...",
has=tag, has=tag,
should=self.get_container_image(), should=should_image,
) )
self.down() self.down()
return self.up(depth + 1) return self.up(depth + 1)

View File

@ -1,5 +1,6 @@
"""Write stage logic""" """Write stage logic"""
from typing import Any from typing import Any
from django.contrib import messages from django.contrib import messages
from django.contrib.auth import update_session_auth_hash from django.contrib.auth import update_session_auth_hash
from django.db import transaction from django.db import transaction