简体   繁体   中英

Cloud Build w/ cloudbuild.yaml in nested folder - build fails

I am experimnting in automating parts of a project that I'd ideally deploy and forget about. The project is comprised of an XML parser and a small Flask website. At the moment the folder structure looks like this:

.
├── init.sql
└── parser
    ├── cloudbuild.yaml
    ├── cloud_func
    │   └── main.py
    ├── Dockerfile
    ├── feed_parse.py
    ├── get_so.py
    ├── requirements.txt
    └── utils.py

Now, I can correctly set up the trigger to look at /parser/cloudbuild.yaml , but building the image with the following command raises an error:

build . --build-arg "CLIENT_CERT=$CSQL_CERT CLIENT_KEY=$CSQL_KEY SERVER_CA=$CSQL_CA SERVER_PW=$CSQL_PW SERVER_HOST=$CSQL_IP" -t gcr.io/and-reporting/appengine/so-parser:latest
BUILD
Already have image (with digest): gcr.io/cloud-builders/docker
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1

it looks to me that gcp has troubles locating my Dockerfile which is in the same folder cloudbuild.yaml is located.
What am I missing?

For the sake of completeness, the Dockerfile looks like this:

FROM python:3.7-alpine

RUN apk update \
  && apk add gcc python3-dev musl-dev libffi-dev \
  && apk del libressl-dev \
  && apk add openssl-dev

COPY requirements.txt /
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

ADD . /parser
WORKDIR /parser/
RUN mkdir -p certs

# Set env variables from secrets 
ARG CLIENT_CERT
ENV CSQL_CERT=${CLIENT_CERT}

ARG CLIENT_KEY
ENV CSQL_KEY=${CLIENT_KEY}

ARG SERVER_CA
ENV CSQL_CA=${SERVER_CA}

ARG SERVER_PW
ENV CSQL_PW=${SERVER_PW}

ARG SERVER_HOST
ENV CSQL_IP=${SERVER_HOST}

# Get ssl certs in files
RUN echo $CLIENT_CERT > ./certs/ssl_cert.pem \
  && echo $CLIENT_KEY > ./certs/ssl_key.pem \
  && echo $SERVER_CA > ./certs/ssl_ca.pem

CMD python get_so.py

edit : and the cloudbuild.yaml I'm using for the build

steps:

# Building image
- name: 'gcr.io/cloud-builders/docker'
  args: [
     'build',
     '-f',
     'Dockerfile',
     '--build-arg',
     'CLIENT_CERT=$$CSQL_CERT CLIENT_KEY=$$CSQL_KEY SERVER_CA=$$CSQL_CA SERVER_PW=$$CSQL_PW SERVER_HOST=$$CSQL_IP',
     '-t',
     'gcr.io/$PROJECT_ID/appengine/so-parser:latest',
     '.'
  ]
  secretEnv: ['CSQL_CERT', 'CSQL_KEY', 'CSQL_CA', 'CSQL_PW', 'CSQL_IP']     

# Push Images       
# - name: 'gcr.io/cloud-builders/docker'
#   args: ['push', 'gcr.io/$PROJECT_ID/appengine/so-parser:latest']

secrets:
- kmsKeyName: projects/myproject/locations/global/keyRings/so-jobs/cryptoKeys/board
  secretEnv:
   CSQL_CERT: [base64 string] 
   CSQL_KEY: [base64 string] 
   CSQL_CA: [base64 string] 
   CSQL_PW: [base64 string] 
   CSQL_IP: [base64 string] 

Because of the dot in your cloudbuild.yaml file, docker is not able to find Dockerfile which is in parser directory:

steps:

- name: "gcr.io/cloud-builders/docker"

  args: ["build", "-t", "gcr.io/$PROJECT_ID/mynodejs:$SHORT_SHA", "./parser"]

If you want to mention the dockerfile name: steps:

- name: "gcr.io/cloud-builders/docker"

  args: ["build", "-t", "gcr.io/$PROJECT_ID/mynodejs:$SHORT_SHA", "-f", "./parser/your-dockerfile"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM