Commit f264abf3 authored by Noé Gaumont's avatar Noé Gaumont 🐙
Browse files

feat: merge dockerfile and dockerfile.cubicweb

parent 550c057fb2d0
ARG DIST
FROM debian:$DIST-slim
FROM debian:$DIST-slim as base
ENV LANG C.UTF-8
RUN mkdir -p /usr/share/man/man1 && mkdir -p /usr/share/man/man7
RUN apt-get update && apt-get -y dist-upgrade \
......@@ -53,3 +53,26 @@ WORKDIR /home/cubicweb
EXPOSE 8080/tcp
ENTRYPOINT ["/entrypoint.sh"]
CMD ["start"]
ARG DIST
FROM logilab/cubicweb:$DIST-buildpackage as build
ARG SOURCE_TARBALL
RUN if test -n "$SOURCE_TARBALL"; then buildpackage -u "$SOURCE_TARBALL"; fi
FROM base
USER root
RUN apt-get update && apt-get -y --no-install-recommends install \
wget \
gnupg \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ARG DIST
ARG COMPONENT
RUN echo "deb http://apt.logilab.fr $DIST $COMPONENT" > /etc/apt/sources.list.d/logilab.list
RUN wget -O - https://apt.logilab.fr/key.asc | apt-key --keyring /etc/apt/trusted.gpg.d/logilab.gpg add -
COPY --from=build /repo /repo
ARG PACKAGES
RUN apt-get update && apt-get -y --install-recommends install \
$PACKAGES \
&& rm -rf /var/lib/apt/lists/*
USER cubicweb
ARG DIST
ARG FROM
FROM logilab/cubicweb:$DIST-buildpackage as build
ARG SOURCE_TARBALL
RUN if test -n "$SOURCE_TARBALL"; then buildpackage -u "$SOURCE_TARBALL"; fi
FROM $FROM
USER root
RUN apt-get update && apt-get -y --no-install-recommends install \
wget \
gnupg \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ARG DIST
ARG COMPONENT
RUN echo "deb http://apt.logilab.fr $DIST $COMPONENT" > /etc/apt/sources.list.d/logilab.list
RUN wget -O - https://apt.logilab.fr/key.asc | apt-key --keyring /etc/apt/trusted.gpg.d/logilab.gpg add -
COPY --from=build /repo /repo
ARG PACKAGES
RUN apt-get update && apt-get -y --install-recommends install \
$PACKAGES \
&& rm -rf /var/lib/apt/lists/*
USER cubicweb
......@@ -5,14 +5,30 @@ import subprocess
import sys
import logging
from dataclasses import dataclass
from typing import Optional
@dataclass
class CubicWebImage:
python: str
debian: str
package_name: str
cubicweb_version: str
tag: str
package_version: str
@property
def cubicweb_version(self):
return self.package_version.split('-', 1)[0]
@property
def cubicweb_major_version(self):
return self.cubicweb_version.rsplit('.', 1)[0]
@property
def tag(self):
return f"{REGISTRY}:{self.base_docker_image}-{self.cubicweb_version}"
@property
def base_docker_image(self):
return f"{self.python}-{self.debian}"
LOG = logging.getLogger(__name__)
......@@ -60,13 +76,6 @@ def _cwdev(_cache={}):
return _cache[None]
def _tag(*args, registry=None):
tag_part = '-'.join([x for x in args if x is not None])
if tag_part:
return '{}:{}'.format(registry or REGISTRY, tag_part)
return REGISTRY
def tag_aliases():
for alias, source in ALIASES:
if alias == 'buildpackage':
......@@ -81,26 +90,26 @@ def tag_aliases():
check_call('docker', 'tag', src, tag)
def build_image(python, dist, cw, onbuild, no_cache=False, registry=None):
tag = _tag(python, dist, cw, onbuild, registry=registry)
def build_image(image: CubicWebImage, onbuild: Optional[str], no_cache=False, registry=None):
args = {}
dockerfile = 'Dockerfile'
if onbuild is not None:
dockerfile = 'Dockerfile.onbuild'
args['FROM'] = _tag(python, dist, cw)
elif cw is not None:
dockerfile = 'Dockerfile.cubicweb'
args['FROM'] = _tag(python, dist)
args['DIST'] = dist
args['PACKAGES'] = 'python-cubicweb' if python == 'py27' else 'python3-cubicweb'
if cw == 'dev':
args['FROM'] = image.tag
tag = image.tag + '-onbuild'
else:
args['PYTHON'] = 'python' if image.python == 'py27' else 'python3'
dockerfile = 'Dockerfile'
args['FROM'] = image.base_docker_image
args['DIST'] = image.debian
args['PACKAGES'] = image.package_name
tag = image.tag
if image.package_version == 'dev':
args['SOURCE_TARBALL'] = _cwdev()
args['COMPONENT'] = 'main'
else:
args['COMPONENT'] = 'cubicweb-{}'.format(cw)
else:
args['DIST'] = dist
args['PYTHON'] = 'python' if python == 'py27' else 'python3'
args['COMPONENT'] = 'cubicweb-{}'.format(image.cubicweb_major_version)
cmd = [
'docker', 'build', '-t', tag,
'-f', dockerfile,
......@@ -127,47 +136,50 @@ def build_buildpackage(dist):
'--build-arg', 'DIST={}'.format(dist),
'-f', 'Dockerfile.buildpackage', '.')
def get_cubicweb_version_matrix():
def get_cubicweb_images():
check_call('docker', 'build', '.', '-f', 'Dockerfile.getversion', '-t','cubicweb:getversion')
versions = check_output('docker', 'run', '--rm', 'cubicweb:getversion').splitlines()
# filter release candidate version
valid_versions = [version for version in versions if '~rc' not in version]
MATRIX = [
# (['py27'], ['stretch', 'buster'], [None, '3.25', '3.26'],
# [None, 'onbuild']),
# (['py35'], ['stretch'], [None, '3.26', '3.27'], [None, 'onbuild']),
(['py37'], ['buster'], ['3.29'], [None, 'onbuild']),
]
return valid_versions
def build(rebuild=False):
images = []
for version in valid_versions:
image = CubicWebImage(
python='py37',
debian='buster',
package_name='python3-cubicweb',
package_version=version
)
images.append(image)
return images
def build(images=[], rebuild=False):
if rebuild:
# pull base images
check_call('docker', 'pull', 'debian:stretch-slim')
check_call('docker', 'pull', 'debian:buster-slim')
build_buildpackage('stretch')
# build_buildpackage('stretch')
build_buildpackage('buster')
for matrix in MATRIX:
for python, dist, cw, onbuild in itertools.product(*matrix):
build_image(python, dist, cw, onbuild)
if rebuild and onbuild is None:
tag = _tag(python, dist, cw)
out = run(
'docker', 'run', '--rm', '-t',
'--user', 'root',
'--entrypoint', 'check-docker-updates.sh',
tag, 'apt')
if out.returncode == 1:
LOG.warning(red(
'%s debian packages updates are available: %s'),
tag, out.stdout)
build_image(python, dist, cw, onbuild, no_cache=True)
else:
assert (out.returncode, out.stdout) == (0, b''), out
LOG.info(green('%s debian packages are up-to-date'), tag)
for image in images:
for image_type in (None, 'onbuild'):
build_image(image, image_type)
if rebuild and onbuild is None:
tag = _tag(python, dist, cw)
out = run(
'docker', 'run', '--rm', '-t',
'--user', 'root',
'--entrypoint', 'check-docker-updates.sh',
tag, 'apt')
if out.returncode == 1:
LOG.warning(red(
'%s debian packages updates are available: %s'),
tag, out.stdout)
build_image(python, dist, cw, onbuild, no_cache=True)
else:
assert (out.returncode, out.stdout) == (0, b''), out
LOG.info(green('%s debian packages are up-to-date'), tag)
def push():
......@@ -202,8 +214,9 @@ if __name__ == '__main__':
help='push images')
args = parser.parse_args()
REGISTRY = args.registry
images = get_cubicweb_images()
if args.push:
push()
else:
build(args.checkrebuild)
build(images=images, rebuild=args.checkrebuild)
tag_aliases()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment