Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将GitlabCI中的文件变量传递给Docker运行(FileNotFound)_Python_Docker_Google Cloud Platform_Gitlab_Gitlab Ci - Fatal编程技术网

Python 将GitlabCI中的文件变量传递给Docker运行(FileNotFound)

Python 将GitlabCI中的文件变量传递给Docker运行(FileNotFound),python,docker,google-cloud-platform,gitlab,gitlab-ci,Python,Docker,Google Cloud Platform,Gitlab,Gitlab Ci,我在GitlabCI中创建了一个受保护的文件变量,以便将名称设置为GOOGLE\u CREDENTIALS,该值是用作我的GOOGLE云服务帐户密钥的JSON文件的内容 根据文档,可以在任何命令中使用此文件变量,因此我使用以下命令: 这是my.gitlab ci.yml的内容: stages: - build_image image: docker:latest services: - docker:dind build_image: stage: build_image

我在GitlabCI中创建了一个受保护的文件变量,以便将名称设置为
GOOGLE\u CREDENTIALS
,该值是用作我的GOOGLE云服务帐户密钥的JSON文件的内容

根据文档,可以在任何命令中使用此文件变量,因此我使用以下命令:

这是my
.gitlab ci.yml
的内容:

stages:
  - build_image

image: docker:latest

services:
  - docker:dind

build_image:
  stage: build_image
  script:
    - docker build . -t johndoe/project_name
    - docker run --volume ${PWD}:/src --env=GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_CREDENTIALS johndoe/project_name
    
我的Dockerfile(以防万一):

这是使用密钥的代码部分:

    try:
        key_path = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
    except KeyError:
        key_path = "./bigquery_key/key.json"
    credentials = service_account.Credentials.from_service_account_file(
        key_path,
        scopes=["https://www.googleapis.com/auth/cloud-platform"],
    )

    client = bigquery.Client(
        credentials=credentials,
        project=credentials.project_id,
    )
我得到的错误如下:

FileNotFoundError:[Errno 2]没有这样的文件或目录:'/builds/johndoe/project\u name.tmp/GOOGLE\u CREDENTIALS'

使用
echo
cat
显示文件确实存在,并且内容与JSON文件和密钥完全匹配,但是由于某种原因,Docker容器不知道它存在

我错过了什么

    try:
        key_path = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
    except KeyError:
        key_path = "./bigquery_key/key.json"
    credentials = service_account.Credentials.from_service_account_file(
        key_path,
        scopes=["https://www.googleapis.com/auth/cloud-platform"],
    )

    client = bigquery.Client(
        credentials=credentials,
        project=credentials.project_id,
    )