Пример #1
0
    def buildServices(
    ):  # TODO: Move this into a dependency so that it can be executed with just a list of services.
        global dockerComposeServicesYaml
        try:
            runPrebuildHook()
            dockerFileYaml = {}
            menuStateFileYaml = {}
            dockerFileYaml[
                "version"] = "2.4"  #original was 3.6 changing to 2.4
            dockerFileYaml["services"] = {}
            menuStateFileYaml["services"] = {}
            dockerFileYaml["services"] = dockerComposeServicesYaml
            menuStateFileYaml["services"] = dockerComposeServicesYaml

            if os.path.exists(envFile):
                with open(r'%s' % envFile) as fileEnv:
                    envSettings = yaml.load(fileEnv)
                mergedYaml = mergeYaml(envSettings, dockerFileYaml)
                dockerFileYaml = mergedYaml

            if os.path.exists(composeOverrideFile):
                with open(r'%s' % composeOverrideFile) as fileOverride:
                    yamlOverride = yaml.load(fileOverride)

                mergedYaml = mergeYaml(yamlOverride, dockerFileYaml)
                dockerFileYaml = mergedYaml

            with open(r'%s' % dockerPathOutput, 'w') as outputFile:
                yaml.dump(dockerFileYaml, outputFile)

            if not os.path.exists(servicesDirectory):
                os.makedirs(servicesDirectory, exist_ok=True)

            with open(r'%s' % dockerSavePathOutput, 'w') as outputFile:
                yaml.dump(menuStateFileYaml, outputFile)
            runPostBuildHook()

            if os.path.exists('./postbuild.sh'):
                servicesList = ""
                for (index,
                     serviceName) in enumerate(dockerComposeServicesYaml):
                    servicesList += " " + serviceName
                subprocess.call("./postbuild.sh" + servicesList, shell=True)
            else:
                print("not found")

            return True
        except Exception as err:
            print("Issue running build:")
            print(err)
            input("Press Enter to continue...")
            return False
Пример #2
0
def buildServices(dockerComposeServicesYaml):
    try:
        runPrebuildHook()
        dockerFileYaml = {}
        menuStateFileYaml = {}
        dockerFileYaml["version"] = "3.6"
        dockerFileYaml["services"] = {}
        menuStateFileYaml["services"] = {}
        dockerFileYaml["services"] = dockerComposeServicesYaml
        menuStateFileYaml["services"] = dockerComposeServicesYaml

        if os.path.exists(envFile):
            with open(r'%s' % envFile) as fileEnv:
                envSettings = yaml.load(fileEnv)
            mergedYaml = mergeYaml(envSettings, dockerFileYaml)
            dockerFileYaml = mergedYaml

        if os.path.exists(composeOverrideFile):
            with open(r'%s' % composeOverrideFile) as fileOverride:
                yamlOverride = yaml.load(fileOverride)

            mergedYaml = mergeYaml(yamlOverride, dockerFileYaml)
            dockerFileYaml = mergedYaml

        with open(r'%s' % dockerPathOutput, 'w') as outputFile:
            yaml.dump(dockerFileYaml,
                      outputFile,
                      explicit_start=True,
                      default_style='"')

        with open(r'%s' % buildCache, 'w') as outputFile:
            yaml.dump(menuStateFileYaml,
                      outputFile,
                      explicit_start=True,
                      default_style='"')
        runPostBuildHook()
        return True
    except Exception as err:
        print("Issue running build:")
        print(err)
        input("Press Enter to continue...")
        return False