diff --git a/Dockerfile.py b/Dockerfile.py index 2953bc3..946b675 100755 --- a/Dockerfile.py +++ b/Dockerfile.py @@ -22,16 +22,6 @@ import sys import subprocess from dotenv import dotenv_values -FTL_VERSION = None - - -def read_pihole_versions(): - global FTL_VERSION - dot = os.path.abspath('.') - config = dotenv_values('{}/VERSIONS'.format(dot)) - FTL_VERSION = config['FTL_VERSION'].replace('/','-') - - def build_dockerfiles(args) -> bool: all_success = True if args['-v']: @@ -64,14 +54,16 @@ def run_and_stream_command_output(command, environment_vars, verbose) -> bool: def build(docker_repo: str, arch: str, debian_version: str, hub_tag: str, show_time: bool, no_cache: bool, verbose: bool) -> bool: - create_tag = f'{docker_repo}:{FTL_VERSION}-{arch}-{debian_version}' + # remove the `pihole/pihole:` from hub_tag for use elsewhere + tag_name = hub_tag.split(":",1)[1] + create_tag = f'{docker_repo}:{tag_name}' print(f' ::: Building {create_tag}') time_arg = 'time' if show_time else '' cache_arg = '--no-cache' if no_cache else '' build_env = os.environ.copy() - build_env['PIHOLE_VERSION'] = FTL_VERSION + build_env['PIHOLE_VERSION'] = os.environ.get('GIT_TAG', None) build_env['DEBIAN_VERSION'] = debian_version - build_env['PIHOLE_TAG'] = hub_tag + build_env['PIHOLE_TAG'] = tag_name build_command = f'{time_arg} docker-compose -f build.yml build {cache_arg} --pull {arch}' print(f' ::: Building {arch} into {create_tag}') success = run_and_stream_command_output(build_command, build_env, verbose) @@ -86,7 +78,6 @@ def build(docker_repo: str, arch: str, debian_version: str, hub_tag: str, show_t if __name__ == '__main__': args = docopt(__doc__, version='Dockerfile 1.1') - read_pihole_versions() success = build_dockerfiles(args) exit_code = 0 if success else 1 sys.exit(exit_code) diff --git a/gh-actions-test.sh b/gh-actions-test.sh index b4ab996..6d603ae 100755 --- a/gh-actions-test.sh +++ b/gh-actions-test.sh @@ -25,6 +25,7 @@ docker run --rm \ --env ARCH="${ARCH}" \ --env ARCH_IMAGE="${ARCH_IMAGE}" \ --env DEBIAN_VERSION="${DEBIAN_VERSION}" \ + --env GIT_TAG="${GIT_TAG}" \ ${enter} image_pipenv mkdir -p ".gh-workspace/${DEBIAN_VERSION}/" diff --git a/test/conftest.py b/test/conftest.py index a938e1f..ec5bbfb 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -3,29 +3,18 @@ import os import pytest import subprocess import testinfra -from dotenv import dotenv_values local_host = testinfra.get_host('local://') check_output = local_host.check_output DEBIAN_VERSION = os.environ.get('DEBIAN_VERSION', 'buster') -FTL_VERSION = None - - -@pytest.fixture(autouse=True) -def read_pihole_versions(): - global FTL_VERSION - dotdot = os.path.abspath(os.path.join(os.path.abspath(__file__), os.pardir, os.pardir)) - config = dotenv_values('{}/VERSIONS'.format(dotdot)) - FTL_VERSION = config['FTL_VERSION'].replace('/','-') - @pytest.fixture() def run_and_stream_command_output(): def run_and_stream_command_output_inner(command, verbose=False): print("Running", command) build_env = os.environ.copy() - build_env['PIHOLE_VERSION'] = FTL_VERSION + build_env['PIHOLE_VERSION'] = version build_result = subprocess.Popen(command.split(), env=build_env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) if verbose: @@ -101,7 +90,7 @@ def arch(request): @pytest.fixture() def version(): - return FTL_VERSION + return os.environ.get('GIT_TAG', None) @pytest.fixture() def debian_version(): @@ -132,7 +121,7 @@ def persist_arch(): @pytest.fixture(scope='module') def persist_version(): - return FTL_VERSION + return version @pytest.fixture(scope='module') def persist_debian_version():