diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7aa430ab90bb667ffec4c07dae7f98c426ffa9b1..5d04081a7bab6a42827108a75f1d1283551fd261 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,8 +1,42 @@ name: Build Packages on: [ push ] jobs: - build-deb: - name: Build DEB package + build-deb-20-04: + name: Build DEB package (Ubuntu 20.04) + runs-on: ubuntu-20.04 + steps: + - name: Install fpm + run: | + sudo apt-get update + sudo apt-get install -y ruby ruby-dev rubygems build-essential python3-simplejson python3-pkg-resources python3-setuptools + sudo gem install fpm + - name: Check out repository code + uses: actions/checkout@v3 + - name: Build package + run: > + fpm --input-type python \ + --output-type deb \ + --python-bin=python3 \ + --python-install-bin /usr/bin \ + --python-install-lib $(python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())') \ + --deb-systemd debian/systemd-resolved-docker.service \ + --no-auto-depends \ + --depends python3-docker \ + --depends python3-dnslib \ + --depends python3-dbus \ + --depends python3-pyroute2 \ + --depends python3-systemd \ + --depends systemd \ + setup.py + - name: Save artifact + uses: actions/upload-artifact@v3 + with: + name: DEB package (Ubuntu 20.04) + path: | + *.deb + + build-deb-22-04: + name: Build DEB package (Ubuntu 22.04) runs-on: ubuntu-22.04 steps: - name: Install fpm @@ -17,6 +51,7 @@ jobs: fpm --input-type python \ --output-type deb \ --python-bin=python3 \ + --python-install-bin /usr/bin \ --deb-systemd debian/systemd-resolved-docker.service \ --no-auto-depends \ --depends python3-docker \ @@ -29,7 +64,7 @@ jobs: - name: Save artifact uses: actions/upload-artifact@v3 with: - name: DEB package + name: DEB package (Ubuntu 22.04) path: | *.deb @@ -69,18 +104,39 @@ jobs: - name: Run tests run: sudo python3 -m unittest - test-deb: - name: Test DEB package + test-deb-20-04: + name: Test DEB package (Ubuntu 20.04) + runs-on: ubuntu-20.04 + needs: + - build-deb-20-04 + steps: + - name: Download DEB package + uses: actions/download-artifact@master + with: + name: DEB package (Ubuntu 20.04) + path: /tmp + - name: Install package + run: sudo apt install /tmp/python-systemd-resolved-docker_*.deb + - name: Start service + run: sudo systemctl start systemd-resolved-docker || (journalctl -xe && false) + - name: Start continaer + run: docker run --detach --interactive --hostname test-container alpine + - name: resolvectl status + run: resolvectl status + - name: Test Query + run: resolvectl query test-container.docker + + test-deb-22-04: + name: Test DEB package (Ubuntu 22.04) runs-on: ubuntu-22.04 needs: - - build-deb + - build-deb-22-04 steps: - name: Download DEB package uses: actions/download-artifact@master with: - name: DEB package + name: DEB package (Ubuntu 22.04) path: /tmp - - run: ls -lash /tmp - name: Install package run: sudo apt install /tmp/python-systemd-resolved-docker_*.deb - name: Start service diff --git a/debian/systemd-resolved-docker.service b/debian/systemd-resolved-docker.service index 0dd4bf82934491ca00241b52d6e0c65b7b134418..33d5c9471f45ddb60d9ac46c7d28fa18098b87a8 100644 --- a/debian/systemd-resolved-docker.service +++ b/debian/systemd-resolved-docker.service @@ -7,7 +7,7 @@ BindsTo=docker.service systemd-resolved.service [Service] Type=notify Environment=PYTHONUNBUFFERED=1 -ExecStart=/usr/local/bin/systemd-resolved-docker +ExecStart=/usr/bin/systemd-resolved-docker Restart=on-failure [Install] diff --git a/src/systemd_resolved_docker/resolvedconnector.py b/src/systemd_resolved_docker/resolvedconnector.py index 96e51ba526be4486cc04bc29333c89ef4533f171..cb88c2baa0475af30fb4ab4202f7e9cdbf20d295 100644 --- a/src/systemd_resolved_docker/resolvedconnector.py +++ b/src/systemd_resolved_docker/resolvedconnector.py @@ -40,20 +40,35 @@ class SystemdResolvedConnector: self.interface, self.dns_domains, ", ".join(map(lambda x: str(x), self.listen_addresses)))) domains = [[domain.strip("."), True] for domain in self.dns_domains] - ips = [ - [ - AF_INET if isinstance(ip_port.ip, ipaddress.IPv4Address) else AF_INET6, - ip_port.ip.packed, - ip_port.port, - "", + + try: + ips = [ + [ + AF_INET if isinstance(ip_port.ip, ipaddress.IPv4Address) else AF_INET6, + ip_port.ip.packed, + ip_port.port, + "", + ] + for ip_port in self.listen_addresses ] - for ip_port in self.listen_addresses - ] - manager = self.if_manager() - manager.SetLinkDNSEx(self.ifindex, ips) - manager.SetLinkDNSSEC(self.ifindex, "no") - manager.SetLinkDomains(self.ifindex, domains) + manager = self.if_manager() + manager.SetLinkDNSEx(self.ifindex, ips) + manager.SetLinkDNSSEC(self.ifindex, "no") + manager.SetLinkDomains(self.ifindex, domains) + except Exception as ex: + ips = [ + [ + AF_INET if isinstance(ip_port.ip, ipaddress.IPv4Address) else AF_INET6, + ip_port.ip.packed + ] + for ip_port in self.listen_addresses + ] + + manager = self.if_manager() + manager.SetLinkDNS(self.ifindex, ips) + manager.SetLinkDNSSEC(self.ifindex, "no") + manager.SetLinkDomains(self.ifindex, domains) def unregister(self): self.handler.log("Unregistering with systemd-resolved: %s" % self.interface)