Static postgres host in docker

This commit is contained in:
Nicolas Meienberger 2022-07-06 11:15:35 +02:00
parent 28f7e7f3d7
commit efca46ccc8
4 changed files with 45 additions and 13 deletions

View file

@ -12,10 +12,10 @@ services:
- 5432:5432
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USERNAME: ${POSTGRES_USERNAME}
POSTGRES_DBNAME: ${POSTGRES_DBNAME}
POSTGRES_USERNAME: tipi
POSTGRES_DBNAME: tipi
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DBNAME} -U $${POSTGRES_USERNAME}" ]
test: [ "CMD-SHELL", "pg_isready -d tipi -U tipi" ]
interval: 5s
timeout: 10s
retries: 120
@ -45,10 +45,10 @@ services:
JWT_SECRET: ${JWT_SECRET}
ROOT_FOLDER_HOST: ${ROOT_FOLDER_HOST}
NGINX_PORT: ${NGINX_PORT}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USERNAME}
POSTGRES_DB: ${POSTGRES_DBNAME}
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_PASSWORD: tipi
POSTGRES_USERNAME: tipi
POSTGRES_DBNAME: ${POSTGRES_DBNAME}
POSTGRES_HOST: tipi-db
networks:
- tipi_main_network

View file

@ -15,6 +15,27 @@ services:
networks:
- tipi_main_network
tipi-db:
container_name: tipi-db
image: postgres:latest
restart: on-failure
stop_grace_period: 1m
volumes:
- ./data/postgres:/var/lib/postgresql/data
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USERNAME: tipi
POSTGRES_DBNAME: tipi
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d tipi -U tipi" ]
interval: 5s
timeout: 10s
retries: 120
networks:
- tipi_main_network
api:
image: meienberger/runtipi:${TIPI_VERSION}
command: bash -c "cd /api && npm run start"
@ -22,16 +43,23 @@ services:
container_name: api
ports:
- 3001:3001
depends_on:
tipi-db:
condition: service_healthy
volumes:
## Docker sock
- /var/run/docker.sock:/var/run/docker.sock:ro
- ${PWD}:/tipi
environment:
- INTERNAL_IP=${INTERNAL_IP}
- TIPI_VERSION=${TIPI_VERSION}
- JWT_SECRET=${JWT_SECRET}
- ROOT_FOLDER_HOST=${ROOT_FOLDER_HOST}
- NGINX_PORT=${NGINX_PORT}
INTERNAL_IP: ${INTERNAL_IP}
TIPI_VERSION: ${TIPI_VERSION}
JWT_SECRET: ${JWT_SECRET}
ROOT_FOLDER_HOST: ${ROOT_FOLDER_HOST}
NGINX_PORT: ${NGINX_PORT}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USERNAME: tipi
POSTGRES_DBNAME: tipi
POSTGRES_HOST: tipi-db
networks:
- tipi_main_network

View file

@ -142,6 +142,7 @@ ENV_FILE=$(mktemp)
[[ -f "$ROOT_FOLDER/templates/env-sample" ]] && cp "$ROOT_FOLDER/templates/env-sample" "$ENV_FILE"
JWT_SECRET=$(derive_entropy "jwt")
POSTGRES_PASSWORD=$(derive_entropy "postgres")
for template in ${ENV_FILE}; do
sed -i "s/<dns_ip>/${DNS_IP}/g" "${template}"
@ -153,6 +154,7 @@ for template in ${ENV_FILE}; do
sed -i "s/<architecture>/${ARCHITECTURE}/g" "${template}"
sed -i "s/<nginx_port>/${NGINX_PORT}/g" "${template}"
sed -i "s/<proxy_port>/${PROXY_PORT}/g" "${template}"
sed -i "s/<postgres_password>/${POSTGRES_PASSWORD}/g" "${template}"
done
mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"

View file

@ -10,3 +10,5 @@ JWT_SECRET=<jwt_secret>
ROOT_FOLDER_HOST=<root_folder>
NGINX_PORT=<nginx_port>
PROXY_PORT=<proxy_port>
POSTGRES_PASSWORD=<postgres_password>