Split build out from tests to ensure it runs first
This commit is contained in:
parent
95dae59418
commit
7c85ac8d32
|
@ -1,5 +1,8 @@
|
|||
""" Generates Dockerfiles from template and builds them locally """
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
import os
|
||||
import testinfra
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
@ -69,5 +72,34 @@ def generate_dockerfiles():
|
|||
f.write(template.render(pihole=merged_data))
|
||||
|
||||
|
||||
def build_everything():
|
||||
for os in ['debian', 'alpine']:
|
||||
for image, archs in {
|
||||
'pi-hole': ['amd64'],
|
||||
'pi-hole-multiarch': ['armhf', 'aarch64'],
|
||||
}.iteritems():
|
||||
for arch in archs:
|
||||
build(image, os, arch)
|
||||
|
||||
|
||||
def build(image, os, arch):
|
||||
run_local = testinfra.get_backend(
|
||||
"local://"
|
||||
).get_module("Command").run
|
||||
|
||||
dockerfile = 'Dockerfile_{}_{}'.format(os, arch)
|
||||
image_tag = '{}:{}_{}'.format(image, os, arch)
|
||||
print " ::: Pulling {} to reuse layers".format(dockerfile, image_tag)
|
||||
pull_cmd = run_local('docker pull {}/{}'.format('diginc', image_tag))
|
||||
print pull_cmd.stdout
|
||||
print " ::: Building {} into {}".format(dockerfile, image_tag)
|
||||
build_cmd = run_local('docker build --pull -f {} -t {} .'.format(dockerfile, image_tag))
|
||||
print build_cmd.stdout
|
||||
if build_cmd.rc != 0:
|
||||
print build_cmd.stderr
|
||||
assert build_cmd.rc == 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
generate_dockerfiles()
|
||||
build_everything()
|
|
@ -1,6 +1,5 @@
|
|||
import pytest
|
||||
import testinfra
|
||||
import DockerfileGeneration
|
||||
|
||||
WEB_SERVER = { 'alpine_amd64': 'nginx', 'debian_amd64': 'lighttpd' }
|
||||
|
||||
|
@ -75,7 +74,10 @@ def webserver(request, tag):
|
|||
|
||||
@pytest.fixture()
|
||||
def image(request, tag):
|
||||
return 'pi-hole:{}'.format(tag)
|
||||
image = 'pi-hole'
|
||||
if 'amd64' not in tag:
|
||||
image = 'pi-hole-multiarch'
|
||||
return '{}:{}'.format(image, tag)
|
||||
|
||||
@pytest.fixture()
|
||||
def cmd(request):
|
||||
|
@ -142,23 +144,3 @@ def RunningPiHole(DockerPersist, Slow, persist_webserver):
|
|||
Slow(lambda: DockerPersist.run('pgrep dnsmasq').rc == 0)
|
||||
Slow(lambda: DockerPersist.run('pgrep {}'.format(persist_webserver) ).rc == 0)
|
||||
return DockerPersist
|
||||
|
||||
|
||||
''' Everything should depend on the building of the docker images '''
|
||||
@pytest.fixture(autouse=True)
|
||||
@pytest.mark.parametrize('arch', [ 'amd64', 'armhf', 'aarch64' ])
|
||||
@pytest.mark.parametrize('os', [ 'debian', 'alpine' ])
|
||||
def test_build_pihole_image(os, arch):
|
||||
run_local = testinfra.get_backend(
|
||||
"local://"
|
||||
).get_module("Command").run
|
||||
|
||||
''' Build the entire matrix of OS+Architecture '''
|
||||
DockerfileGeneration.generate_dockerfiles()
|
||||
dockerfile = 'Dockerfile_{}_{}'.format(os, arch)
|
||||
image_tag = '{}:{}_{}'.format('pi-hole', os, arch)
|
||||
build_cmd = run_local('docker build --pull -f {} -t {} .'.format(dockerfile, image_tag))
|
||||
if build_cmd.rc != 0:
|
||||
print build_cmd.stdout
|
||||
print build_cmd.stderr
|
||||
assert build_cmd.rc == 0
|
||||
|
|
Loading…
Reference in New Issue