Skip to content

Commit

Permalink
fix proxy migration
Browse files Browse the repository at this point in the history
  • Loading branch information
chendelin1982 authored Dec 6, 2024
1 parent 2d9362a commit 2f7e4bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion docker/proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ LABEL version="2.11.3-rc1"

COPY README.md /data/nginx/README.md
RUN mkdir /data/nginx/custom
RUN mkdir -p /etc/websoft9
COPY ./config/http.conf /data/nginx/custom/http.conf
COPY ./config/initproxy.conf /data/nginx/default_host/initproxy.conf
COPY ./config/initproxy.conf /etc/websoft9/initproxy.conf
COPY ./init_nginx.sh /app/init_nginx.sh
RUN chmod +x /app/init_nginx.sh

Expand Down
38 changes: 20 additions & 18 deletions docker/proxy/init_nginx.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
#!/bin/bash

# 设置密码目录
# Define variables
credential_path="/data/credential"

# 检查是否已经存在密码文件
# Migrating initproxy.conf file

cp -f /etc/websoft9/initproxy.conf /data/nginx/default_host/initproxy.conf
[ -f /etc/websoft9/initproxy.conf ] && rm -f /data/nginx/proxy_host/initproxy.conf


# If credential file then create it and init credential for NPM
# Reload NPM docker image Environments

if [ ! -f "$credential_path" ]; then
# 设置用户名和生成随机密码
# Set init credential
INITIAL_ADMIN_EMAIL="admin@mydomain.com"
INITIAL_ADMIN_PASSWORD=$(openssl rand -base64 16 | tr -d '/+' | cut -c1-16)

# 设置环境变量
export INITIAL_ADMIN_EMAIL
export INITIAL_ADMIN_PASSWORD

# 写入密码文件
# Write credential to file
mkdir -p "$(dirname "$credential_path")"
credential_json="{\"username\":\"$INITIAL_ADMIN_EMAIL\",\"password\":\"$INITIAL_ADMIN_PASSWORD\"}"
echo "$credential_json" > "$credential_path"
else
# 从密码文件中读取用户名和密码
INITIAL_ADMIN_EMAIL=$(jq -r '.username' "$credential_path")
INITIAL_ADMIN_PASSWORD=$(jq -r '.password' "$credential_path")
echo "{\"username\":\"$INITIAL_ADMIN_EMAIL\",\"password\":\"$INITIAL_ADMIN_PASSWORD\"}" > "$credential_path"

# 设置环境变量
export INITIAL_ADMIN_EMAIL
export INITIAL_ADMIN_PASSWORD
else
read -r INITIAL_ADMIN_EMAIL INITIAL_ADMIN_PASSWORD < <(jq -r '.username + " " + .password' "$credential_path")
fi

# 启动 Nginx
# Reload NPM docker image Environments
export INITIAL_ADMIN_EMAIL
export INITIAL_ADMIN_PASSWORD

# Start NPM
exec /init

0 comments on commit 2f7e4bf

Please sign in to comment.