Test image name updates, passing locally. reorg Dockerfile to build fast, starting on new deploy

Signed-off-by: Adam Hill <adam@diginc.us>
This commit is contained in:
Adam Hill 2018-08-04 13:31:58 -05:00
parent 6e15abd002
commit 80d5b9dbc1
No known key found for this signature in database
GPG Key ID: 2193804FCA429855
8 changed files with 92 additions and 94 deletions

View File

@ -90,12 +90,8 @@ def build_dockerfiles(args):
return
for arch in args['--arch']:
docker_repo = 'pi-hole-multiarch'
if arch == 'amd64':
docker_repo = 'pi-hole'
# TODO make version an argument, or auto-detect branch for non production tags
build(docker_repo, 'v4.0', arch, args)
# TODO: include from external .py that can be shared with Dockerfile.py / Tests / deploy scripts '''
build('pihole', 'v4.0', arch, args)
def build(docker_repo, version, arch, args):

View File

@ -1,13 +1,5 @@
FROM {{ pihole.base }}
LABEL image="{{ pihole.name }}:{{ pihole.version }}_{{ pihole.arch }}"
LABEL maintainer="{{ pihole.maintainer }}"
LABEL url="https://www.github.com/pi-hole/docker-pi-hole"
ENV VERSION {{ pihole.version }}
ENV ARCH {{ pihole.arch }}
ENV PATH /opt/pihole:${PATH}
COPY install.sh /usr/local/bin/docker-install.sh
ENV PIHOLE_INSTALL /root/ph_install.sh
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/{{ pihole.s6_version }}/s6-overlay-{{ pihole.s6arch }}.tar.gz
@ -44,6 +36,14 @@ ENV S6_KEEP_ENV 1
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2
ENV FTL_CMD no-daemon
ENV VERSION {{ pihole.version }}
ENV ARCH {{ pihole.arch }}
ENV PATH /opt/pihole:${PATH}
LABEL image="{{ pihole.name }}:{{ pihole.version }}_{{ pihole.arch }}"
LABEL maintainer="{{ pihole.maintainer }}"
LABEL url="https://www.github.com/pi-hole/docker-pi-hole"
HEALTHCHECK CMD dig @127.0.0.1 pi.hole || exit 1
SHELL ["/bin/bash", "-c"]

View File

@ -1,13 +1,5 @@
FROM debian:stretch
LABEL image="pihole/pihole:v4.0_amd64"
LABEL maintainer="adam@diginc.us"
LABEL url="https://www.github.com/pi-hole/docker-pi-hole"
ENV VERSION v4.0
ENV ARCH amd64
ENV PATH /opt/pihole:${PATH}
COPY install.sh /usr/local/bin/docker-install.sh
ENV PIHOLE_INSTALL /root/ph_install.sh
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.4.0/s6-overlay-amd64.tar.gz
@ -44,6 +36,14 @@ ENV S6_KEEP_ENV 1
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2
ENV FTL_CMD no-daemon
ENV VERSION v4.0
ENV ARCH amd64
ENV PATH /opt/pihole:${PATH}
LABEL image="pihole/pihole:v4.0_amd64"
LABEL maintainer="adam@diginc.us"
LABEL url="https://www.github.com/pi-hole/docker-pi-hole"
HEALTHCHECK CMD dig @127.0.0.1 pi.hole || exit 1
SHELL ["/bin/bash", "-c"]

View File

@ -223,23 +223,25 @@ setup_web_port() {
}
setup_web_password() {
if [ -z "${WEBPASSWORD+x}" ] ; then
# Not set at all, give the user a random pass
WEBPASSWORD=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
echo "Assigning random password: $WEBPASSWORD"
fi;
# Turn bash debug on while setting up password (to print it)
set -x
if [[ "$WEBPASSWORD" == "" ]] ; then
echo "" | pihole -a -p
else
pihole -a -p "$WEBPASSWORD" "$WEBPASSWORD"
fi
if [ "${PH_VERBOSE:-0}" -gt 0 ] ; then
# Turn bash debug back off after print password setup
# (subshell to null hides printing output)
{ set +x; } 2>/dev/null
fi
#if ! grep -q 'WEBPASSWORD' ${setupVars}; then
if [ -z "${WEBPASSWORD+x}" ] ; then
# Not set at all, give the user a random pass
WEBPASSWORD=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
echo "Assigning random password: $WEBPASSWORD"
fi;
# Turn bash debug on while setting up password (to print it)
set -x
if [[ "$WEBPASSWORD" == "" ]] ; then
echo "" | pihole -a -p
else
pihole -a -p "$WEBPASSWORD" "$WEBPASSWORD"
fi
if [ "${PH_VERBOSE:-0}" -gt 0 ] ; then
# Turn bash debug back off after print password setup
# (subshell to null hides printing output)
{ set +x; } 2>/dev/null
fi
#fi
}
setup_ipv4_ipv6() {

View File

@ -10,39 +10,45 @@ parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
namespace='pihole'
localimg='pihole'
remoteimg="$namespace/$localimg"
branch="$(parse_git_branch)"
version="${version:-unset}"
dry="${dry}"
if [[ -n "$dry" ]] ; then dry='echo ' ; fi
if [[ "$version" == 'unset' && "$branch" == 'master' ]]; then
echo "Version is unset and master/prod branch wants a version...pass in \$version!"
exit 1
if [[ "$version" == 'unset' ]]; then
version="$branch"
if [[ "$branch" == "master" ]]; then
echo "Version number var is unset and master branch needs a version...pass in \$version variable!"
exit 1
else if [[ "$branch" = "release/"* ]]
echo "Version number is being taken from this release branch"
version="$(echo $branch | grep -Po 'v[\d.-]')"
fi
echo "Using the branch ($branch) for deployed image version since not passed in"
fi
echo "# DEPLOYING:"
echo "version: $version"
echo "branch: $branch"
[[ -n "$dry" ]] && echo "DRY RUN: $dry"
echo "Example tagging: docker tag $localimg:$tag $remoteimg:${version}_${tag}"
echo
$dry ./Dockerfile.py
if [[ "$branch" == 'master' ]] ; then
if [[ "$branch" == "master" ]] || [[ "$branch" = "release/"* ]] ; then
# ARMv6/armel doesn't have a FTL binary for v4.0 pi-hole
# for tag in debian_armhf debian_aarch64 debian_armel; do
for tag in debian_armhf debian_aarch64; do
for tag in amd64 armhf aarch64; do
# Verison specific tags for ongoing history
$dry docker tag pi-hole-multiarch:$tag pihole/pihole-multiarch:v${version}_${tag}
$dry docker push pihole/pihole-multiarch:v${version}_${tag}
$dry docker tag $localimg:$tag $remoteimg:${version}_${tag}
$dry docker push pihole/pihole-multiarch:${version}_${tag}
# Floating latest tags
$dry docker tag pi-hole-multiarch:$tag pihole/pihole-multiarch:${tag}
$dry docker push pihole/pihole-multiarch:${tag}
done
else
for tag in debian_armhf debian_aarch64; do
$dry docker tag pi-hole-multiarch:$tag pihole/pihole-multiarch:${tag}_${branch}
$dry docker push pihole/pihole-multiarch:${tag}_${branch}
done
fi

View File

@ -44,7 +44,7 @@ test_configs
echo " ::: Docker start setup complete"
echo <EOF>>
echo """
:: ::: ::: ::: ::: ::: ::: ::: ::: :::
:: Image moved / deprecation notice
:: OLD IMAGE : diginc/pi-hole
@ -52,4 +52,4 @@ echo <EOF>>
:: In order to get the latest updates
:: please update your image references
:: ::: ::: ::: ::: ::: ::: ::: ::: :::
EOF
"""

View File

@ -7,7 +7,7 @@ check_output = testinfra.get_backend(
def DockerGeneric(request, args, image, cmd):
assert 'docker' in check_output('id'), "Are you in the docker group?"
if 'pi-hole' in image:
if 'pihole' in image:
args += " --dns 127.0.0.1 -v /dev/null:/etc/pihole/adlists.default -e PYTEST=\"True\""
docker_run = "docker run -d {} {} {}".format(args, image, cmd)
print docker_run
@ -44,7 +44,8 @@ def Docker(request, args, image, cmd):
@pytest.fixture(scope='module')
def DockerPersist(request, persist_args, persist_image, persist_cmd, Dig):
''' Persistent Docker container for multiple tests '''
''' Persistent Docker container for multiple tests, instead of stopping container after one test '''
''' Uses DUP'd module scoped fixtures because smaller scoped fixtures won't mix with module scope '''
persistent_container = DockerGeneric(request, persist_args, persist_image, persist_cmd)
''' attach a dig conatiner for lookups '''
persistent_container.dig = Dig(persistent_container.id)
@ -58,26 +59,23 @@ def args(request):
def arch(request):
return request.param
@pytest.fixture(params=['debian'])
def os(request):
return request.param
@pytest.fixture()
def version(request):
''' TODO: include from external .py that can be shared with Dockerfile.py / Tests / deploy scripts '''
return 'v4.0'
@pytest.fixture()
def tag(request, os, arch):
return '{}_{}'.format(os, arch)
def tag(request, version, arch):
return '{}_{}'.format(version, arch)
@pytest.fixture
def webserver(request, tag):
webserver = 'nginx'
if 'debian' in tag:
webserver = 'lighttpd'
return webserver
''' TODO: this is obvious without alpine+nginx as the alternative, remove fixture, hard code lighttpd in tests? '''
return 'lighttpd'
@pytest.fixture()
def image(request, tag):
image = 'pi-hole-multiarch'
if 'amd64' in tag:
image = 'pi-hole'
image = 'pihole'
return '{}:{}'.format(image, tag)
@pytest.fixture()
@ -89,30 +87,27 @@ def persist_arch(request):
'''amd64 only, dnsmasq/pihole-FTL(?untested?) will not start under qemu-user-static :('''
return request.param
@pytest.fixture(scope='module', params=['debian'])
def persist_os(request):
return request.param
@pytest.fixture(scope='module')
def persist_version(request):
''' TODO: include from external .py that can be shared with Dockerfile.py / Tests / deploy scripts '''
return 'v4.0'
@pytest.fixture(scope='module')
def persist_args(request):
return '-e ServerIP="127.0.0.1" -e ServerIPv6="::1"'
@pytest.fixture(scope='module')
def persist_tag(request, persist_os, persist_arch):
return '{}_{}'.format(persist_os, persist_arch)
def persist_tag(request, persist_version, persist_arch):
return '{}_{}'.format(persist_version, persist_arch)
@pytest.fixture(scope='module')
def persist_webserver(request, persist_tag):
webserver = 'nginx'
if 'debian' in persist_tag:
webserver = 'lighttpd'
return webserver
''' TODO: this is obvious without alpine+nginx as the alternative, remove fixture, hard code lighttpd in tests? '''
return 'lighttpd'
@pytest.fixture(scope='module')
def persist_image(request, persist_tag):
image = 'pi-hole-multiarch'
if 'amd64' in persist_tag:
image = 'pi-hole'
image = 'pihole'
return '{}:{}'.format(image, persist_tag)
@pytest.fixture(scope='module')

View File

@ -9,28 +9,27 @@ DEFAULTARGS = '-e ServerIP="127.0.0.1" '
(DEFAULTARGS + '-e "IPv6=False"', False, 'IPv4'),
(DEFAULTARGS + '-e "IPv6=foobar"', False, 'IPv4'),
])
def test_IPv6_not_True_removes_ipv6(Docker, os, args, expected_ipv6, expected_stdout):
def test_IPv6_not_True_removes_ipv6(Docker, args, expected_ipv6, expected_stdout):
''' When a user overrides IPv6=True they only get IPv4 listening webservers '''
IPV6_LINE = { 'debian': 'use-ipv6.pl' }
WEB_CONFIG = { 'debian': '/etc/lighttpd/lighttpd.conf' }
IPV6_LINE = 'use-ipv6.pl'
WEB_CONFIG = '/etc/lighttpd/lighttpd.conf'
function = Docker.run('. /bash_functions.sh ; setup_ipv4_ipv6')
assert "Using {}".format(expected_stdout) in function.stdout
config = Docker.run('cat {}'.format( WEB_CONFIG[os])).stdout
assert (IPV6_LINE[os] in config) == expected_ipv6
config = Docker.run('cat {}'.format(WEB_CONFIG)).stdout
assert (IPV6_LINE in config) == expected_ipv6
@pytest.mark.parametrize('args', [DEFAULTARGS + '-e "WEB_PORT=999"'])
def test_overrides_default_WEB_PORT(Docker, os, args):
def test_overrides_default_WEB_PORT(Docker, args):
''' When a --net=host user sets WEB_PORT to avoid synology's 80 default IPv4 and or IPv6 ports are updated'''
CONFIG_LINES = { 'debian': ['server.port\s*=\s*999'] }
WEB_CONFIG = { 'debian': '/etc/lighttpd/lighttpd.conf' }
CONFIG_LINE = 'server.port\s*=\s*999'
WEB_CONFIG = '/etc/lighttpd/lighttpd.conf'
function = Docker.run('. /bash_functions.sh ; eval `grep setup_web_port /start.sh`')
assert "Custom WEB_PORT set to 999" in function.stdout
assert "INFO: Without proper router DNAT forwarding to 127.0.0.1:999, you may not get any blocked websites on ads" in function.stdout
config = Docker.run('cat {}'.format( WEB_CONFIG[os])).stdout
for expected_line in CONFIG_LINES[os]:
assert re.search(expected_line, config) != None
config = Docker.run('cat {}'.format(WEB_CONFIG)).stdout
assert re.search(CONFIG_LINE, config) != None
# grep fails to find any of the old address w/o port
assert Docker.run('grep -rq "://127.0.0.1/" /var/www/html/').rc == 1
assert Docker.run('grep -rq "://pi.hole/" /var/www/html/').rc == 1
@ -121,11 +120,11 @@ expected_debian_lines = [
'"ServerIP" => "127.0.0.1"',
'"PHP_ERROR_LOG" => "/var/log/lighttpd/error.log"'
]
@pytest.mark.parametrize('os,expected_lines,repeat_function', [
('debian', expected_debian_lines, 1),
('debian', expected_debian_lines, 2)
@pytest.mark.parametrize('expected_lines,repeat_function', [
(expected_debian_lines, 1),
(expected_debian_lines, 2)
])
def test_debian_setup_php_env(Docker, os, expected_lines, repeat_function):
def test_debian_setup_php_env(Docker, expected_lines, repeat_function):
''' confirm all expected output is there and nothing else '''
stdout = ''
for i in range(repeat_function):