Esempio n. 1
0
  def preBuild():
    global dockerComposeServicesYaml
    # Setup service directory
    if not os.path.exists(serviceService):
      os.makedirs(serviceService, exist_ok=True)

    os.makedirs(serviceVolume, exist_ok=True)
    os.makedirs(serviceVolume + '/html', exist_ok=True)

    # Multi-service:
    with open((r'%s/' % serviceTemplate) + servicesFileName) as objServiceFile:
      servicesListed = yaml.load(objServiceFile)

    oldBuildCache = {}
    try:
      with open(r'%s' % buildCache) as objBuildCache:
        oldBuildCache = yaml.load(objBuildCache)
    except:
      pass

    buildCacheServices = {}
    if "services" in oldBuildCache:
      buildCacheServices = oldBuildCache["services"]

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

    if os.path.exists(buildSettings):

      # Password randomisation
      with open(r'%s' % buildSettings) as objBuildSettingsFile:
        nextCloudYamlBuildOptions = yaml.load(objBuildSettingsFile)
        if (
          nextCloudYamlBuildOptions["databasePasswordOption"] == "Randomise database password for this build"
          or nextCloudYamlBuildOptions["databasePasswordOption"] == "Randomise database password every build"
          or nextCloudYamlBuildOptions["databasePasswordOption"] == "Use default password for this build"
        ):
          if nextCloudYamlBuildOptions["databasePasswordOption"] == "Use default password for this build":
            mySqlRootPassword = "******"
            mySqlPassword = "******"
          else:
            mySqlPassword = generateRandomString()
            mySqlRootPassword = generateRandomString()

          for (index, serviceName) in enumerate(servicesListed):
            dockerComposeServicesYaml[serviceName] = servicesListed[serviceName]
            if "environment" in servicesListed[serviceName]:
              for (envIndex, envName) in enumerate(servicesListed[serviceName]["environment"]):
                envName = envName.replace("%randomMySqlPassword%", mySqlPassword)
                dockerComposeServicesYaml[serviceName]["environment"][envIndex] = envName.replace("%randomPassword%", mySqlRootPassword)

          # Ensure you update the "Do nothing" and other 2 strings used for password settings in 'passwords.py'
          if (nextCloudYamlBuildOptions["databasePasswordOption"] == "Randomise database password for this build"):
            nextCloudYamlBuildOptions["databasePasswordOption"] = "Do nothing"
            with open(buildSettings, 'w') as outputFile:
              yaml.dump(nextCloudYamlBuildOptions, outputFile)
        else: # Do nothing - don't change password
          for (index, serviceName) in enumerate(buildCacheServices):
            if serviceName in buildCacheServices: # Load service from cache if exists (to maintain password)
              dockerComposeServicesYaml[serviceName] = buildCacheServices[serviceName]
            else:
              dockerComposeServicesYaml[serviceName] = servicesListed[serviceName]

    else:
      print("NextCloud Warning: Build settings file not found, using default password")
      time.sleep(1)
      mySqlRootPassword = "******"
      mySqlPassword = "******"
      for (index, serviceName) in enumerate(servicesListed):
        dockerComposeServicesYaml[serviceName] = servicesListed[serviceName]
        if "environment" in servicesListed[serviceName]:
          for (envIndex, envName) in enumerate(servicesListed[serviceName]["environment"]):
            envName = envName.replace("%randomMySqlPassword%", mySqlPassword)
            dockerComposeServicesYaml[serviceName]["environment"][envIndex] = envName.replace("%randomPassword%", mySqlRootPassword)
        nextCloudYamlBuildOptions = {
          "version": "1",
          "application": "IOTstack",
          "service": "NextCloud",
          "comment": "NextCloud Build Options"
        }

      nextCloudYamlBuildOptions["databasePasswordOption"] = "Do nothing"
      with open(buildSettings, 'w') as outputFile:
        yaml.dump(nextCloudYamlBuildOptions, outputFile)

    return True
Esempio n. 2
0
    def preBuild():
        # Multi-service:
        with open((r'%s/' % serviceTemplate) +
                  servicesFileName) as objServiceFile:
            serviceYamlTemplate = yaml.load(objServiceFile)

        oldBuildCache = {}
        try:
            with open(r'%s' % buildCache) as objBuildCache:
                oldBuildCache = yaml.load(objBuildCache)
        except:
            pass

        buildCacheServices = {}
        if "services" in oldBuildCache:
            buildCacheServices = oldBuildCache["services"]

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

        if os.path.exists(buildSettings):
            # Password randomisation
            with open(r'%s' % buildSettings) as objBuildSettingsFile:
                influxDbYamlBuildOptions = yaml.load(objBuildSettingsFile)
                if (influxDbYamlBuildOptions["databasePasswordOption"]
                        == "Randomise database password for this build"
                        or influxDbYamlBuildOptions["databasePasswordOption"]
                        == "Randomise database password every build"
                        or influxDbYamlBuildOptions["databasePasswordOption"]
                        == "Use default password for this build"):
                    if influxDbYamlBuildOptions[
                            "databasePasswordOption"] == "Use default password for this build":
                        randomPassword = "******"
                    else:
                        randomPassword = generateRandomString()
                    for (index, serviceName) in enumerate(serviceYamlTemplate):
                        dockerComposeServicesYaml[
                            serviceName] = serviceYamlTemplate[serviceName]
                        if "environment" in serviceYamlTemplate[serviceName]:
                            for (envIndex, envName) in enumerate(
                                    serviceYamlTemplate[serviceName]
                                ["environment"]):
                                envName = envName.replace(
                                    "%randomPassword%", randomPassword)
                                dockerComposeServicesYaml[serviceName][
                                    "environment"][envIndex] = envName

                    # Ensure you update the "Do nothing" and other 2 strings used for password settings in 'passwords.py'
                    if (influxDbYamlBuildOptions["databasePasswordOption"] ==
                            "Randomise database password for this build"):
                        influxDbYamlBuildOptions[
                            "databasePasswordOption"] = "Do nothing"
                        with open(buildSettings, 'w') as outputFile:
                            yaml.dump(influxDbYamlBuildOptions, outputFile)
                else:  # Do nothing - don't change password
                    for (index, serviceName) in enumerate(buildCacheServices):
                        if serviceName in buildCacheServices:  # Load service from cache if exists (to maintain password)
                            dockerComposeServicesYaml[
                                serviceName] = buildCacheServices[serviceName]
                        else:
                            dockerComposeServicesYaml[
                                serviceName] = serviceYamlTemplate[serviceName]

        else:
            print(
                "InfluxDB Warning: Build settings file not found, using default password"
            )
            time.sleep(1)
            randomPassword = "******"
            for (index, serviceName) in enumerate(serviceYamlTemplate):
                dockerComposeServicesYaml[serviceName] = serviceYamlTemplate[
                    serviceName]
                if "environment" in serviceYamlTemplate[serviceName]:
                    for (envIndex, envName) in enumerate(
                            serviceYamlTemplate[serviceName]["environment"]):
                        envName = envName.replace("%randomPassword%",
                                                  randomPassword)
                        dockerComposeServicesYaml[serviceName]["environment"][
                            envIndex] = envName
                influxDbYamlBuildOptions = {
                    "version": "1",
                    "application": "IOTstack",
                    "service": "InfluxDB",
                    "comment": "InfluxDB Build Options"
                }

            influxDbYamlBuildOptions["databasePasswordOption"] = "Do nothing"
            with open(buildSettings, 'w') as outputFile:
                yaml.dump(influxDbYamlBuildOptions, outputFile)

        return True