From dcd8479c79d7f0595b3a44e5041e49d5461e755e Mon Sep 17 00:00:00 2001 From: Corey Sotiropoulos Date: Mon, 7 Apr 2025 03:26:51 -0400 Subject: [PATCH] Fix tracking issues with .env --- .env | 0 .gitignore | 2 +- README.md | 4 ++-- docker-compose.yml | 4 ++-- entrypoint.sh | 3 +++ mariadb-entrypoint.sh | 6 +++--- 6 files changed, 11 insertions(+), 8 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index e69de29..0000000 diff --git a/.gitignore b/.gitignore index 4c49bd7..30fa1ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -.env +config \ No newline at end of file diff --git a/README.md b/README.md index 240a128..e8cfb71 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ That's it! All the setup is handled for you. Check out the [official LSB documen ## Notes - If using WSL with Windows, make sure [the project is stored in the WSL file system](https://learn.microsoft.com/en-us/windows/wsl/filesystems#file-storage-and-performance-across-file-systems) for best performance. -- To facilitate automatically generating secure database passwords and simplify the setup process, the `.env` file is intentionally empty and untracked by Git. - - **Optional** - You can manually populate this _before_ building the containers with these variables: +- Secure database passwords and a default user and database name are generated into `config/.env` to simplify the setup process. + - **Optional** - You can manually create this _before_ building the containers with these variables: ``` MARIADB_DATABASE= MARIADB_USER= diff --git a/docker-compose.yml b/docker-compose.yml index c3ac205..a24f8b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,13 @@ x-common: &common # Configs used by more than one service. image: lsd_service pull_policy: never - env_file: .env # Automatically generated by MariaDB service entrypoint. entrypoint: ["/entrypoint.sh"] # Copies the MariaDB env vars into corresponding LSB settings. environment: XI_NETWORK_HTTP_HOST: 0.0.0.0 XI_NETWORK_ZMQ_IP: world XI_NETWORK_SQL_HOST: database volumes: # YAML merge can't be used with sequences, so bind everything here. (SEE NOTE ABOUT WSL IN README!) + - ./config:/config - ./.git:/.git # Since LSB is a submodule, we want to preserve - ./server/.git:/server/.git # the directory structure inside the container. - ./server/log:/server/log @@ -26,7 +26,7 @@ services: entrypoint: ["/mariadb-entrypoint.sh"] restart: always volumes: - - ./.env:/env/.env + - ./config:/config - ./mariadb-entrypoint.sh:/mariadb-entrypoint.sh # Custom entrypoint to generate .env. - ./server/sql:/docker-entrypoint-initdb.d # Initializes the database. - database:/var/lib/mysql diff --git a/entrypoint.sh b/entrypoint.sh index 8211c66..6f7bfd4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,9 @@ #!/bin/bash # Export XI_ variables from corresponding MARIADB_ variables. +set -a +source "/config/.env" +set +a export XI_NETWORK_SQL_DATABASE=$MARIADB_DATABASE export XI_NETWORK_SQL_LOGIN=$MARIADB_USER export XI_NETWORK_SQL_PASSWORD="$MARIADB_PASSWORD" diff --git a/mariadb-entrypoint.sh b/mariadb-entrypoint.sh index fcc5bc6..015fdd9 100755 --- a/mariadb-entrypoint.sh +++ b/mariadb-entrypoint.sh @@ -1,9 +1,9 @@ #!/bin/bash -ENV_FILE="/env/.env" +ENV_FILE="/config/.env" -# Set default values if the .env file is empty. -if [ ! -s "$ENV_FILE" ]; then +# Set default values if the .env file doesn't exist. +if [ ! -e "$ENV_FILE" ]; then MARIADB_DATABASE=xidb MARIADB_USER=xiadmin XI_NETWORK_ENABLE_HTTP=1