From 58f60d126e010724af88222f6d2bf89485805481 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 10 Aug 2022 16:38:51 +0800 Subject: [PATCH 01/19] Update docs/docker --- docs/docker/Dockerfile | 22 ++++++++++--------- docs/docker/docker-compose.yml | 34 +++++++++++++++++++++++++++++ docs/docker/entrypoint.sh | 40 ++++++++++++---------------------- docs/docker/nginx.conf | 2 +- docs/docker/spug.ini | 4 ---- 5 files changed, 61 insertions(+), 41 deletions(-) create mode 100644 docs/docker/docker-compose.yml diff --git a/docs/docker/Dockerfile b/docs/docker/Dockerfile index 2be65fb..09b509a 100644 --- a/docs/docker/Dockerfile +++ b/docs/docker/Dockerfile @@ -1,35 +1,37 @@ -FROM centos:7.8.2003 +FROM centos:7.9.2009 ENV TZ=Asia/Shanghai -RUN yum install -y epel-release https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm && yum install -y --setopt=tsflags=nodocs nginx redis mariadb-server mariadb-devel python36 python36-devel openldap-devel supervisor git gcc wget sshpass rsync sshfs && yum -y clean all --enablerepo='*' +RUN yum install -y epel-release https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm && yum install -y --setopt=tsflags=nodocs nginx redis mariadb-devel python36 python36-devel openldap-devel supervisor git gcc wget unzip net-tools sshpass rsync sshfs && yum -y clean all --enablerepo='*' -RUN pip3 install --upgrade pip -i https://pypi.doubanio.com/simple/ -RUN pip3 install --no-cache-dir -i https://pypi.doubanio.com/simple/ \ +RUN pip3 install --no-cache-dir --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/ +RUN pip3 install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ \ gunicorn \ mysqlclient \ + cryptography==36.0.2 \ apscheduler==3.7.0 \ asgiref==3.2.10 \ - Django==2.2.27 \ + Django==2.2.28 \ channels==2.3.1 \ channels_redis==2.4.1 \ paramiko==2.11.0 \ django-redis==4.10.0 \ requests==2.22.0 \ GitPython==3.0.8 \ - python-ldap==3.2.0 \ - openpyxl==3.0.3 + python-ldap==3.4.0 \ + openpyxl==3.0.3 \ + user_agents==2.2.0 +RUN localedef -c -i en_US -f UTF-8 en_US.UTF-8 ENV LANG=en_US.UTF-8 +ENV LC_ALL=en_US.UTF-8 RUN echo -e '\n# Source definitions\n. /etc/profile\n' >> /root/.bashrc -RUN mkdir /data +RUN mkdir -p /data/repos COPY init_spug /usr/bin/ COPY nginx.conf /etc/nginx/ COPY ssh_config /etc/ssh/ COPY spug.ini /etc/supervisord.d/ -COPY my.cnf /etc/ COPY redis.conf /etc/ COPY entrypoint.sh / -COPY spug.tar.gz /tmp/ VOLUME /data EXPOSE 80 diff --git a/docs/docker/docker-compose.yml b/docs/docker/docker-compose.yml new file mode 100644 index 0000000..a167e03 --- /dev/null +++ b/docs/docker/docker-compose.yml @@ -0,0 +1,34 @@ +version: "3.3" +services: + db: + image: mariadb:10.8 + container_name: spug-db + restart: always + command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + volumes: + - /data/spug/mysql:/var/lib/mysql + environment: + - MYSQL_DATABASE=spug + - MYSQL_USER=spug + - MYSQL_PASSWORD=spug.cc + - MYSQL_ROOT_PASSWORD=spug.cc + spug: + image: openspug/spug-service + container_name: spug + privileged: true + restart: always + volumes: + - /data/spug/service:/data/spug + - /data/spug/repos:/data/repos + ports: + # 如果80端口被占用可替换为其他端口,例如: - "8000:80" + - "80:80" + environment: + - SPUG_DOCKER_VERSION=v3.2.4 + - MYSQL_DATABASE=spug + - MYSQL_USER=spug + - MYSQL_PASSWORD=spug.cc + - MYSQL_HOST=db + - MYSQL_PORT=3306 + depends_on: + - db diff --git a/docs/docker/entrypoint.sh b/docs/docker/entrypoint.sh index 0ce291f..f572e08 100755 --- a/docs/docker/entrypoint.sh +++ b/docs/docker/entrypoint.sh @@ -6,10 +6,16 @@ if [ -e /root/.bashrc ]; then source /root/.bashrc fi -if [ ! -d /data/spug ]; then - tar xf /tmp/spug.tar.gz -C /data/ +if [ ! -d /data/spug/spug_api ]; then + git clone -b $SPUG_DOCKER_VERSION https://gitee.com/openspug/spug.git /data/spug + curl -o web.tar.gz https://cdn.spug.cc/spug/web_${SPUG_DOCKER_VERSION}.tar.gz + tar xf web.tar.gz -C /data/spug/spug_web/ + rm -f web.tar.gz SECRET_KEY=$(< /dev/urandom tr -dc '!@#%^.a-zA-Z0-9' | head -c50) - cat > /data/spug/spug_api/spug//overrides.py << EOF + cat > /data/spug/spug_api/spug/overrides.py << EOF +import os + + DEBUG = False ALLOWED_HOSTS = ['127.0.0.1'] SECRET_KEY = '${SECRET_KEY}' @@ -18,12 +24,12 @@ DATABASES = { 'default': { 'ATOMIC_REQUESTS': True, 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'spug', - 'USER': 'spug', - 'PASSWORD': 'spug.dev', - 'HOST': 'localhost', + 'NAME': os.environ.get('MYSQL_DATABASE'), + 'USER': os.environ.get('MYSQL_USER'), + 'PASSWORD': os.environ.get('MYSQL_PASSWORD'), + 'HOST': os.environ.get('MYSQL_HOST'), + 'PORT': os.environ.get('MYSQL_PORT'), 'OPTIONS': { - 'unix_socket': '/var/lib/mysql/mysql.sock', 'charset': 'utf8mb4', 'sql_mode': 'STRICT_TRANS_TABLES', } @@ -32,22 +38,4 @@ DATABASES = { EOF fi -if [ ! -d /data/mysql ]; then - mkdir -p /data/mysql - mysql_install_db - chown -R mysql.mysql /data/mysql - - tfile=`mktemp` - cat >> $tfile << EOF -use mysql; -flush privileges; -create database spug character set utf8mb4 collate utf8mb4_unicode_ci; -grant all on spug.* to spug@'localhost' identified by 'spug.dev'; -flush privileges; -EOF - - /usr/libexec/mysqld --user=mysql --bootstrap < $tfile - rm -f $tfile -fi - exec supervisord -c /etc/supervisord.conf diff --git a/docs/docker/nginx.conf b/docs/docker/nginx.conf index e317759..348dc80 100644 --- a/docs/docker/nginx.conf +++ b/docs/docker/nginx.conf @@ -41,7 +41,7 @@ http { listen [::]:80 default_server; server_name _; root /data/spug/spug_web/build; - client_max_body_size 100m; + client_max_body_size 0; add_header X-Frame-Options SAMEORIGIN always; gzip on; diff --git a/docs/docker/spug.ini b/docs/docker/spug.ini index 30f0b75..e294f6a 100644 --- a/docs/docker/spug.ini +++ b/docs/docker/spug.ini @@ -9,10 +9,6 @@ autostart = true command = redis-server /etc/redis.conf autostart = true -[program:mariadb] -command = /usr/libexec/mysqld --user=mysql -autostart = true - [program:spug-api] command = sh /data/spug/spug_api/tools/start-api.sh autostart = true From 9ebf120326d2016d624e11048cc70a465f52b7b2 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 10 Aug 2022 16:40:51 +0800 Subject: [PATCH 02/19] Update docs/docker --- docs/docker/my.cnf | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 docs/docker/my.cnf diff --git a/docs/docker/my.cnf b/docs/docker/my.cnf deleted file mode 100644 index dd66596..0000000 --- a/docs/docker/my.cnf +++ /dev/null @@ -1,9 +0,0 @@ -[mysqld] -datadir=/data/mysql -log-error=/data/mysql/mysql.log -pid-file=/data/mysql/mysql.pid -socket=/var/lib/mysql/mysql.sock -symbolic-links=0 -max_connections=1000 - -!includedir /etc/my.cnf.d From c47a051aab3c23bc80771294853827cbec5c3c10 Mon Sep 17 00:00:00 2001 From: vapao Date: Tue, 23 Aug 2022 15:01:11 +0800 Subject: [PATCH 03/19] =?UTF-8?q?U=20=E5=BB=B6=E9=95=BF=E5=88=B7=E6=96=B0g?= =?UTF-8?q?it=E7=89=88=E6=9C=AC=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_web/src/pages/deploy/request/Ext1Form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spug_web/src/pages/deploy/request/Ext1Form.js b/spug_web/src/pages/deploy/request/Ext1Form.js index 5401e63..ca451c5 100644 --- a/spug_web/src/pages/deploy/request/Ext1Form.js +++ b/spug_web/src/pages/deploy/request/Ext1Form.js @@ -50,7 +50,7 @@ export default observer(function () { function fetchVersions() { setFetching(true); const deploy_id = store.record.deploy_id - const p1 = http.get(`/api/app/deploy/${deploy_id}/versions/`, {timeout: 120000}) + const p1 = http.get(`/api/app/deploy/${deploy_id}/versions/`, {timeout: 300000}) const p2 = http.get('/api/repository/', {params: {deploy_id}}) Promise.all([p1, p2]) .then(([res1, res2]) => { From f09dd6eb4e2213881c58af564f98affc26933f2d Mon Sep 17 00:00:00 2001 From: vapao Date: Thu, 8 Sep 2022 16:13:49 +0800 Subject: [PATCH 04/19] =?UTF-8?q?F=20=E4=BF=AE=E5=A4=8D=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=85=B3=E8=81=94=E8=B4=A6=E6=88=B7=E6=95=B0=E9=87=8F=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E6=98=BE=E7=A4=BA=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/account/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spug_api/apps/account/models.py b/spug_api/apps/account/models.py index 80cafff..b5bc60c 100644 --- a/spug_api/apps/account/models.py +++ b/spug_api/apps/account/models.py @@ -100,7 +100,7 @@ class Role(models.Model, ModelMixin): tmp['page_perms'] = json.loads(self.page_perms) if self.page_perms else {} tmp['deploy_perms'] = json.loads(self.deploy_perms) if self.deploy_perms else {} tmp['group_perms'] = json.loads(self.group_perms) if self.group_perms else [] - tmp['used'] = self.user_set.count() + tmp['used'] = self.user_set.filter(deleted_by_id__isnull=True).count() return tmp def add_deploy_perm(self, target, value): From a9b364638dedd5c695923d9abe3494d910100308 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 14 Sep 2022 15:26:33 +0800 Subject: [PATCH 05/19] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=AF=B9sh=E7=9A=84=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/libs/ssh.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spug_api/libs/ssh.py b/spug_api/libs/ssh.py index ac967b5..7f4d600 100644 --- a/spug_api/libs/ssh.py +++ b/spug_api/libs/ssh.py @@ -180,7 +180,8 @@ class SSH: counter = 0 self.channel = self.client.invoke_shell(**self.term) - command = 'set +o zle\n[ -n "$BASH_VERSION" ] && set +o history\n[ -n "$ZSH_VERSION" ] && set -o no_nomatch\n' + command = '[ -n "$BASH_VERSION" ] && set +o history\n' + command += '[ -n "$ZSH_VERSION" ] && set +o zle && set -o no_nomatch\n' command += 'export PS1= && stty -echo\n' command = self._handle_command(command, self.default_env) self.channel.sendall(command) @@ -221,7 +222,7 @@ class SSH: def _handle_command(self, command, environment): new_command = commands = '' if not self.exec_file: - self.exec_file = f'/tmp/{uuid4().hex}' + self.exec_file = f'/tmp/spug.{uuid4().hex}' commands += f'trap \'rm -f {self.exec_file}\' EXIT\n' env_command = self._make_env_command(environment) @@ -230,7 +231,7 @@ class SSH: new_command += command new_command += f'\necho {self.eof} $?\n' self.put_file_by_fl(StringIO(new_command), self.exec_file) - commands += f'source {self.exec_file}\n' + commands += f'. {self.exec_file}\n' return commands def _decode(self, content): From f013f157a24f607377ca3a7b02a5feaed6fd9ca8 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 14 Sep 2022 16:05:43 +0800 Subject: [PATCH 06/19] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E4=B8=BB=E6=9C=BA=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/host/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spug_api/apps/host/utils.py b/spug_api/apps/host/utils.py index cbd99bc..2dec266 100644 --- a/spug_api/apps/host/utils.py +++ b/spug_api/apps/host/utils.py @@ -122,7 +122,7 @@ def fetch_ali_instances(ak, ac, region_id, page_number=1): instance_charge_type=check_instance_charge_type(item['InstanceChargeType'], 'ali'), internet_charge_type=check_internet_charge_type(item['InternetChargeType'], 'ali'), public_ip_address=item['PublicIpAddress']['IpAddress'], - private_ip_address=list(map(lambda x: x['PrimaryIpAddress'], network_interface)), + private_ip_address=[x['PrimaryIpAddress'] for x in network_interface if x.get('PrimaryIpAddress')], zone_id=item['ZoneId'] ) if len(res['Instances']['Instance']) == page_size: From 5ad4a34a655e80b5d9109c258e97318a8b04a7c4 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 28 Sep 2022 15:52:30 +0800 Subject: [PATCH 07/19] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=96=B9=E5=BC=8F=20#544?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_web/src/pages/login/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spug_web/src/pages/login/index.js b/spug_web/src/pages/login/index.js index f223aa1..eb3b020 100644 --- a/spug_web/src/pages/login/index.js +++ b/spug_web/src/pages/login/index.js @@ -20,7 +20,7 @@ export default function () { const [form] = Form.useForm(); const [counter, setCounter] = useState(0); const [loading, setLoading] = useState(false); - const [loginType, setLoginType] = useState('default'); + const [loginType, setLoginType] = useState(localStorage.getItem('login_type') || 'default'); const [codeVisible, setCodeVisible] = useState(false); const [codeLoading, setCodeLoading] = useState(false); @@ -76,6 +76,7 @@ export default function () { localStorage.setItem('nickname', data['nickname']); localStorage.setItem('is_supper', data['is_supper']); localStorage.setItem('permissions', JSON.stringify(data['permissions'])); + localStorage.setItem('login_type', loginType); updatePermissions(); if (history.location.state && history.location.state['from']) { history.push(history.location.state['from']) @@ -100,7 +101,7 @@ export default function () {
灵活、强大、易用的开源运维平台
- setLoginType(v)}> + setLoginType(v)}> From 35506a569070ec18bb96b32257cac4c3c0568581 Mon Sep 17 00:00:00 2001 From: vapao Date: Sat, 8 Oct 2022 15:04:27 +0800 Subject: [PATCH 08/19] =?UTF-8?q?U=20=E5=A2=9E=E5=8A=A0=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E6=A0=87=E9=A2=98=E5=AD=97=E6=AE=B5=E9=95=BF?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/deploy/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spug_api/apps/deploy/models.py b/spug_api/apps/deploy/models.py index 3920664..15ac935 100644 --- a/spug_api/apps/deploy/models.py +++ b/spug_api/apps/deploy/models.py @@ -27,7 +27,7 @@ class DeployRequest(models.Model, ModelMixin): ) deploy = models.ForeignKey(Deploy, on_delete=models.CASCADE) repository = models.ForeignKey(Repository, null=True, on_delete=models.SET_NULL) - name = models.CharField(max_length=50) + name = models.CharField(max_length=100) type = models.CharField(max_length=2, choices=TYPES, default='1') extra = models.TextField() host_ids = models.TextField() From dc7340e24aa397435836eb6ae93e7acaabaf9072 Mon Sep 17 00:00:00 2001 From: vapao Date: Fri, 21 Oct 2022 16:47:41 +0800 Subject: [PATCH 09/19] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E5=8F=91=E5=9C=A8=E6=96=87=E4=BB=B6=E8=BF=87=E5=A4=9A?= =?UTF-8?q?=E6=97=B6=E5=B1=95=E7=A4=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_web/src/pages/exec/task/index.module.less | 1 + spug_web/src/pages/exec/transfer/Output.js | 3 ++- spug_web/src/pages/exec/transfer/index.js | 11 +++++++---- spug_web/src/pages/exec/transfer/index.module.less | 6 ++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/spug_web/src/pages/exec/task/index.module.less b/spug_web/src/pages/exec/task/index.module.less index e6add70..2a229b5 100644 --- a/spug_web/src/pages/exec/task/index.module.less +++ b/spug_web/src/pages/exec/task/index.module.less @@ -8,6 +8,7 @@ .left { padding: 24px; width: 60%; + border-right: 1px solid #dfdfdf; .area { cursor: pointer; diff --git a/spug_web/src/pages/exec/transfer/Output.js b/spug_web/src/pages/exec/transfer/Output.js index e4262bb..ffc8f69 100644 --- a/spug_web/src/pages/exec/transfer/Output.js +++ b/spug_web/src/pages/exec/transfer/Output.js @@ -32,7 +32,8 @@ function OutView(props) { store.tag = '' gCurrent = current term.setOption('disableStdin', true) - term.setOption('fontSize', gStore.terminal.fontSize) + term.setOption('fontSize', 14) + term.setOption('lineHeight', 1.2) term.setOption('fontFamily', gStore.terminal.fontFamily) term.setOption('theme', {background: '#2b2b2b', foreground: '#A9B7C6', cursor: '#2b2b2b'}) term.attachCustomKeyEventHandler((arg) => { diff --git a/spug_web/src/pages/exec/transfer/index.js b/spug_web/src/pages/exec/transfer/index.js index 853a167..b564b64 100644 --- a/spug_web/src/pages/exec/transfer/index.js +++ b/spug_web/src/pages/exec/transfer/index.js @@ -121,11 +121,13 @@ function TransferIndex() {