<commit_before>"""
Copyright (c) 2017 Red Hat, Inc
All rights reserved.

This software may be modified and distributed under the terms
of the BSD license. See the LICENSE file for details.


Combines the module information looked up by pre_resolve_module_compose,
combines it with additional information from container.yaml, and
generates a Dockerfile that will build a filesystem image for the module
at /var/tmp/flatpak-build.

Example configuration:
{
    'name': 'flatpak_create_dockerfile',
    'args': {'base_image': 'registry.fedoraproject.org/fedora:latest'}
}
"""

import os

from flatpak_module_tools.flatpak_builder import FlatpakSourceInfo, FlatpakBuilder

from atomic_reactor.constants import DOCKERFILE_FILENAME, YUM_REPOS_DIR
from atomic_reactor.plugin import PreBuildPlugin
from atomic_reactor.plugins.pre_reactor_config import get_flatpak_base_image
from atomic_reactor.plugins.pre_resolve_module_compose import get_compose_info
from atomic_reactor.plugins.build_orchestrate_build import override_build_kwarg
from atomic_reactor.rpm_util import rpm_qf_args
from atomic_reactor.util import render_yum_repo, split_module_spec
from atomic_reactor.yum_util import YumRepo


DOCKERFILE_TEMPLATE = '''FROM {base_image}

LABEL name="{name}"
LABEL com.redhat.component="{name}"
LABEL version="{stream}"
LABEL release="{version}"

ADD atomic-reactor-includepkgs /tmp/

RUN mkdir -p /var/tmp/flatpak-build/dev && \
    for i in null zero random urandom ; do cp -a /dev/$i /var/tmp/flatpak-build/dev ; done

RUN cat /tmp/atomic-reactor-includepkgs >> /etc/dnf/dnf.conf && \\
    dnf -y --nogpgcheck \\
    --disablerepo=* \\
    --enablerepo=atomic-reactor-koji-plugin-* \\
    --enablerepo=atomic-reactor-module-* \\
    --installroot=/var/tmp/flatpak-build module enable {modules} && \\
    dnf -y --nogpgcheck \\
    --disablerepo=* \\
    --enablerepo=atomic-reactor-koji-plugin-* \\
    --enablerepo=atomic-reactor-module-* \\
    --installroot=/var/tmp/flatpak-build install {packages}
RUN rpm --root=/var/tmp/flatpak-build {rpm_qf_args} > /var/tmp/flatpak-build.rpm_qf
COPY cleanup.sh /var/tmp/flatpak-build/tmp/
RUN chroot /var/tmp/flatpak-build/ /bin/sh /tmp/cleanup.sh
'''


WORKSPACE_SOURCE_KEY = 'source_info'
<commit_msg>flatpak_create_dockerfile: Initialize /etc/os-release in the installroot<commit_after>"""
Copyright (c) 2017 Red Hat, Inc
All rights reserved.

This software may be modified and distributed under the terms
of the BSD license. See the LICENSE file for details.


Combines the module information looked up by pre_resolve_module_compose,
combines it with additional information from container.yaml, and
generates a Dockerfile that will build a filesystem image for the module
at /var/tmp/flatpak-build.

Example configuration:
{
    'name': 'flatpak_create_dockerfile',
    'args': {'base_image': 'registry.fedoraproject.org/fedora:latest'}
}
"""

import os

from flatpak_module_tools.flatpak_builder import FlatpakSourceInfo, FlatpakBuilder

from atomic_reactor.constants import DOCKERFILE_FILENAME, YUM_REPOS_DIR
from atomic_reactor.plugin import PreBuildPlugin
from atomic_reactor.plugins.pre_reactor_config import get_flatpak_base_image
from atomic_reactor.plugins.pre_resolve_module_compose import get_compose_info
from atomic_reactor.plugins.build_orchestrate_build import override_build_kwarg
from atomic_reactor.rpm_util import rpm_qf_args
from atomic_reactor.util import render_yum_repo, split_module_spec
from atomic_reactor.yum_util import YumRepo


# /var/tmp/flatpak-build is the final image we'll turn into a Flaptak
# In order for 'dnf module enable' to work correctly, we need an
# /etc/os-release in the install root with the correct PLATFORM_ID
# for our base package set. To make that work, we install system-release
# into a *different* install root and copy /etc/os-release over.
DOCKERFILE_TEMPLATE = '''FROM {base_image}

LABEL name="{name}"
LABEL com.redhat.component="{name}"
LABEL version="{stream}"
LABEL release="{version}"

ADD atomic-reactor-includepkgs /tmp/

RUN mkdir -p /var/tmp/flatpak-build/dev && \
    for i in null zero random urandom ; do cp -a /dev/$i /var/tmp/flatpak-build/dev ; done

RUN cat /tmp/atomic-reactor-includepkgs >> /etc/dnf/dnf.conf && \\
    INSTALLDIR=/var/tmp/flatpak-build && \\
    DNF='\\
    dnf -y --nogpgcheck \\
    --disablerepo=* \\
    --enablerepo=atomic-reactor-koji-plugin-* \\
    --enablerepo=atomic-reactor-module-* \\
    ' && \\
    $DNF --installroot=$INSTALLDIR-init install system-release && \\
    mkdir -p $INSTALLDIR/etc/ && \\
    cp $INSTALLDIR-init/etc/os-release $INSTALLDIR/etc/os-release && \\
    $DNF --installroot=$INSTALLDIR module enable {modules} && \\
    $DNF --installroot=$INSTALLDIR install {packages}
RUN rpm --root=/var/tmp/flatpak-build {rpm_qf_args} > /var/tmp/flatpak-build.rpm_qf
COPY cleanup.sh /var/tmp/flatpak-build/tmp/
RUN chroot /var/tmp/flatpak-build/ /bin/sh /tmp/cleanup.sh
'''


WORKSPACE_SOURCE_KEY = 'source_info'

{'fraction_non_alphanumeric': 0.10847252968404106, 'fraction_numerical': 0.0016099818877037633, 'mean_word_length': 4.367170626349892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4935964', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1647, 'n_words': 419}