Bring GIT_TAG into the build environment for use as PIHOLE_VERSION in the container.

Remove the `pihole/pihole:` part of the PIHOLE_TAG in the python script (see #920)

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner 2021-09-12 12:04:59 +01:00
parent 1a7bfdc2ee
commit 6cec6f937f
No known key found for this signature in database
GPG Key ID: 872950F3ECF2B173
3 changed files with 9 additions and 28 deletions

View File

@ -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)

View File

@ -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}/"

View File

@ -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():