working traefik

This commit is contained in:
Oliver
2025-08-30 09:53:31 +02:00
parent 9726dc0060
commit 86acea94b9
29 changed files with 378 additions and 81 deletions

View File

@@ -15,7 +15,7 @@ from datetime import datetime
DB_PATH = "/4server/data/contracts.db"
BIN_PATH = "/4server/sbin"
API_KEY = os.getenv("API_KEY", "your-secret-api-key")
VERSION = "API: 0.0.6"
VERSION = "API: 0.0.7"
# FastAPI app
app = FastAPI()
@@ -65,19 +65,25 @@ def init_db():
def execute_db(query: str, params: tuple = (), fetch: bool = False):
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row # <-- Add this line
cursor = conn.cursor()
cursor.execute(query, params)
conn.commit()
data = cursor.fetchall() if fetch else None
conn.close()
if data and fetch:
return [dict(row) for row in data] # Convert each row to dict
return data
# ---------------------- Models ----------------------
class ContainerModel(BaseModel):
UUID: Optional[str] = None
email: str
expires: str
email: Optional[str] = None
expires: Optional[str] = None
tags: Optional[str] = None
env: Optional[str] = None
affiliate: Optional[str] = None
@@ -85,13 +91,13 @@ class ContainerModel(BaseModel):
history: Optional[str] = None
comment: Optional[str] = None
domains: Optional[str] = None
status: str
created: str
status: Optional[str] = None
created: Optional[str] = None
bump: Optional[str] = None
class ContainerIDRequest(BaseModel):
container_id: str
container_id: Optional[str] = None
class UpdateContainerRequest(ContainerModel):

BIN
app/sbin/nebula-cert Executable file

Binary file not shown.

183
app/sbin/start/ODOO_18 Executable file
View File

@@ -0,0 +1,183 @@
#/bin/bash
echo "Start container ODOO_18: $UUID""
export PATH=/4SERVER/sbin:$PATH
SERVER_IP=$( ip -4 addr show eth0 | awk '/inet/ {print $2}' | cut -d/ -f1 )
echo "SERVER_IP $SERVER_IP"
if [ -z "$1" ]; then
exit 0
else
BASEURL="/4SERVER/data/$1/"
fi
DOMAIN="$UUID.odoo4projects.com $DOMAIN"
CLIENT_DOMAIN=$(cat ${BASEURL}etc/domain)
echo "CLIENT_DOMAIN: $CLIENT_DOMAIN"
echo ""
if [[ -n "$CLIENT_DOMAIN" ]]; then
DOMAIN+=" www.$CLIENT_DOMAIN $CLIENT_DOMAIN"
fi
echo "Domains: $DOMAIN"
NEW=0
if [ ! -d "$BASEURL" ]; then
echo "NEW CLIENT !!!"
echo "Wait for DNS to update"
WAIT=true
START_TIME=$(date +%s)
while $WAIT; do
nslookup "$1.odoo4projects.com" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Domain $DOMAIN resolved successfully."
WAIT=false
fi
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ $ELAPSED_TIME -ge 120 ]; then
echo "Timeout reached. Domain $DOMAIN could not be resolved."
WAIT=false
fi
sleep 5
done
NEW=1
fi
echo "Get valid DNS entries:"
filtered_domains=""
for domain in $DOMAIN; do
nslookup_output=$(nslookup "$domain" 2>/dev/null)
status=$?
echo "DOMAIN: $domain $status"
if [[ $status -eq 0 ]]; then
#ns_ip=$(echo "$nslookup_output" | grep 'Address:' | tail -n1 | awk '{print $2}')
ns_ip=$(echo "$nslookup_output" | grep -Eo 'Address: ([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $2}' | tail -n1)
echo "NS IP $ns_ip"
if [[ "$ns_ip" == "$SERVER_IP" ]]; then
filtered_domains+=" $domain"
echo "Domain added $filtered_domains"
fi
else
echo "Failed to nslookup $domain -- $ns_ip"
fi
done
filtered_domains=$(echo "$filtered_domains" | xargs)
echo "Filtered domains: $filtered_domains"
DOMAIN_LABEL=""
for domain in $filtered_domains; do
if [ -z "$DOMAIN_LABEL" ]; then
DOMAIN_LABEL="traefik.http.routers.$1.rule=Host(\`$domain\`)"
else
DOMAIN_LABEL+=" || Host(\`$domain\`)"
fi
done
echo $DOMAIN_LABEL
echo "end domains"
exit 0
echo "BASEURL: $BASEURL"
PORT=$((CONTRACT_ID + 2200))
echo "CREATING PORT $PORT"
UUID="${1:-default}"
DATA_DIR="${BASEURL}odoo/"
CUSTOM_DIR="${BASEURL}git/$UUID/custom/"
ENTERPRISE_DIR="${BASEURL}git/$UUID/enterprise/"
LOGS_DIR="${BASEURL}logs/"
CONFIG_DIR="${BASEURL}config/"
CC_DIR="${BASEURL}cc/"
BACKUP_DIR="/BACKUP/$1"
GIT_DIR="${BASEURL}git-server/"
ETC_DIR="${BASEURL}etc/"
INSTALL_DIR="${BASEURL}install/"
SSH_DIR="${BASEURL}.ssh/"
HUGO_DIR="${BASEURL}git-server/local/hugo"
log restoreODOO "DOMAIN_LABEL $DOMAIN_LABEL"
log restoreODOO "CREATING CONTAINER $UUID"
echo "Stopping and Deleting Contianer"
d stop $UUID
d container rm $UUID
echo "Done Stopping & Deleting containers Errors above are OK"
EXTRA_DOCKER_PARAMETER=""
if [ -d "$HUGO_DIR" ]; then
EXTRA_DOCKER_PARAMETER="-v $HUGO_DIR:/mnt/hugo"
fi
echo "******************"
echo $EXTRA_DOCKER_PARAMETER
echo $HUGO_DIR
echo ***********************""
# start container - check done in checkContractsBee
sudo docker run -d --name "$UUID" \
--network docker-compose_4projects \
--restart=always \
$EXTRA_DOCKER_PARAMETER \
-v "$DATA_DIR/odoo-web-data:/var/lib/odoo" \
-v "$CUSTOM_DIR:/mnt/addons/custom" \
-v "$ENTERPRISE_DIR:/mnt/addons/enterprise" \
-v "$LOGS_DIR:/mnt/logs" \
-v "$CC_DIR:/mnt/cc" \
-v "$BACKUP_DIR:/mnt/backup" \
-v "$CONFIG_DIR:/etc/odoo" \
-v "$GIT_DIR:/git-server" \
-v "$ETC_DIR:/mnt/etc" \
-v "$INSTALL_DIR:/mnt/install" \
-v "$SSH_DIR:/etc/sshkey" \
-p "$PORT:22" \
-e HOST=beedb \
-e USER=$UUID \
-e PASSWORD=$UUID \
-e STAGING=$STAGING \
--label "$DOMAIN_LABEL" \
--label "traefik.http.services.$1.loadbalancer.server.port=8069" \
--label "traefic.http.routers.$1.entrypoints=web, websecure" \
--label "traefik.http.routers.$1.tls.certresolver=production" \
--label "traefik.http.routers.$1.tls=true" \
--label "traefik.http.routers.$1.service=$1" \
--label "traefik.http.routers.$1_S.entrypoints=web,websecure" \
--label "traefik.http.routers.$1_S.rule=Host(\`s.$1.odoo4projects.com\`)" \
--label "traefik.http.routers.$1_S.tls.certresolver=production" \
--label "traefik.http.routers.$1_S.tls=true" \
--label "traefik.http.services.$1_S.loadbalancer.server.port=8070" \
--label "traefik.http.routers.$1_S.service=$1_S" \
docker.odoo4projects.com/4projects/odoo_18:$BRANCH
sudo chmod 777 $DATA_DIR/odoo-web-data
sudo mkdir $ETC_DIR
sudo chmod 777 $ETC_DIR
sudo chmod 777 $INSTALL_DIR
sudo cp /4PROJECTS/config/odoo_18/odoo.conf $CONFIG_DIR
sudo cp /4PROJECTS/config/odoo_18/staging.conf $CONFIG_DIR
echo "git clone ssh://git@$1.odoo4projects.com:$PORT/git-server/repos/odoo.git" > $ETC_DIR/gitpath
echo "$1" > $ETC_DIR/uuid
d exec -it $1 chown -R odoo /mnt
d exec -it $1 chgrp -R odoo /mnt/
d exec -it $1 chown -R git /git-server
d exec -it $1 chgrp -R git /git-server
d exec -it $1 chmod -R g+rw /git-server
if [ "$NEW" -eq 1 ]; then
restoreODOO $1 default.zip
echo "here"
restoreODOO ${1}_ default.zip
echo "there"
fi

View File

@@ -34,7 +34,6 @@ done < <(sqlite3 "$DB_PATH" "
")
# Debug: print loaded environment variables
env | grep -E 'UUID|EMAIL|EXPIRES|TAGS|ENV|AFFILIATE|IMAGE|HISTORY|COMMENT|DOMAINS|STATUS|CREATED|BUMP'
@@ -50,10 +49,10 @@ case "$SECOND_PART" in
"$BIN_PATH/start/n8n"
;;
002)
"$BIN_PATH/start/ODOO18"
"$BIN_PATH/start/ODOO_18"
;;
003)
"$BIN_PATH/start/ODOO19"
"$BIN_PATH/start/ODOO_19"
;;
*)
echo "Unknown UUID type: $SECOND_PART"