diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ca25156..b510b49 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -40,16 +40,23 @@ jobs: - name: Register Traefik route run: | - ROUTE_B64="aHR0cDoKICByb3V0ZXJzOgogICAgdWJpZ2VvLWFwaToKICAgICAgcnVsZTogIkhvc3QoYGFwaS11YmlnZW8uZGFya2NvZGV4LmRldmApIgogICAgICBzZXJ2aWNlOiB1YmlnZW8tYXBpCiAgICAgIGVudHJ5UG9pbnRzOgogICAgICAgIC0gd2Vic2VjdXJlCiAgICAgIHRsczoKICAgICAgICBjZXJ0UmVzb2x2ZXI6IGxldHNlbmNyeXB0CiAgc2VydmljZXM6CiAgICB1YmlnZW8tYXBpOgogICAgICBsb2FkQmFsYW5jZXI6CiAgICAgICAgc2VydmVyczoKICAgICAgICAgIC0gdXJsOiAiaHR0cDovL3ViaWdlby1hcGk6MzIwMCIK" docker run --rm \ - -e ROUTE_B64="$ROUTE_B64" \ -v /etc/easypanel/traefik/config:/traefik-config \ - alpine sh -c 'echo "$ROUTE_B64" | base64 -d > /traefik-config/api-ubigeo.yaml && echo "written:" && cat /traefik-config/api-ubigeo.yaml' + alpine sh -c ' + apk add jq -q --no-progress 2>/dev/null + FILE=/traefik-config/main.yaml - - name: Diagnostics - run: | - echo "=== main.yaml content ===" - docker run --rm -v /etc/easypanel/traefik/config:/traefik-config alpine cat /traefik-config/main.yaml || echo "FAILED" + if jq -e ".http.routers[\"https-ubigeo-0\"]" "$FILE" > /dev/null 2>&1; then + echo "ubigeo route already exists in main.yaml" + exit 0 + fi + + jq ".http.routers[\"http-ubigeo-0\"] = {\"rule\": \"Host(\\\"api-ubigeo.darkcodex.dev\\\") && PathPrefix(\\\"/\\\")\", \"entryPoints\": [\"http\"], \"middlewares\": [\"redirect-to-https\", \"bad-gateway-error-page\"], \"service\": \"ubigeo_api-0\"} | + .http.routers[\"https-ubigeo-0\"] = {\"rule\": \"Host(\\\"api-ubigeo.darkcodex.dev\\\") && PathPrefix(\\\"/\\\")\", \"entryPoints\": [\"https\"], \"middlewares\": [\"bad-gateway-error-page\"], \"service\": \"ubigeo_api-0\", \"tls\": {\"certResolver\": \"letsencrypt\"}} | + .http.services[\"ubigeo_api-0\"] = {\"loadBalancer\": {\"passHostHeader\": true, \"servers\": [{\"url\": \"http://ubigeo-api:3200/\"}]}}" \ + "$FILE" > /tmp/main-new.json && mv /tmp/main-new.json "$FILE" + echo "Traefik route injected into main.yaml" + ' - name: Health check run: |