sun-pc 5 月之前
父節點
當前提交
5e75f2204a
共有 3 個文件被更改,包括 30 次插入23 次删除
  1. 0 0
      .env
  2. 21 20
      build.sh
  3. 9 3
      main.py

+ 0 - 0
.env.example → .env


+ 21 - 20
build.sh

@@ -1,22 +1,23 @@
 #!/bin/bash
 #!/bin/bash
 
 
-# 命名镜像
-local_imge="eps2svg:v1.0.0"
-repository_image="registry.cn-chengdu.aliyuncs.com/infish/$local_imge"
-
-# 删除本地已存在的镜像
-docker rmi $repository_image
-
-# 创建本地镜像
-docker build -t $local_imge .
-
-# 镜像标签
-docker tag $local_imge $repository_image
-
-# push到镜像仓库,需要登陆对应docker仓库账号
-docker push $repository_image
-
-
-# 运行示例
-# docker run  -itd -p 20001:20001 --name comm-pay-service pay-service:1.0.0
-
+# Image configuration
+VERSION="1.0.0"
+LOCAL_IMAGE="eps2svg:v${VERSION}"
+REGISTRY="registry.cn-chengdu.aliyuncs.com/infish"
+REGISTRY_IMAGE="${REGISTRY}/${LOCAL_IMAGE}"
+
+# Build local image
+echo "Building local image: ${LOCAL_IMAGE}"
+docker build -t ${LOCAL_IMAGE} .
+
+# Tag for registry
+echo "Tagging image for registry: ${REGISTRY_IMAGE}"
+docker tag ${LOCAL_IMAGE} ${REGISTRY_IMAGE}
+
+# Push to registry (uncomment to push)
+# echo "Pushing to registry..."
+# docker push ${REGISTRY_IMAGE}
+
+# Run locally
+echo "Running container locally..."
+docker run -p 8087:8000 --env-file .env ${LOCAL_IMAGE}

+ 9 - 3
main.py

@@ -1,5 +1,6 @@
 import os
 import os
 import subprocess
 import subprocess
+import shutil
 from typing import Optional
 from typing import Optional
 from fastapi import FastAPI, UploadFile, HTTPException
 from fastapi import FastAPI, UploadFile, HTTPException
 from fastapi.responses import JSONResponse, FileResponse
 from fastapi.responses import JSONResponse, FileResponse
@@ -67,8 +68,13 @@ async def convert_eps_to_svg(file: UploadFile):
         # Convert EPS to SVG
         # Convert EPS to SVG
         subprocess.run(['eps2svg', input_path, temp_svg], check=True)
         subprocess.run(['eps2svg', input_path, temp_svg], check=True)
         
         
-        # Optimize SVG using scour
-        subprocess.run(['scour', '-i', temp_svg, '-o', final_svg], check=True)
+        # Try to optimize SVG using scour
+        try:
+            subprocess.run(['scour', '-i', temp_svg, '-o', final_svg], check=True)
+        except subprocess.CalledProcessError:
+            # If scour fails, use the unoptimized SVG
+            shutil.copy(temp_svg, final_svg)
+            print("Scour optimization failed, using unoptimized SVG")
         
         
         # Upload to OBS
         # Upload to OBS
         obs_client = get_obs_client()
         obs_client = get_obs_client()
@@ -95,4 +101,4 @@ async def convert_eps_to_svg(file: UploadFile):
 
 
 @app.get("/health")
 @app.get("/health")
 def health_check():
 def health_check():
-    return {"status": "healthy"}
+    return {"status": "healthy"}