Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dind installation docking resource problem #1474

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions default_region_sqlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# -*- coding: UTF-8 -*-
import datetime
import os
import uuid

import sqlite3


def create_db_client():
db = sqlite3.connect('/app/data/db.sqlite3')
return db


def make_uuid(key=None):
random_uuid = str(uuid.uuid4()).replace('-', '')
return random_uuid


def get_region_id():
return make_uuid()


def get_url():
return os.environ.get('REGION_URL')


def get_wsurl():
return os.environ.get('REGION_WS_URL')


def get_http_domain():
return os.environ.get('REGION_HTTP_DOMAIN')


def get_tcp_domain():
return os.environ.get('REGION_TCP_DOMAIN')


# 获取文件的内容
def get_contends(path):
with open(path) as file_object:
contends = file_object.read()
return contends


def get_ssl_ca_cert():
content = get_contends("/app/region/ssl/ca.pem")
print(content)
return content


def get_cert_file():
content = get_contends("/app/region/ssl/client.pem")
print(content)
return content


def get_key_file():
content = get_contends("/app/region/ssl/client.key.pem")
print(content)
return content


def get_current_time():
create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(create_time)
return create_time


def get_sql():
sql = 'INSERT INTO region_info (`region_id`,`region_name`,`region_alias`,`url`,`status`,`desc`,`wsurl`, \
`httpdomain`,`tcpdomain`,`scope`,`ssl_ca_cert`,`cert_file`,`key_file`,`create_time`) VALUES ("{0}", "rainbond", \
"默认集群", "{1}", "1", "当前集群是默认安装添加的集群", "{2}", "{3}", "{4}", "private", \
"{5}", "{6}", "{7}", "{8}" )'.format(get_region_id(), get_url(), get_wsurl(), get_http_domain(), get_tcp_domain(),
get_ssl_ca_cert(), get_cert_file(), get_key_file(), get_current_time())
print(sql)
return sql


def insert_default_region_info():
sql = get_sql()
db = create_db_client()
cursor = db.cursor()
cursor.execute(sql)
cursor.close()
db.commit()
db.close()


def get_region_info():
print("get region info")
db = create_db_client()
cursor = db.cursor()
cursor.execute("select * from region_info")
data = cursor.fetchone()
cursor.close()
db.commit()
db.close()
return data


if __name__ == '__main__':
print("Initialize default region info ")
region_info = get_region_info()
if region_info:
print("default region info already exists, skip it")
else:
print("default region info do not exists, init it")
insert_default_region_info()
print("init default region info success")
30 changes: 22 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,36 @@ function init_database() {
return 0
}

if [ "$1" = "debug" -o "$1" = "bash" ]; then
exec /bin/bash
elif [ "$1" = "version" ]; then
echo "${RELEASE_DESC}"
elif [ "$1" = "init" ]; then
if ! (init_database); then
use_sqlite() {
# shellcheck disable=SC1035
if !(python default_region_sqlite.py 2> /dev/null); then
echo -e "${RED}failed to default_region${NC}"
exit 1
fi
}

use_mysql() {
if !(python default_region.py 2> /dev/null); then
echo -e "${RED}failed to default_region${NC}"
exit 1
echo -e "${RED}failed to default_region${NC}"
exit 1
fi
}

if [ "$1" = "debug" -o "$1" = "bash" ]; then
exec /bin/bash
elif [ "$1" = "version" ]; then
echo "${RELEASE_DESC}"
else
if ! (init_database); then
exit 1
fi
if [ "${INSTALL_TYPE}" != "allinone" ]; then
if [ "$DB_TYPE" != "mysql" ]; then
use_sqlite
else
use_mysql
fi
fi
# python upgrade.py
exec gunicorn goodrain_web.wsgi -b 0.0.0.0:${PORT:-7070} --max-requests=5000 -k gevent --reload --workers=2 --timeout=75 --log-file - --access-logfile - --error-logfile -
fi
2 changes: 1 addition & 1 deletion openapi/sub_urls/app_url.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# creater by: barnett
from console.utils import perms_route_config as perms

from django.conf.urls import url
from openapi.views.apps.apps import (AppInfoView, APPOperationsView, AppServiceEventsView, AppServicesView,
AppServiceTelescopicHorizontalView, AppServiceTelescopicVerticalView, ComponentBuildView,
Expand Down
1 change: 0 additions & 1 deletion openapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# creater by: barnett
import os

from console.utils import perms_route_config as perms
from django.conf.urls import include, url
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
Expand Down
Loading