<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function, unicode_literals

import os
from io import BytesIO

from flyingcloud import DockerBuildLayer


# TODO
# - fail if layer config dir is not present

class BuildFlaskExampleError(Exception):
    pass


class ExampleBuildLayer(DockerBuildLayer):
    USERNAME_VAR = 'EXAMPLE_DOCKER_REGISTRY_USERNAME'
    PASSWORD_VAR = '<PASSWORD>'
    Registry = 'quay.io'
    RegistryDockerVersion = "1.17"
    Organization = 'cookbrite'
    AppName = 'flaskexample'
    LoginRequired = False

    # TODO: reconsider these
    SquashLayer = False
    PushLayer = False
    PullLayer = False


class SystemBaseLayer(ExampleBuildLayer):
    CommandName = 'sysbase'
    Description = 'Build System Base Layer - Phusion'
    LayerSuffix = CommandName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    SaltStateDir = LayerSuffix
    PullLayer = False


class PythonBaseLayer(ExampleBuildLayer):
    CommandName = 'pybase'
    Description = 'Build Python Base Layer - modern Python 2.7.x'
    LayerSuffix = CommandName
    SourceImageName = SystemBaseLayer.TargetImageName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    SaltStateDir = LayerSuffix


class OpenCvLayer(ExampleBuildLayer):
    CommandName = 'opencv'
    Description = 'Build OpenCV layer'
    LayerSuffix = CommandName
    SourceImageName = PythonBaseLayer.TargetImageName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    SaltStateDir = CommandName


class FlaskExampleLayer(ExampleBuildLayer):
    CommandName = 'app'
    Description = 'Build Flask Example app'
    LayerSuffix = CommandName
    SaltStateDir = LayerSuffix
    SourceImageName = OpenCvLayer.TargetImageName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    ExposedPorts = [80]


class FlaskExampleTestLayer(ExampleBuildLayer):
    CommandName = 'tests'
    Description = 'Build Flask Tests Layer'
    LayerSuffix = CommandName
    SourceImageName = FlaskExampleLayer.TargetImageName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    SaltStateDir = CommandName


def main():
    base_dir = os.path.abspath(os.path.dirname(__file__))
    defaults = dict(
            base_dir=base_dir,
    )

    # TODO: discovery mechanism
    ExampleBuildLayer.main(
            defaults,
            SystemBaseLayer,
            PythonBaseLayer,
            OpenCvLayer,
            FlaskExampleLayer,
            description="Build a Flask example Docker image using SaltStack",
    )<commit_msg>renamed app layer to be a better name (app)<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function, unicode_literals

import os
from io import BytesIO

from flyingcloud import DockerBuildLayer


# TODO
# - fail if layer config dir is not present

class BuildFlaskExampleError(Exception):
    pass


class ExampleBuildLayer(DockerBuildLayer):
    USERNAME_VAR = 'EXAMPLE_DOCKER_REGISTRY_USERNAME'
    PASSWORD_VAR = 'EXAMPLE_DOCKER_REGISTRY_PASSWORD'
    Registry = 'quay.io'
    RegistryDockerVersion = "1.17"
    Organization = 'cookbrite'
    AppName = 'flaskexample'
    LoginRequired = False

    # TODO: reconsider these
    SquashLayer = False
    PushLayer = False
    PullLayer = False


class SystemBaseLayer(ExampleBuildLayer):
    CommandName = 'sysbase'
    Description = 'Build System Base Layer - Phusion'
    LayerSuffix = CommandName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    SaltStateDir = LayerSuffix
    PullLayer = False


class PythonBaseLayer(ExampleBuildLayer):
    CommandName = 'pybase'
    Description = 'Build Python Base Layer - modern Python 2.7.x'
    LayerSuffix = CommandName
    SourceImageName = SystemBaseLayer.TargetImageName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    SaltStateDir = LayerSuffix


class OpenCvLayer(ExampleBuildLayer):
    CommandName = 'opencv'
    Description = 'Build OpenCV layer'
    LayerSuffix = CommandName
    SourceImageName = PythonBaseLayer.TargetImageName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    SaltStateDir = CommandName


class AppLayer(ExampleBuildLayer):
    CommandName = 'app'
    Description = 'Build Flask Example app'
    LayerSuffix = CommandName
    SaltStateDir = LayerSuffix
    SourceImageName = OpenCvLayer.TargetImageName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    ExposedPorts = [80]


class FlaskExampleTestLayer(ExampleBuildLayer):
    CommandName = 'tests'
    Description = 'Build Flask Tests Layer'
    LayerSuffix = CommandName
    SourceImageName = AppLayer.TargetImageName
    TargetImagePrefixName = "{}/{}/{}_{}".format(
            ExampleBuildLayer.Registry, ExampleBuildLayer.Organization, ExampleBuildLayer.AppName, CommandName)
    TargetImageName = TargetImagePrefixName + ":latest"
    SaltStateDir = CommandName


def main():
    base_dir = os.path.abspath(os.path.dirname(__file__))
    defaults = dict(
            base_dir=base_dir,
    )

    # TODO: discovery mechanism
    ExampleBuildLayer.main(
            defaults,
            SystemBaseLayer,
            PythonBaseLayer,
            OpenCvLayer,
            AppLayer,
            description="Build a Flask example Docker image using SaltStack",
    )
{'fraction_non_alphanumeric': 0.08662232076866223, 'fraction_numerical': 0.0023651145602365115, 'mean_word_length': 3.761435608726249, 'pattern_counts': {'":': 10, '<': 4, '<?xml version=': 0, '>': 4, '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': '2361286', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1860, 'n_words': 420}