SiloCityLabs / lochnas

Docker configuration for all-in-one nas setup
https://lochnas.com
GNU General Public License v3.0
51 stars 3 forks source link

Generate htpasswd on startup for nginx #42

Closed ldrrp closed 2 years ago

ldrrp commented 2 years ago

Problem

The user may change the configured passwords and we need to update that file on startup.

Solution

On startup if nginx is enabled we need to generate the htpasswd file. This can be done by adding a script to the docker-templates/nginx/startup.sh path. The code is already configured to handle the case where the file already exists. Double check app.go to make sure thats the correct path.

Old bash script:

#!/bin/bash

# ==========================
# NGINX
# ==========================
if [[ $NGINX_ENABLED == "true" ]]; then
   DOCKER_FILES=$DOCKER_FILES" -f docker-templates/nginx/docker-compose.yml"

   data_dir_exists "nginx"

   #Generate htpasswd
   NGINX_PASSWORD="$(openssl passwd -1 $NGINX_PASSWORD)"
   echo "$NGINX_USERNAME:$NGINX_PASSWORD" > $GLOBAL_ROOT/docker-data/nginx/.htpasswd
fi

Steps to Reproduce the Problem

  1. Update password configuration in .env file
  2. Run server ./server.bin