簡體   English   中英

Cloud Run - BUILD_DOCKER_UNKNOWN // 無法導入 python

[英]Cloud Run - BUILD_DOCKER_UNKNOWN // cant import python

我正在嘗試使用燒瓶服務將非網絡 python 腳本放在 Cloud Run 上,而我在 Cloud Run 以及 Docker 和 Dockerfiles 上是全新的。 我需要為此腳本導入電報和 yfinance。 在 Cloud Run 編輯器中,pylint 已經表示無法導入 yfinance 和電報,但我通過 Cloud Run 終端中的 pip install 安裝了兩者。 main.py 在我的電腦上本地工作,但不知道這里發生了什么......

我給你看我的主文件(main.py):

import yfinance as yf
import time
from telegram import Bot
from flask import Flask, request
import os

app = Flask(__name__)

@app.route('/')

def my_stockscout():

    bot = Bot('thecorrecttoken')   
    
    def fetch_yfinance_data(ticker): 
        
     
        try: 
        
            #print ("Fetching", ticker)
            data = yf.Ticker(ticker)
     
            # download historic data 
            df = data.history(period="max", intervall="1d") 
     
            # fill NaN with previous values 
            df.fillna(method='ffill', inplace= True)
            
            
            #put Date to Column instead of index
            df.reset_index(level=0, inplace=True)
     
            # save df to csv file 
            df.to_csv(f'./data/{ticker}.csv', sep=';', index=True, header=True)
            #print(f'Fetching {ticker} data complete.') 
            time.sleep(1) 
     
        
                
           
        
        # Ermittle MAX aus den gezogegenen Kursdaten und letzten Schlusswert
        
            allTimeMax = round(df['Close'].max(),2)
            #allTimeMaxRaw = df['Close'].max()
            #allTimeMaxDate = str(df['Date'].max(),2)
            maxRow = df['Close'].argmax()
            lastCloseValue = round(df['Close'].iloc[-1],2)
            allTimeMaxDate = df.iloc[maxRow].values[0]
            
        
        
        # Alarm einstellen
        # Wenn letzter Kurseintrag (heute) kleiner 20% - 40% von MAX-bisher, dann Alarm
        
        
            if  allTimeMax-(allTimeMax/100)*40 <= lastCloseValue <= allTimeMax-(allTimeMax/100)*20:
                stockinfo = "Der Kurswert - "+str(lastCloseValue)+" -  betraegt "+str(round(lastCloseValue/(allTimeMax/100),2))+" Prozent des AllTimeMax-Wertes "+str(allTimeMax)
                bot.send_message(chat_id=155358511, text="<a href='https://finance.yahoo.com/quote/"+str(ticker)+"?p="+str(ticker)+"&.tsrc=fin-srch'>"+str(ticker)+"</a>: Regime Knappheit: "+stockinfo)
                pync.notify(stockinfo, title=str(ticker)+": Regime Knappheit!")
                
        
            elif lastCloseValue < allTimeMax-(allTimeMax/100)*40:
                stockinfo = "Der Kurswert - "+str(lastCloseValue)+" - betraegt "+str(round(lastCloseValue/(allTimeMax/100),2))+" Prozent des AllTimeMax-Wertes "+str(allTimeMax)
                bot.send_message(chat_id=155358511, text="<a href='https://finance.yahoo.com/quote/"+str(ticker)+"?p="+str(ticker)+"&.tsrc=fin-srch'>"+str(ticker)+"</a>: Regime Eskalation: "+stockinfo)
                pync.notify(stockinfo, title=str(ticker)+": !Regime Eskalation!")
                
                
            else: 
                stockinfo = "Der Kurswert - "+str(lastCloseValue)+" - betraegt "+str(round(lastCloseValue/(allTimeMax/100),2))+" Prozent des AllTimeMax-Wertes "+str(allTimeMax)+" vom "+str(allTimeMaxDate)[:10]            
                #telegram_send.send(messages=["<a href='https://finance.yahoo.com/quote/"+str(ticker)+"?p="+str(ticker)+"&.tsrc=fin-srch'>"+str(ticker)+"</a>: Normales Regime: "+text])
                pync.notify(stockinfo, title=str(ticker)+": Normales Regime")
                #bot.send_message(chat_id=155358511, text="<a href='https://finance.yahoo.com/quote/"+str(ticker)+"?p="+str(ticker)+"&.tsrc=fin-srch'>"+str(ticker)+"</a>: Normales Regime: "+stockinfo)
                
        
        except Exception as e: 
            print("Error fetching", ticker, "data: ", e)
            
    fetch_yfinance_data("IUSQ.DE")
    fetch_yfinance_data("IESZ.SW")      
    
    return 'ok',200
#my_stockscout()
if __name__ == "__main__":
  app.run(host='0.0.0.0',port=int(os.environ.get('PORT',8080)))

這是 Dockerfile:

# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.9-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN pip install Flask gunicorn yfinance time telegram

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

如果我在 Cloud Run 模擬器中運行它,我會得到這個 output:

Starting to run the app using configuration 'Cloud Run: Run/Debug Locally' from .vscode/launch.json...
To view more detailed logs, go to Output channel : "Cloud Run: Run/Debug Locally - Detailed"
Dependency check started
Dependency check succeeded
Unpausing minikube
The minikube profile 'cloud-run-dev-internal' has been scheduled to stop automatically after exiting Cloud Code. To disable this on future deployments, set autoStop to false in your launch configuration /home/oaorama/.vscode/launch.json
Update initiated
Build started for artifact oaorama
Build failed for artifact oaorama
Update failed with error code BUILD_DOCKER_UNKNOWN
build [oaorama] failed: exit status 1. Docker build ran into internal error. Please retry.
If this keeps happening, please open an issue..
Skaffold exited with code 1.

我嘗試使用不同的 Python 版本,但仍然是相同的錯誤 output。

也許你們有一個線索? 我完全迷失在這里......

我懷疑問題可能出在launch.json 文件上。 或者,您可以放入 docker 文件並查看出錯的位置。 如果您沒有看到任何輸出,它可能在其他地方。

RUN echo "this does stuff"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM