From 5015f8b59d8b6f883cf35196867bb5ad89e70927 Mon Sep 17 00:00:00 2001 From: ukkopahis <95980324+ukkopahis@users.noreply.github.com> Date: Sun, 19 Jun 2022 09:23:52 +0300 Subject: [PATCH] timescaledb: fix broken template Implements and resolves #232 Also changes user to reflect the strong recommendation of #287 As %randomPassword% doesn't seem to work, change to use the default password as listed on Default-Configs.md and add support for #505 style variables. Change default public port from 5433 to avoid port-conflict with posgresql. --- .templates/timescaledb/build.py | 116 ---------------------------- .templates/timescaledb/service.yml | 24 +++--- docs/Basic_setup/Default-Configs.md | 2 +- docs/Containers/Timescaledb.md | 8 ++ 4 files changed, 21 insertions(+), 129 deletions(-) delete mode 100755 .templates/timescaledb/build.py create mode 100644 docs/Containers/Timescaledb.md diff --git a/.templates/timescaledb/build.py b/.templates/timescaledb/build.py deleted file mode 100755 index abb3f75d..00000000 --- a/.templates/timescaledb/build.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python3 - -issues = {} # Returned issues dict -buildHooks = {} # Options, and others hooks -haltOnErrors = True - -# Main wrapper function. Required to make local vars work correctly -def main(): - import os - import time - import sys - - from deps.consts import servicesDirectory, templatesDirectory - from deps.common_functions import getExternalPorts, getInternalPorts, checkPortConflicts - - global dockerComposeServicesYaml # The loaded memory YAML of all checked services - global toRun # Switch for which function to run when executed - global buildHooks # Where to place the options menu result - global currentServiceName # Name of the current service - global issues # Returned issues dict - global haltOnErrors # Turn on to allow erroring - global hideHelpText # Showing and hiding the help controls text - global serviceService - - serviceService = servicesDirectory + currentServiceName - serviceTemplate = templatesDirectory + currentServiceName - - try: # If not already set, then set it. - hideHelpText = hideHelpText - except: - hideHelpText = False - - # runtime vars - portConflicts = [] - - # This lets the menu know whether to put " >> Options " or not - # This function is REQUIRED. - def checkForOptionsHook(): - try: - buildHooks["options"] = callable(runOptionsMenu) - except: - buildHooks["options"] = False - return buildHooks - return buildHooks - - # This function is REQUIRED. - def checkForPreBuildHook(): - try: - buildHooks["preBuildHook"] = callable(preBuild) - except: - buildHooks["preBuildHook"] = False - return buildHooks - return buildHooks - - # This function is REQUIRED. - def checkForPostBuildHook(): - try: - buildHooks["postBuildHook"] = callable(postBuild) - except: - buildHooks["postBuildHook"] = False - return buildHooks - return buildHooks - - # This function is REQUIRED. - def checkForRunChecksHook(): - try: - buildHooks["runChecksHook"] = callable(runChecks) - except: - buildHooks["runChecksHook"] = False - return buildHooks - return buildHooks - - # This service will not check anything unless this is set - # This function is optional, and will run each time the menu is rendered - def runChecks(): - checkForIssues() - return [] - - # This function is optional, and will run after the docker-compose.yml file is written to disk. - def postBuild(): - return True - - # This function is optional, and will run just before the build docker-compose.yml code. - def preBuild(): - return True - - # ##################################### - # Supporting functions below - # ##################################### - - def checkForIssues(): - for (index, serviceName) in enumerate(dockerComposeServicesYaml): - if not currentServiceName == serviceName: # Skip self - currentServicePorts = getExternalPorts(currentServiceName, dockerComposeServicesYaml) - portConflicts = checkPortConflicts(serviceName, currentServicePorts, dockerComposeServicesYaml) - if (len(portConflicts) > 0): - issues["portConflicts"] = portConflicts - - # ##################################### - # End Supporting functions - # ##################################### - - if haltOnErrors: - eval(toRun)() - else: - try: - eval(toRun)() - except: - pass - -# This check isn't required, but placed here for debugging purposes -global currentServiceName # Name of the current service -if currentServiceName == 'timescaledb': - main() -else: - print("Error. '{}' Tried to run 'timescaledb' config".format(currentServiceName)) diff --git a/.templates/timescaledb/service.yml b/.templates/timescaledb/service.yml index 23293646..f47dfe42 100644 --- a/.templates/timescaledb/service.yml +++ b/.templates/timescaledb/service.yml @@ -1,13 +1,13 @@ -timescaledb: - container_name: timescaledb - image: timescale/timescaledb:latest-pg12 - restart: unless-stopped - environment: - POSTGRES_USER=timescaleuser - POSTGRES_PASSWORD=%randomPassword% - POSTGRES_DB=postdb - ports: - - "5432:5432" - volumes: - - ./volumes/timescaledb/data:/var/lib/postgresql/data + timescaledb: + container_name: timescaledb + image: timescale/timescaledb:latest-pg12 + restart: unless-stopped + environment: + - POSTGRES_USER=${IOTSTACK_TIMESCALEDB_USER:-postgres} + - POSTGRES_PASSWORD={IOTSTACK_TIMESCALEDB_INITIAL_PASSWORD:-IOtSt4ckTim3Scale} + - POSTGRES_DB=postdb + ports: + - ${IOTSTACK_TIMESCALEDB_PORT_INT:-5433}:5432 + volumes: + - ./volumes/timescaledb/data:/var/lib/postgresql/data diff --git a/docs/Basic_setup/Default-Configs.md b/docs/Basic_setup/Default-Configs.md index 88594b51..a3240e49 100644 --- a/docs/Basic_setup/Default-Configs.md +++ b/docs/Basic_setup/Default-Configs.md @@ -38,7 +38,7 @@ Do note that the ports listed are not all of the ports containers use. They are | rtl_433 | *none* | *none* | *none* | No | | tasmoadmin | *none* | *none* | 8088 | No | | telegraf | *none* | *none* | *none* | No | -| timescaledb | timescaleuser | IOtSt4ckTim3Scale | *none* | No | +| timescaledb | postgres | IOtSt4ckTim3Scale | *none* | No | | transmission | *none* | *none* | 9091 | No | | webthingsio_gateway | *none* | *none* | 4060 | No | | zigbee2mqtt | *none* | *none* | *none* | No | diff --git a/docs/Containers/Timescaledb.md b/docs/Containers/Timescaledb.md new file mode 100644 index 00000000..fafcd8b6 --- /dev/null +++ b/docs/Containers/Timescaledb.md @@ -0,0 +1,8 @@ + +### Default port changed + +In order to avoid port conflict with PostgreSQL, the public database port is +mapped to **5433** using Docker. + +Cross-container access from other containers still works as previously: +`timescaledb:5432`.