Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade docker python module #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions nginx-ingress/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
FROM nginx:1.21.6-alpine
FROM nginx:1.25.0-alpine

RUN apk add --update --no-cache python3 curl bash openssl && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt\
&& rm -rf ./requirements.txt
RUN pip3 install --no-cache-dir docker jinja2
ENV DOCKER_HOST "unix:///var/run/docker.sock"
ENV UPDATE_INTERVAL "30"
ENV DNS_UPDATE_INTERVAL "5"
Expand Down
32 changes: 16 additions & 16 deletions nginx-ingress/ingress/ingress.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from docker import Client
import docker
from jinja2 import Template

import os, socket
Expand Down Expand Up @@ -59,10 +59,10 @@ def resolve_pattern(format):
with open(nginx_config_template_path, 'r') as handle:
nginx_config_template = handle.read()

cli = Client(base_url = os.environ['DOCKER_HOST'])
d_cli = docker.DockerClient(base_url=os.environ['DOCKER_HOST'])

while True:
services = cli.services()
services = d_cli.services.list()

services_list = []
for service in services:
Expand All @@ -75,31 +75,31 @@ def resolve_pattern(format):
alt_virtual_host = ''
service_port = 80
service_name = ''
service_id = service.get('ID','')
service_id = service.id

# issue 15
certificate_name = None

if service['Spec'].get('Labels'):
if service['Spec']['Labels'].get('ingress.host'):
if service.attrs['Spec'].get('Labels'):
if service.attrs['Spec']['Labels'].get('ingress.host'):
http_config = True
virtual_host = service['Spec']['Labels'].get('ingress.host')
alt_virtual_host = service['Spec']['Labels'].get('ingress.alt_host','')
service_port = service['Spec']['Labels'].get('ingress.port', 80)
service_name = service['Spec'].get('Name')
virtual_host = service.attrs['Spec']['Labels'].get('ingress.host')
alt_virtual_host = service.attrs['Spec']['Labels'].get('ingress.alt_host','')
service_port = service.attrs['Spec']['Labels'].get('ingress.port', 80)
service_name = service.attrs['Spec'].get('Name')

if service['Spec']['Labels'].get('ingress.ssl') and service['Spec']['Labels'].get('ingress.ssl_redirect'):
if service.attrs['Spec']['Labels'].get('ingress.ssl') and service.attrs['Spec']['Labels'].get('ingress.ssl_redirect'):
https_config = True
https_redirect = True
elif service['Spec']['Labels'].get('ingress.ssl'):
elif service.attrs['Spec']['Labels'].get('ingress.ssl'):
https_config = True
https_redirect = False

if service['Spec']['Labels'].get('ingress.virtual_proto'):
virtual_proto = service['Spec']['Labels'].get('ingress.virtual_proto', 'http')
if service.attrs['Spec']['Labels'].get('ingress.virtual_proto'):
virtual_proto = service.attrs['Spec']['Labels'].get('ingress.virtual_proto', 'http')

if service['Spec']['Labels'].get('ingress.certificate_name'):
certificate_name = service['Spec']['Labels'].get('ingress.certificate_name')
if service.attrs['Spec']['Labels'].get('ingress.certificate_name'):
certificate_name = service.attrs['Spec']['Labels'].get('ingress.certificate_name')

out = {
'http_config': http_config,
Expand Down
6 changes: 0 additions & 6 deletions nginx-ingress/requirements.txt

This file was deleted.