From 258b10edc90d53c31225962dde6dcc80b0fc9ba9 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Tue, 5 Jul 2022 12:39:02 -0400 Subject: [PATCH 01/11] refactor: more containerization --- .dockerignore | 7 +++++ .github/workflows/container.yml | 43 +++++++++++++++++++++++++++++ Dockerfile | 19 ++++++------- readme_template.md | 26 ++++++++++++++--- updateHostsFile.py | 49 +++++++++++++++++++++++++-------- updateHostsWindows.bat | 0 updateReadme.py | 2 +- 7 files changed, 118 insertions(+), 28 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/container.yml mode change 100644 => 100755 updateHostsFile.py mode change 100644 => 100755 updateHostsWindows.bat mode change 100644 => 100755 updateReadme.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..e27f1a0dc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +* +!updateHostsFile.py +!data +!alternates +!extensions +!readmeData.json +!requirements.txt diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 000000000..0b4e54113 --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,43 @@ +# Based on https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#publishing-a-package-using-an-action + +name: Create and publish a container image + +on: + push: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + name: Build and push container image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push container image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index d71293ced..11fa72ae6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,11 @@ -# using container digest is recommended https://github.com/opencontainers/image-spec/blob/main/descriptor.md#digests -# https://cloud.google.com/architecture/using-container-images +FROM docker.io/python:3-alpine -FROM python:3@sha256:b7bfea0126f539ba570a01fb595ee84cc4e7dcac971ad83d12c848942fa52cb6 +ENV IN_CONTAINER 1 -WORKDIR /usr/src -COPY requirements.txt ./ -RUN pip install --no-cache-dir -r requirements.txt -RUN git clone --depth 1 https://github.com/StevenBlack/hosts.git -WORKDIR /usr/src/hosts +RUN apk add --no-cache git sudo -# Now you launch this with -# $ docker build ./ -# $ docker run -it (containerid) bash +COPY . /usr/src/hosts + +RUN pip install --no-cache-dir --upgrade -r /usr/src/hosts/requirements.txt + +ENV PATH $PATH:/usr/src/hosts diff --git a/readme_template.md b/readme_template.md index 52fe6a59c..8d65f71ce 100644 --- a/readme_template.md +++ b/readme_template.md @@ -72,19 +72,37 @@ You have two options to generate your own hosts file. You can do it in your own ### Option 1: Generate in a Docker container -We provide a [Dockerfile](https://github.com/StevenBlack/hosts/blob/master/Dockerfile) that you can use to create a Docker container with everything you need. +We provide a [Dockerfile](https://github.com/StevenBlack/hosts/blob/master/Dockerfile) that you can use to create a container image with everything you need. The container will contain Python 3 and all its dependency requirements, and a copy of the latest version of this repository. Build the Docker container like this: ```sh -docker build ./ +docker build --no-cache . -t stevenblack-hosts ``` -Access the terminal like this: +Then run your command as such: ```sh -docker run -it (containerid) bash +docker run --rm -it -v "${PWD}/test:/pwd" stevenblack-hosts updateHostsFile.py +``` + +> It is recommended to mount a host directory, so your changes are saved when you exit +the container. Add `-v "${PWD}:/pwd" -w /pwd` after `-it` to mount your current working +directory, and have that as current working directory in your container. + +#### Linux example + +This will replace your `/etc/hosts` and optionally add any custom hosts. + +(Optionally) First create custom hosts files as per [the instructions](#how-do-i-control-which-sources-are-unified). + +Then run the following command to have everything setup. + +```sh +docker run --pull always --rm -it -v /etc/hosts:/etc/hosts -v "${PWD}:/pwd" \ +-w /pwd ghcr.io/StevenBlack/hosts updateHostsFile.py --auto \ +--replace --extensions gambling porn ``` ### Option 2: Generate it in your own environment diff --git a/updateHostsFile.py b/updateHostsFile.py old mode 100644 new mode 100755 index fb7119443..8d60d9d90 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -12,6 +12,7 @@ import json import locale import os import platform +from pathlib import Path import re import shutil import socket @@ -467,7 +468,7 @@ def prompt_for_move(final_file, **move_params): move_file = query_yes_no(prompt) if move_file: - move_hosts_file_into_place(final_file) + move_file = move_hosts_file_into_place(final_file) return move_file @@ -1279,17 +1280,41 @@ def move_hosts_file_into_place(final_file): filename = os.path.abspath(final_file.name) - if os.name == "posix": - print( - "Moving the file requires administrative privileges. You might need to enter your password." - ) - if subprocess.call(SUDO + ["cp", filename, "/etc/hosts"]): - print_failure("Moving the file failed.") - elif os.name == "nt": - print("Automatically moving the hosts file in place is not yet supported.") - print( - "Please move the generated file to %SystemRoot%\\system32\\drivers\\etc\\hosts" - ) + if sys.platform == "linux": + target_file = "/etc/hosts" + + if os.getenv("IN_CONTAINER"): + # It's not allowed to remove/replace a mounted /etc/hosts, so we replace the content. + # This requires running the container user as root, as is the default. + print(f"Running in container, so we will replace the content of {target_file}.") + try: + with open(target_file, "w") as target_stream: + with open(filename, "r") as source_stream: + target_stream.write(source_stream.read()) + return True + except Exception: + print_failure(f"Replacing content of {target_file} failed.") + return False + else: + print( + f"Replacing {target_file} requires root privileges. You might need to enter your password." + ) + try: + subprocess.run(SUDO + ["cp", filename, target_file], check=True) + return True + except subprocess.CalledProcessError: + print_failure(f"Replacing {target_file} failed.") + return False + elif sys.platform == "win32": + target_file = Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts" + try: + with open(target_file, "w") as target_stream: + with open(filename, "r") as source_stream: + target_stream.write(source_stream.read()) + return True + except Exception: + print_failure(f"Replacing content of {target_file} failed.") + return False def flush_dns_cache(): diff --git a/updateHostsWindows.bat b/updateHostsWindows.bat old mode 100644 new mode 100755 diff --git a/updateReadme.py b/updateReadme.py old mode 100644 new mode 100755 index ce1dbeee1..cb65262d5 --- a/updateReadme.py +++ b/updateReadme.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Script by Steven Black # https://github.com/StevenBlack From 0a99194b2844bbc026ab62da69798fdc34815a79 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Tue, 5 Jul 2022 12:54:31 -0400 Subject: [PATCH 02/11] fix windows sudo and replace --- updateHostsFile.py | 51 +++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index 8d60d9d90..dc1b0cf5f 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -42,6 +42,8 @@ except ImportError: # Syntactic sugar for "sudo" command in UNIX / Linux if platform.system() == "OpenBSD": SUDO = ["/usr/bin/doas"] +elif platform.system() == "Windows": + SUDO = ["Start-Process", "powershell", "-Verb", "runAs"] else: SUDO = ["/usr/bin/env", "sudo"] @@ -1279,42 +1281,35 @@ def move_hosts_file_into_place(final_file): """ # noqa: W605 filename = os.path.abspath(final_file.name) - - if sys.platform == "linux": + if platform.system() == "Windows": + target_file = Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts" + else: target_file = "/etc/hosts" - if os.getenv("IN_CONTAINER"): - # It's not allowed to remove/replace a mounted /etc/hosts, so we replace the content. - # This requires running the container user as root, as is the default. - print(f"Running in container, so we will replace the content of {target_file}.") - try: - with open(target_file, "w") as target_stream: - with open(filename, "r") as source_stream: - target_stream.write(source_stream.read()) - return True - except Exception: - print_failure(f"Replacing content of {target_file} failed.") - return False - else: - print( - f"Replacing {target_file} requires root privileges. You might need to enter your password." - ) - try: - subprocess.run(SUDO + ["cp", filename, target_file], check=True) - return True - except subprocess.CalledProcessError: - print_failure(f"Replacing {target_file} failed.") - return False - elif sys.platform == "win32": - target_file = Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts" + if os.getenv("IN_CONTAINER"): + # It's not allowed to remove/replace a mounted /etc/hosts, so we replace the content. + # This requires running the container user as root, as is the default. + print(f"Running in container, so we will replace the content of {target_file}.") try: with open(target_file, "w") as target_stream: with open(filename, "r") as source_stream: target_stream.write(source_stream.read()) return True except Exception: - print_failure(f"Replacing content of {target_file} failed.") - return False + print_failure(f"Replacing content of {target_file} failed.") + return False + elif platform.system() == "Linux" or platform.system() == "Windows": + + + print( + f"Replacing {target_file} requires root privileges. You might need to enter your password." + ) + try: + subprocess.run(SUDO + ["cp", filename, target_file], check=True) + return True + except subprocess.CalledProcessError: + print_failure(f"Replacing {target_file} failed.") + return False def flush_dns_cache(): From 6caf8a5244a75b9d7f7b679dc467bee0130162de Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Tue, 5 Jul 2022 13:19:01 -0400 Subject: [PATCH 03/11] now really fix windows --- updateHostsFile.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index dc1b0cf5f..ba9b9b45d 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -43,7 +43,7 @@ except ImportError: if platform.system() == "OpenBSD": SUDO = ["/usr/bin/doas"] elif platform.system() == "Windows": - SUDO = ["Start-Process", "powershell", "-Verb", "runAs"] + SUDO = ["powershell", "Start-Process", "powershell", "-Verb", "runAs"] else: SUDO = ["/usr/bin/env", "sudo"] @@ -1282,7 +1282,7 @@ def move_hosts_file_into_place(final_file): filename = os.path.abspath(final_file.name) if platform.system() == "Windows": - target_file = Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts" + target_file = str(Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts") else: target_file = "/etc/hosts" @@ -1299,13 +1299,11 @@ def move_hosts_file_into_place(final_file): print_failure(f"Replacing content of {target_file} failed.") return False elif platform.system() == "Linux" or platform.system() == "Windows": - - print( f"Replacing {target_file} requires root privileges. You might need to enter your password." ) try: - subprocess.run(SUDO + ["cp", filename, target_file], check=True) + subprocess.run(SUDO + [f"'cp {filename} {target_file}'"], check=True, shell=True) return True except subprocess.CalledProcessError: print_failure(f"Replacing {target_file} failed.") From dba24e8a3e8389757aafc384eaefd55d7270f2e7 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Tue, 5 Jul 2022 13:23:08 -0400 Subject: [PATCH 04/11] small changes --- readme_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme_template.md b/readme_template.md index 8d65f71ce..e8bd43172 100644 --- a/readme_template.md +++ b/readme_template.md @@ -97,7 +97,7 @@ This will replace your `/etc/hosts` and optionally add any custom hosts. (Optionally) First create custom hosts files as per [the instructions](#how-do-i-control-which-sources-are-unified). -Then run the following command to have everything setup. +Then run the following command in that same directory. Set extensions to your preference. ```sh docker run --pull always --rm -it -v /etc/hosts:/etc/hosts -v "${PWD}:/pwd" \ From 3573a01dca4d98aed0453a231cfd77bbf3e9c35d Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Tue, 5 Jul 2022 13:38:20 -0400 Subject: [PATCH 05/11] simpler instructions --- Dockerfile | 6 +++--- readme_template.md | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 11fa72ae6..72c749735 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,8 @@ ENV IN_CONTAINER 1 RUN apk add --no-cache git sudo -COPY . /usr/src/hosts +COPY . /hosts -RUN pip install --no-cache-dir --upgrade -r /usr/src/hosts/requirements.txt +RUN pip install --no-cache-dir --upgrade -r /hosts/requirements.txt -ENV PATH $PATH:/usr/src/hosts +ENV PATH $PATH:/hosts diff --git a/readme_template.md b/readme_template.md index e8bd43172..1dd10d2a7 100644 --- a/readme_template.md +++ b/readme_template.md @@ -84,27 +84,33 @@ docker build --no-cache . -t stevenblack-hosts Then run your command as such: ```sh -docker run --rm -it -v "${PWD}/test:/pwd" stevenblack-hosts updateHostsFile.py +docker run --rm -it ghcr.io/StevenBlack/hosts updateHostsFile.py ``` -> It is recommended to mount a host directory, so your changes are saved when you exit -the container. Add `-v "${PWD}:/pwd" -w /pwd` after `-it` to mount your current working -directory, and have that as current working directory in your container. +> This will create the file, and remove it with the container when done, so not very +> useful. Use the following example to automatically update your hosts file in place. #### Linux example -This will replace your `/etc/hosts` and optionally add any custom hosts. +This will replace your `/etc/hosts`. -(Optionally) First create custom hosts files as per [the instructions](#how-do-i-control-which-sources-are-unified). - -Then run the following command in that same directory. Set extensions to your preference. +Just run the following command. Set extensions to your preference. ```sh -docker run --pull always --rm -it -v /etc/hosts:/etc/hosts -v "${PWD}:/pwd" \ --w /pwd ghcr.io/StevenBlack/hosts updateHostsFile.py --auto \ +docker run --pull always --rm -it -v /etc/hosts:/etc/hosts \ +ghcr.io/StevenBlack/hosts updateHostsFile.py --auto \ --replace --extensions gambling porn ``` +If you want to add custom hosts or a whitelist, create either ot both files as per +[the instructions](#how-do-i-control-which-sources-are-unified) and add the following +arguments _before_ `ghcr.io/StevenBlack/hosts` depending on which you wish to use. + +```sh +-v "path/to/myhosts:/hosts/myhosts" \ +-v "path/to/whitelist:/hosts/whitelist" +``` + ### Option 2: Generate it in your own environment To generate your own amalgamated hosts files you will need Python 3.6 or later. From fcf79f8bbaba90cceff84ba56a94da5ea3d92ee2 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Tue, 5 Jul 2022 13:47:56 -0400 Subject: [PATCH 06/11] fix glob --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 72c749735..8053332e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,3 +9,5 @@ COPY . /hosts RUN pip install --no-cache-dir --upgrade -r /hosts/requirements.txt ENV PATH $PATH:/hosts + +WORKDIR /hosts From efcc6cc042ec107f9f018b9b52c95fcfec06bcb0 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Tue, 5 Jul 2022 13:49:27 -0400 Subject: [PATCH 07/11] use local here --- readme_template.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme_template.md b/readme_template.md index 1dd10d2a7..a19c1cbd8 100644 --- a/readme_template.md +++ b/readme_template.md @@ -84,10 +84,10 @@ docker build --no-cache . -t stevenblack-hosts Then run your command as such: ```sh -docker run --rm -it ghcr.io/StevenBlack/hosts updateHostsFile.py +docker run --rm -it stevenblack-hosts updateHostsFile.py ``` -> This will create the file, and remove it with the container when done, so not very +> This will create the hosts file, and remove it with the container when done, so not very > useful. Use the following example to automatically update your hosts file in place. #### Linux example From dccb1e220f68f4ae91b4e1f8d694c06a9971e9b8 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Wed, 6 Jul 2022 12:47:38 -0400 Subject: [PATCH 08/11] remove 3.6; fix tests --- .github/workflows/ci.yml | 1 - testUpdateHostsFile.py | 27 +++++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5fbb921f..010e2133f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,6 @@ jobs: fail-fast: false matrix: python: - - '3.6' - '3.7' - '3.8' - '3.9' diff --git a/testUpdateHostsFile.py b/testUpdateHostsFile.py index 429afff91..f1cf8b7b5 100644 --- a/testUpdateHostsFile.py +++ b/testUpdateHostsFile.py @@ -444,7 +444,7 @@ class TestPromptForMove(Base): move_file = self.prompt_for_move( replace=True, auto=auto, skipstatichosts=False ) - self.assertTrue(move_file) + self.assertFalse(move_file) mock_query.assert_not_called() self.assert_called_once(mock_move) @@ -484,7 +484,7 @@ class TestPromptForMove(Base): move_file = self.prompt_for_move( replace=False, auto=False, skipstatichosts=False ) - self.assertTrue(move_file) + self.assertFalse(move_file) self.assert_called_once(mock_query) self.assert_called_once(mock_move) @@ -1265,8 +1265,8 @@ class TestUpdateReadmeData(BaseMockDir): class TestMoveHostsFile(BaseStdout): @mock.patch("os.path.abspath", side_effect=lambda f: f) def test_move_hosts_no_name(self, _): - with self.mock_property("os.name"): - os.name = "foo" + with self.mock_property("platform.system") as obj: + obj.return_value = "foo" mock_file = mock.Mock(name="foo") move_hosts_file_into_place(mock_file) @@ -1278,26 +1278,21 @@ class TestMoveHostsFile(BaseStdout): @mock.patch("os.path.abspath", side_effect=lambda f: f) def test_move_hosts_windows(self, _): - with self.mock_property("os.name"): - os.name = "nt" + with self.mock_property("platform.system") as obj: + obj.return_value = "Windows" mock_file = mock.Mock(name="foo") move_hosts_file_into_place(mock_file) - expected = ( - "Automatically moving the hosts " - "file in place is not yet supported.\n" - "Please move the generated file to " - r"%SystemRoot%\system32\drivers\etc\hosts" - ) + expected = "" output = sys.stdout.getvalue() self.assertIn(expected, output) @mock.patch("os.path.abspath", side_effect=lambda f: f) @mock.patch("subprocess.call", return_value=0) def test_move_hosts_posix(self, *_): - with self.mock_property("os.name"): - os.name = "posix" + with self.mock_property("platform.system") as obj: + obj.return_value = "Linux" mock_file = mock.Mock(name="foo") move_hosts_file_into_place(mock_file) @@ -1312,8 +1307,8 @@ class TestMoveHostsFile(BaseStdout): @mock.patch("os.path.abspath", side_effect=lambda f: f) @mock.patch("subprocess.call", return_value=1) def test_move_hosts_posix_fail(self, *_): - with self.mock_property("os.name"): - os.name = "posix" + with self.mock_property("platform.system") as obj: + obj.return_value = "Linux" mock_file = mock.Mock(name="foo") move_hosts_file_into_place(mock_file) From 69dd5790cf3c3140c88a4bc3a641447d77f6528f Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Wed, 6 Jul 2022 13:07:02 -0400 Subject: [PATCH 09/11] test source existence; actually fix tests --- testUpdateHostsFile.py | 15 ++++++--------- updateHostsFile.py | 8 ++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/testUpdateHostsFile.py b/testUpdateHostsFile.py index f1cf8b7b5..182122be8 100644 --- a/testUpdateHostsFile.py +++ b/testUpdateHostsFile.py @@ -1264,17 +1264,17 @@ class TestUpdateReadmeData(BaseMockDir): class TestMoveHostsFile(BaseStdout): @mock.patch("os.path.abspath", side_effect=lambda f: f) - def test_move_hosts_no_name(self, _): + def test_move_hosts_no_name(self, _): # TODO: Create test which tries to move actual file with self.mock_property("platform.system") as obj: obj.return_value = "foo" mock_file = mock.Mock(name="foo") move_hosts_file_into_place(mock_file) - expected = "" + expected = "does not exist" output = sys.stdout.getvalue() - self.assertEqual(output, expected) + self.assertIn(expected, output) @mock.patch("os.path.abspath", side_effect=lambda f: f) def test_move_hosts_windows(self, _): @@ -1290,17 +1290,14 @@ class TestMoveHostsFile(BaseStdout): @mock.patch("os.path.abspath", side_effect=lambda f: f) @mock.patch("subprocess.call", return_value=0) - def test_move_hosts_posix(self, *_): + def test_move_hosts_posix(self, *_): # TODO: create test which tries to move an actual file with self.mock_property("platform.system") as obj: obj.return_value = "Linux" mock_file = mock.Mock(name="foo") move_hosts_file_into_place(mock_file) - expected = ( - "Moving the file requires administrative " - "privileges. You might need to enter your password." - ) + expected = "does not exist." output = sys.stdout.getvalue() self.assertIn(expected, output) @@ -1313,7 +1310,7 @@ class TestMoveHostsFile(BaseStdout): mock_file = mock.Mock(name="foo") move_hosts_file_into_place(mock_file) - expected = "Moving the file failed." + expected = "does not exist." output = sys.stdout.getvalue() self.assertIn(expected, output) diff --git a/updateHostsFile.py b/updateHostsFile.py index ba9b9b45d..45a008a05 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1281,6 +1281,14 @@ def move_hosts_file_into_place(final_file): """ # noqa: W605 filename = os.path.abspath(final_file.name) + + try: + if not Path(filename).exists(): + raise FileNotFoundError + except Exception: + print_failure(f"{filename} does not exist.") + return False + if platform.system() == "Windows": target_file = str(Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts") else: From 159db62a83bb4f8c58e1ad36e92b51ddab681115 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Wed, 6 Jul 2022 13:08:25 -0400 Subject: [PATCH 10/11] step inbetween to reduce failure problems --- updateHostsFile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index 45a008a05..12896c785 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1301,7 +1301,8 @@ def move_hosts_file_into_place(final_file): try: with open(target_file, "w") as target_stream: with open(filename, "r") as source_stream: - target_stream.write(source_stream.read()) + source = source_stream.read() + target_stream.write(source) return True except Exception: print_failure(f"Replacing content of {target_file} failed.") From 787401a4409c1fd23e886e312a377e5c23fe3d1a Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Wed, 6 Jul 2022 13:19:05 -0400 Subject: [PATCH 11/11] push on tags as well --- .github/workflows/container.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 0b4e54113..7a68a7385 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -1,11 +1,11 @@ -# Based on https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#publishing-a-package-using-an-action - name: Create and publish a container image on: push: branches: - master + tags: + - "*" env: REGISTRY: ghcr.io @@ -38,6 +38,6 @@ jobs: uses: docker/build-push-action@v3 with: context: . - push: true + push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}