update
All checks were successful
Setup Docker Action / setup_docker (3.12.7) (push) Has been skipped

This commit is contained in:
hoangvv 2025-01-15 10:25:27 +07:00
parent 530900a6be
commit 544997a004
4 changed files with 22 additions and 9 deletions

View File

@ -34,9 +34,14 @@ jobs:
with: with:
postgresql version: '16' postgresql version: '16'
- name : Test postgres - name: Make envfile
run: psql postgresql://postgres:postgres@localhost:5432/postgres -c "SELECT 1" uses: SpicyPizza/create-envfile@v2.0
with:
PG_USER: ${{ secrets.PG_USER }}
PG_PASSWORD: ${{ secrets.PG_PASSWORD }}
DB_SERVER: ${{ vars.DB_SERVER }}
DB_PORT: ${{ vars.DB_PORT }}
- name: Generate Config - name: Generate Config
run: make gen_config run: make gen_config

3
.gitignore vendored
View File

@ -49,4 +49,5 @@ package.json
/man/ /man/
/share/ /share/
/src/ /src/
/deployment/postgresql/* /deployment/postgresql/*
venv/*

View File

@ -1,3 +1,4 @@
include .env
.SHELLFLAGS += ${SHELLFLAGS} -e .SHELLFLAGS += ${SHELLFLAGS} -e
PWD = $(shell pwd) PWD = $(shell pwd)
UID = $(shell id -u) UID = $(shell id -u)

View File

@ -192,24 +192,30 @@ Generate_Config_Docker(){
Show 0 " Generate Config Complete" Show 0 " Generate Config Complete"
} }
Generate_Config_Native(){ Generate_Config_Native(){
# Load environment variables from .env file
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
else
Show 1 ".env file not found!"
exit 1
fi
ADDONS=${1:-} ADDONS=${1:-}
REPO_NAME=$(basename "$(git rev-parse --show-toplevel)" | sed -E 's/[.-]/_/g') REPO_NAME=$(basename "$(git rev-parse --show-toplevel)" | sed -E 's/[.-]/_/g')
USER="${REPO_NAME:-"default_repo"}" USER="${REPO_NAME:-"default_repo"}"
DB_PORT=$(sudo -u postgres psql -t -c "SHOW port;" | awk '{print $1}' || echo 5432)
PASSWORD="$(openssl rand -hex 24)" PASSWORD="$(openssl rand -hex 24)"
# Check if the user already exists # Check if the user already exists
USER_EXISTS=$(sudo -u postgres psql -t -c "SELECT 1 FROM pg_roles WHERE rolname='$USER';") USER_EXISTS=$(psql "postgresql://${PG_USER}:${PG_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "SELECT 1 FROM pg_roles WHERE rolname='$USER';")
if [ -z "$USER_EXISTS" ]; then if [ -z "$USER_EXISTS" ]; then
# User does not exist, create the user # User does not exist, create the user
Show 2 "Create the new PostgreSQL username: $USER with password: $PASSWORD" Show 2 "Create the new PostgreSQL username: $USER with password: $PASSWORD"
sudo -u postgres psql -c "CREATE USER $USER WITH PASSWORD '$PASSWORD';" psql "postgresql://${PG_USER}:${PG_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "CREATE USER $USER WITH PASSWORD '$PASSWORD';"
Show 2 " Grant $USER superuser (admin) privileges" Show 2 " Grant $USER superuser (admin) privileges"
sudo -u postgres psql -c "ALTER USER $USER WITH SUPERUSER;" psql "postgresql://${PG_USER}:${PG_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH SUPERUSER;"
else else
# User exists, update the password # User exists, update the password
Show 2 "User $USER already exists, updating password to $PASSWORD" Show 2 "User $USER already exists, updating password to $PASSWORD"
sudo -u postgres psql -c "ALTER USER $USER WITH PASSWORD '$PASSWORD';" psql "postgresql://${PG_USER}:${PG_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH PASSWORD '$PASSWORD';"
fi fi
${PYTHON} "$SETUP_PATH/gen_config.py" --db_user $USER --db_pass $PASSWORD --deploy_path "$(pwd)" \ ${PYTHON} "$SETUP_PATH/gen_config.py" --db_user $USER --db_pass $PASSWORD --deploy_path "$(pwd)" \
--addons_path $ADDONS --db_port $DB_PORT --addons_path $ADDONS --db_port $DB_PORT