From 0b891bede630fc51f46c3e5ab59186091551778e Mon Sep 17 00:00:00 2001 From: qiaofeng1227 <76487013@qq.com> Date: Wed, 11 Oct 2023 17:19:38 +0800 Subject: [PATCH] apphub 0.0.5 --- docker/apphub/Dockerfile | 4 ++-- systemd/script/crontab.sh | 35 +++++++++++++++++++++++++----- systemd/script/send_credentials.sh | 28 +++++++++++++++++++----- systemd/script/start_up.sh | 2 +- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/docker/apphub/Dockerfile b/docker/apphub/Dockerfile index 1e1156ba..84a53dd2 100644 --- a/docker/apphub/Dockerfile +++ b/docker/apphub/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.10-bullseye AS buildstage LABEL maintainer="Websoft9" -LABEL version="0.0.4" +LABEL version="0.0.5" ENV LIBRARY_VERSION=v0.5.8 @@ -23,7 +23,7 @@ WORKDIR /websoft9 COPY --from=buildstage /media/data ./media COPY --from=buildstage /library ./library -COPY --from=buildstage /websoft9/appmanage_new ./apphub +COPY --from=buildstage /websoft9/apphub ./apphub COPY --from=buildstage /swagger-ui/dist ./apphub/swagger-ui RUN apt update && apt install git jq iproute2 supervisor -y && \ diff --git a/systemd/script/crontab.sh b/systemd/script/crontab.sh index 9ed9d6c2..1834309e 100644 --- a/systemd/script/crontab.sh +++ b/systemd/script/crontab.sh @@ -1,9 +1,34 @@ #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin -# monitor /lib/systemd/system/cockpit.socket and config.ini, make sure config.ini port is the same with cockpit.socket -while true; do - inotifywait -e modify /lib/systemd/system/cockpit.socket - # 当文件修改时,执行你需要的操作 -done +# 监控的文件 +FILES="/lib/systemd/system/cockpit.socket /var/lib/docker" +cockpit_port="9000" +# 监控文件发生变动时需要做的事情 +on_change() { + set +e + # TODO 从配置文件中获取端口号 apphub need add getconfig cli + cockpit_port =$(docker exec -it websoft9-apphub apphub getconfig cockpit port) + sudo sed -i "s/ListenStream=[0-9]*/ListenStream=${cockpit_port}/" /lib/systemd/system/cockpit.socket + sudo systemctl daemon-reload + sudo systemctl restart cockpit + set_Firewalld + set -e +} + +set_Firewalld(){ + echo "Set cockpit service to Firewalld..." + sudo sed -i "s/port=\"[0-9]*\"/port=\"$cockpit_port\"/g" /etc/firewalld/services/cockpit.xml + sudo sed -i "s/port=\"[0-9]*\"/port=\"$cockpit_port\"/g" /usr/lib/firewalld/services/cockpit.xml + sudo firewall-cmd --reload +} + +# 循环,持续监控 +while true; do + # monitor /lib/systemd/system/cockpit.socket and config.ini, make sure config.ini port is the same with cockpit.socket + inotifywait -e modify -m $FILES | while read PATH EVENT FILE; do + echo "Set cockpit port by config.ini..." + on_change + done +done diff --git a/systemd/script/send_credentials.sh b/systemd/script/send_credentials.sh index c85182b0..c5a41bc4 100644 --- a/systemd/script/send_credentials.sh +++ b/systemd/script/send_credentials.sh @@ -3,15 +3,33 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin set -e trap "sleep 1; continue" ERR -try_times=100 +try_times=20 counter=1 - -portainer_username="admin" +deployment_username="admin" credential_path="/var/websoft9/credential" -apphub_container_name="websoft9-apphub" +containers=("websoft9-git" "websoft9-deployment" "websoft9-proxy") -copy_credential() { +for container in ${containers[@]}; do + temp_file=$(mktemp) + echo "Copying /var/websoft9/credential from $container to $temp_file" + docker cp $container:$credential_path $temp_file + # Check if temp_file is JSON format + if jq -e . >/dev/null 2>&1 <<< "$(cat "$temp_file")"; then + # If it is JSON format, use it directly + username=$(jq -r '.username' $temp_file) + password=$(jq -r '.password' $temp_file) + else + # If it is not JSON format, get the content and convert it to JSON + content=$(cat "$temp_file") + username="$deployment_username" + password="$content" + fi + + rm -f "$temp_file" +done + +get_credential() { # 设置参数的默认值 source_container= diff --git a/systemd/script/start_up.sh b/systemd/script/start_up.sh index 061d4d73..345e00ba 100644 --- a/systemd/script/start_up.sh +++ b/systemd/script/start_up.sh @@ -2,4 +2,4 @@ /bin/bash send_credentials.sh /bin/bash set_hosts.sh -/bin/bash crontab.sh \ No newline at end of file +/bin/bash crontab.sh & \ No newline at end of file