diff --git a/.github/workflows/build-packages.yml b/.github/workflows/build-packages.yml deleted file mode 100644 index 17c479d3ceae5ebcf369167d7053b7e3dbae69d9..0000000000000000000000000000000000000000 --- a/.github/workflows/build-packages.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Build Packages -on: [push] -jobs: - Debian: - runs-on: ubuntu-latest - container: - image: debian:latest - steps: - - name: Install fpm - run: | - apt-get update - apt-get install -y ruby ruby-dev rubygems build-essential python3-simplejson python3-pkg-resources python3-setuptools - gem install fpm - - name: Check out repository code - uses: actions/checkout@v3 - - name: Build package - run: fpm -s python -t deb --python-bin=python3 --deb-systemd systemd-resolved-docker.service setup.py - - name: Save artifact - uses: actions/upload-artifact@v3 - with: - name: Debian package - path: | - *.deb - - Fedora: - runs-on: ubuntu-latest - container: - image: fedora:latest - steps: - - name: Install tito - run: dnf install -y tito python3-devel - - name: Check out repository code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: List contents - run: git config --global --add safe.directory $(pwd) - - name: Build package - run: tito build --rpm --offline --test - - name: Save artifacts - uses: actions/upload-artifact@v3 - with: - name: RPM package - path: | - /tmp/tito/noarch/*.rpm \ No newline at end of file diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000000000000000000000000000000000000..7aa430ab90bb667ffec4c07dae7f98c426ffa9b1 --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,93 @@ +name: Build Packages +on: [ push ] +jobs: + build-deb: + name: Build DEB package + runs-on: ubuntu-22.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 \ + --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 + path: | + *.deb + + build-rpm: + name: Build RPM package + runs-on: ubuntu-22.04 + container: + image: fedora:latest + steps: + - name: Install tito + run: dnf install -y tito python3-devel + - name: Check out repository code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: List contents + run: git config --global --add safe.directory $(pwd) + - name: Build package + run: tito build --rpm --offline --test + - name: Save artifacts + uses: actions/upload-artifact@v3 + with: + name: RPM package + path: | + /tmp/tito/noarch/*.rpm + + tests: + name: Run tests + runs-on: ubuntu-22.04 + steps: + - name: Check out repository code + uses: actions/checkout@v3 + - name: Install packages + run: | + sudo apt-get update + sudo apt-get install -y python3 python3-docker python3-dnslib python3-dbus python3-pyroute2 python3-systemd + - name: Run tests + run: sudo python3 -m unittest + + test-deb: + name: Test DEB package + runs-on: ubuntu-22.04 + needs: + - build-deb + steps: + - name: Download DEB package + uses: actions/download-artifact@master + with: + name: DEB package + path: /tmp + - run: ls -lash /tmp + - name: Install package + run: sudo apt install /tmp/python-systemd-resolved-docker_*.deb + - name: Start service + run: sudo systemctl start systemd-resolved-docker + - 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 diff --git a/.gitignore b/.gitignore index 79c7cf3e6986aefb7246fe5db470688e6713f9f5..1acef6558342611d1e66095e843532519155eb02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /dist *.egg-info __pycache__ +_trial_temp diff --git a/debian/systemd-resolved-docker.service b/debian/systemd-resolved-docker.service new file mode 100644 index 0000000000000000000000000000000000000000..0dd4bf82934491ca00241b52d6e0c65b7b134418 --- /dev/null +++ b/debian/systemd-resolved-docker.service @@ -0,0 +1,14 @@ +[Unit] +Description=systemd-resolved and docker DNS integration +Requires=docker.service systemd-resolved.service +After=docker.service systemd-resolved.service +BindsTo=docker.service systemd-resolved.service + +[Service] +Type=notify +Environment=PYTHONUNBUFFERED=1 +ExecStart=/usr/local/bin/systemd-resolved-docker +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/src/systemd_resolved_docker/utils.py b/src/systemd_resolved_docker/utils.py index a46e6d1e7f100cfc1cae036f40e4fef720875f5b..8ecc78094449ce3fc8029bdc5b48eb48f8df93fc 100644 --- a/src/systemd_resolved_docker/utils.py +++ b/src/systemd_resolved_docker/utils.py @@ -61,11 +61,12 @@ def find_default_docker_bridge_gateway(cli): def create_dummy_interface(interface, ip_addresses): with NDB(log='on') as ndb: - nbd_if = ndb.interfaces.create(ifname=interface, kind="dummy").set(state="up") + nbd_if = ndb.interfaces.create(ifname=interface, kind="dummy") for ip_address in ip_addresses: nbd_if = nbd_if.add_ip("%s/%s" % ( ip_address.ip.exploded, "32" if isinstance(ip_address.ip, ipaddress.IPv4Address) else "128")) + nbd_if.set('state', 'up') nbd_if.commit()