Skip to content

Commit

Permalink
Squash!
Browse files Browse the repository at this point in the history
  • Loading branch information
diginc committed Jan 31, 2020
1 parent b87b28a commit 9ce1ecb
Show file tree
Hide file tree
Showing 26 changed files with 1,013 additions and 123 deletions.
67 changes: 67 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: 2

.job_template: &job_template
machine:
enabled: true
steps:
- checkout
#- attach_workspace:
# at: ./ci-workspace/
- run:
command: ./circle-test.sh
- persist_to_workspace:
root: .
paths: [ 'ci-workspace' ]

jobs:
amd64:
<<: *job_template
arm64:
<<: *job_template
armhf:
<<: *job_template
armel:
<<: *job_template
deploy:
docker:
- image: circleci/python:latest
steps:
- setup_remote_docker:
version: 18.06.0-ce
- checkout
- attach_workspace:
at: .
- run:
command: ./circle-deploy.sh



workflows:
version: 2
build:
jobs:
- amd64:
filters:
tags:
only: /^v.*/
- arm64:
filters:
tags:
only: /^v.*/
- armhf:
filters:
tags:
only: /^v.*/
- armel:
filters:
tags:
only: /^v.*/
- deploy:
requires:
- amd64
- arm64
- armhf
- armel
filters:
tags:
only: /^v.*/
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
**/*.sw*
.tox
.git
**/__pycache__
.pipenv
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
.cache
__pycache__
.tox
.pipenv
.eggs
UNKNOWN.egg-info
.env
ci-workspace

# WIP/test stuff
doco.yml
ci-workspace
.pipenv
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

83 changes: 47 additions & 36 deletions Dockerfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env python
#!/usr/bin/env python3
""" Dockerfile.py - generates and build dockerfiles
Usage:
Dockerfile.py [--arch=<arch> ...] [--skip=<arch> ...] [-v] [-t] [--no-build | --no-generate] [--no-cache]
Dockerfile.py [--hub_tag=<tag>] [--arch=<arch> ...] [-v] [-t] [--no-build | --no-generate] [--no-cache]
Options:
--no-build Skip building the docker images
--no-cache Build without using any cache data
--no-generate Skip generating Dockerfiles from template
--arch=<arch> What Architecture(s) to build [default: amd64 armel armhf aarch64]
--skip=<arch> What Architectures(s) to skip [default: None]
--hub_tag=<tag> What the Docker Hub Image should be tagged as [default: None]
--arch=<arch> What Architecture(s) to build [default: amd64 armel armhf arm64]
-v Print docker's command output [default: False]
-t Print docker's build time [default: False]
Examples:
"""
from __future__ import print_function


from docopt import docopt
from jinja2 import Environment, FileSystemLoader
Expand All @@ -29,7 +29,7 @@
base_vars = {
'name': 'pihole/pihole',
'maintainer' : 'adam@diginc.us',
's6_version' : 'v1.21.7.0',
's6_version' : 'v1.22.1.0',
}

os_base_vars = {
Expand All @@ -47,19 +47,23 @@
__version__: [
{
'base': 'pihole/debian-base:latest',
'arch': 'amd64'
'arch': 'amd64',
's6arch': 'amd64',
},
{
'base': 'multiarch/debian-debootstrap:armel-stretch-slim',
'arch': 'armel'
'arch': 'armel',
's6arch': 'arm',
},
{
'base': 'multiarch/debian-debootstrap:armhf-stretch-slim',
'arch': 'armhf'
'arch': 'arm',
's6arch' : 'arm',
},
{
'base': 'multiarch/debian-debootstrap:arm64-stretch-slim',
'arch': 'aarch64'
'arch': 'arm64',
's6arch' : 'aarch64',
}
]
}
Expand All @@ -69,19 +73,17 @@ def generate_dockerfiles(args):
print(" ::: Skipping Dockerfile generation")
return

for version, archs in images.iteritems():
for version, archs in images.items():
for image in archs:
if image['arch'] not in args['--arch'] or image['arch'] in args['--skip']:
return
s6arch = image['arch']
if image['arch'] == 'armel':
s6arch = 'arm'
if image['arch'] not in args['--arch']:
continue
s6arch = image['s6arch'] if image['s6arch'] else image['arch']
merged_data = dict(
{ 'version': version }.items() +
base_vars.items() +
os_base_vars.items() +
image.items() +
{ 's6arch': s6arch }.items()
list({ 'version': version }.items()) +
list(base_vars.items()) +
list(os_base_vars.items()) +
list(image.items()) +
list({ 's6arch': s6arch }.items())
)
j2_env = Environment(loader=FileSystemLoader(THIS_DIR),
trim_blocks=True)
Expand All @@ -98,17 +100,28 @@ def build_dockerfiles(args):
return

for arch in args['--arch']:
# TODO: include from external .py that can be shared with Dockerfile.py / Tests / deploy scripts '''
#if arch == 'armel':
# print("Skipping armel, incompatible upstream binaries/broken")
# continue
build('pihole', arch, args)


def run_and_stream_command_output(command, args):
print("Running", command)
build_result = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
bufsize=1, universal_newlines=True)
if args['-v']:
while build_result.poll() is None:
for line in build_result.stdout:
print(line, end='')
build_result.wait()
if build_result.returncode != 0:
print(" ::: Error running".format(command))
print(build_result.stderr)


def build(docker_repo, arch, args):
dockerfile = 'Dockerfile_{}'.format(arch)
repo_tag = '{}:{}_{}'.format(docker_repo, __version__, arch)
cached_image = '{}/{}'.format('pihole', repo_tag)
print(" ::: Building {}".format(repo_tag))
time=''
if args['-t']:
time='time '
Expand All @@ -118,22 +131,20 @@ def build(docker_repo, arch, args):
build_command = '{time}docker build {no_cache} --pull --cache-from="{cache},{create_tag}" -f {dockerfile} -t {create_tag} .'\
.format(time=time, no_cache=no_cache, cache=cached_image, dockerfile=dockerfile, create_tag=repo_tag)
print(" ::: Building {} into {}".format(dockerfile, repo_tag))
run_and_stream_command_output(build_command, args)
if args['-v']:
print(build_command, '\n')
build_result = subprocess.Popen(build_command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if args['-v']:
for c in iter(lambda: build_result.stdout.read(1), b''):
sys.stdout.write(c)
build_result.wait()
if build_result.returncode != 0:
print(" ::: Building {} encountered an error".format(dockerfile))
print(build_result.stderr)
assert build_result.returncode == 0
if args['--hub_tag']:
hub_tag_command = "{time}docker tag {create_tag} {hub_tag}"\
.format(time=time, create_tag=repo_tag, hub_tag=args['--hub_tag'])
print(" ::: Tagging {} into {}".format(repo_tag, args['--hub_tag']))
run_and_stream_command_output(hub_tag_command, args)


if __name__ == '__main__':
args = docopt(__doc__, version='Dockerfile 1.0')
# print args
args = docopt(__doc__, version='Dockerfile 1.1')
if args['-v']:
print(args)

generate_dockerfiles(args)
build_dockerfiles(args)
8 changes: 8 additions & 0 deletions Dockerfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh
# alpine sh only

set -eux
./Dockerfile.py -v --arch="${ARCH}" --hub_tag="${ARCH_IMAGE}"
# TODO: Add junitxml output and have circleci consume it
# 2 parallel max b/c race condition with docker fixture (I think?)
py.test -vv -n 2 -k "${ARCH}" ./test/
2 changes: 1 addition & 1 deletion Dockerfile_amd64
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM pihole/debian-base:latest

ENV ARCH amd64
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.7.0/s6-overlay-amd64.tar.gz
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-amd64.tar.gz

COPY install.sh /usr/local/bin/install.sh
COPY VERSION /etc/docker-pi-hole-version
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile_aarch64 → Dockerfile_arm64
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM multiarch/debian-debootstrap:arm64-stretch-slim

ENV ARCH aarch64
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.7.0/s6-overlay-aarch64.tar.gz
ENV ARCH arm64
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-aarch64.tar.gz

COPY install.sh /usr/local/bin/install.sh
COPY VERSION /etc/docker-pi-hole-version
Expand Down Expand Up @@ -40,7 +40,7 @@ ENV DNSMASQ_USER root
ENV VERSION v4.3.2
ENV PATH /opt/pihole:${PATH}

LABEL image="pihole/pihole:v4.3.2_aarch64"
LABEL image="pihole/pihole:v4.3.2_arm64"
LABEL maintainer="adam@diginc.us"
LABEL url="https://www.github.com/pi-hole/docker-pi-hole"

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile_armel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM multiarch/debian-debootstrap:armel-stretch-slim

ENV ARCH armel
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.7.0/s6-overlay-arm.tar.gz
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-arm.tar.gz

COPY install.sh /usr/local/bin/install.sh
COPY VERSION /etc/docker-pi-hole-version
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM docker:latest

# Based on https://github.com/Ilhicas/alpine-pipenv
ARG packages
RUN apk --update add python3 python3-dev curl gcc make \
musl-dev libffi-dev openssl-dev ${packages} \
&& rm -rf /var/cache/apk/* \
&& pip3 install -U pip pipenv


# -v "$(pwd):/$(pwd)" -w "$(pwd)" to prevent nested docker path confusion
COPY ./Dockerfile.sh /usr/local/bin/
COPY Pipfile* /root/
WORKDIR /root

RUN pipenv install --system \
&& sed -i 's|/bin/sh|/bin/bash|g' /usr/lib/python3.8/site-packages/testinfra/backend/docker.py


RUN echo "set -ex && Dockerfile.sh && \$@" > /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT entrypoint.sh
CMD Dockerfile.sh
Loading

0 comments on commit 9ce1ecb

Please sign in to comment.