提交 3cc83329 编写于 作者: T TommyLike 提交者: Gitee

回退 'Pull Request !9 : 使用华为云数据库提供mailman web数据存储能力'

上级 e06bfc1f
# infrastructure2222
# infrastructure
### Brief Introduction
......
......@@ -3,52 +3,85 @@ set -e
function wait_for_postgres () {
# Check if the default postgres database is up and accepting connections before
# Check if the postgres database is up and accepting connections before
# moving forward.
# TODO: Use python's psycopg2 module to do this in python instead of
# installing postgres-client in the image.
until psql $DEFAULT_URL -c '\l'; do
until psql $DATABASE_URL -c '\l'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - continuing"
}
function create_default_database() {
if [[ "$( psql $DEFAULT_URL -tAc "SELECT 1 FROM pg_database WHERE datname='$DB_NAME'" )" = '1' ]]; then
echo "Database already exists, skipping creating"
else
echo "creating new database for mailman web"
psql $DEFAULT_URL -c "CREATE DATABASE $DB_NAME;"
function wait_for_mysql () {
# Check if MySQL is up and accepting connections.
HOSTNAME=$(python3 <<EOF
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
o = urlparse('$DATABASE_URL')
print(o.hostname)
EOF
)
until mysqladmin ping --host "$HOSTNAME" --silent; do
>&2 echo "MySQL is unavailable - sleeping"
sleep 1
done
>&2 echo "MySQL is up - continuing"
}
function check_or_create () {
# Check if the path exists, if not, create the directory.
if [[ ! -e dir ]]; then
echo "$1 does not exist, creating ..."
mkdir "$1"
fi
}
# function postgres_ready(){
# python << END
# import sys
# import psycopg2
# try:
# conn = psycopg2.connect(dbname="$POSTGRES_DB", user="$POSTGRES_USER", password="$POSTGRES_PASSWORD", host="postgres")
# except psycopg2.OperationalError:
# sys.exit(-1)
# sys.exit(0)
# END
# }
# Check if $SECRET_KEY is defined, if not, bail out.
if [[ ! -v SECRET_KEY ]]; then
echo "SECRET_KEY is not defined. Aborting."
exit 1
fi
if [[ ! -v DATABASE_URL_PREFIX ]]; then
echo "DATABASE_URL_PREFIX is not defined. Aborting..."
exit 1
# Check if $DATABASE_URL is defined, if not, use a standard sqlite database.
#
# If the $DATABASE_URL is defined and is postgres, check if it is available
# yet. Do not start the container before the postgresql boots up.
#
# If the $DATABASE_URL is defined and is mysql, check if the database is
# available before the container boots up.
#
# TODO: Check the database type and detect if it is up based on that. For now,
# assume that postgres is being used if DATABASE_URL is defined.
if [[ ! -v DATABASE_URL ]]; then
echo "DATABASE_URL is not defined. Using sqlite database..."
export DATABASE_URL=sqlite://mailmanweb.db
export DATABASE_TYPE='sqlite'
fi
if [[ ! -v DB_NAME ]]; then
echo "DB_NAME is not defined. Aborting..."
exit 1
fi
export DATABASE_URL="$DATABASE_URL_PREFIX/$DB_NAME"
# this is the default database that will exist on a new created Postgres service on huaweicloud.
export DEFAULT_URL="$DATABASE_URL_PREFIX/postgres"
if [[ "$DATABASE_TYPE" = 'postgres' ]]
then
wait_for_postgres
create_default_database
else
echo "Entrypoint.sh only support postgres, please check and update"
exit 1
elif [[ "$DATABASE_TYPE" = 'mysql' ]]
then
wait_for_mysql
fi
# Check if we are in the correct directory before running commands.
......
# StatefulSet for postgres database service
---
kind: StatefulSet
apiVersion: apps/v1beta1
metadata:
name: mailman-database
namespace: mail
labels:
app: mail-suit-service
spec:
serviceName: mail-suit-service
replicas: 1
selector:
matchLabels:
app: mail-suit-service
template:
metadata:
labels:
app: mail-suit-service
spec:
containers:
- name: mailman-database
image: postgres:9.6-alpine
imagePullPolicy: "IfNotPresent"
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: mailman-database-volume
subPath: postgres
env:
- name: POSTGRES_DB
value: mailmandb
- name: POSTGRES_USER
value: mailman
- name: POSTGRES_PASSWORD
value: mailmanpass
- name: PGDATA
value: /var/lib/postgresql/data/postgres
#NOTE: Empty dir can't be used in a production dir. Please upgrade it before using.
volumes:
- name: mailman-database-volume
persistentVolumeClaim:
claimName: db-data-vol
## define the postgros volume
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-data-vol
namespace: mail
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
storageClassName: ssd
volumeMode: Filesystem
## define the config volume for both mail-core & exim4
---
apiVersion: v1
......
......@@ -58,7 +58,7 @@ spec:
containers:
- name: mailman-web
# We modified the mail-web image to add static folder.
image: swr.cn-north-1.myhuaweicloud.com/openeuler/mail-web:v1.0.1
image: swr.cn-north-1.myhuaweicloud.com/openeuler/mail-web:v1.0.0
imagePullPolicy: "IfNotPresent"
volumeMounts:
- mountPath: /opt/mailman-web-config
......@@ -73,12 +73,8 @@ spec:
env:
- name: DATABASE_TYPE
value: postgres
- name: DATABASE_URL_PREFIX
#NOTE: Replace Postgres-Service-ConnectionURL with real connection info.
#For instance postgres://username:password@internal_ip_address:5432
value: <Postgres-Service-ConnectionURL>
- name: DB_NAME
value: mailmandb
- name: DATABASE_URL
value: postgres://mailman:mailmanpass@mailman-database-0.mail-suit-service.mail.svc.cluster.local/mailmandb
- name: HYPERKITTY_API_KEY
valueFrom:
secretKeyRef:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册