We’re using GCP Cloud Build to build and push container images upon any merge activities to main branch in GitHub. In the 2nd step of CloudBuild, we run into the issue COPY failed: file not found in build context or excluded by .dockerignore: stat requirements.txt: file does not exist
.
I ran docker build .
under the root directory where both Dockerfile
and requirements.txt
are located.
The directory looks like this:
- Dockerfile
- requirements.txt
- deploy
- cloudbuild.yaml
- deployment.yaml
Dockerfile:
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.10.12-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
ENV PYTHONPATH /app
# Install production dependencies.
COPY requirements.txt ./requirements.txt
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
CMD ["python3", "telegram_bot.py"]
This is the cloudbuild.yaml:
steps:
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
git clone https://[email protected]/CohumanSpace/cohuman.git
cd cohuman
git checkout .
secretEnv: ['GH_TOKEN']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', "--no-cache", '-t', 'gcr.io/cohuman-432919/telegram-bot:$SHORT_SHA', '-f', '../Dockerfile', '.']
dir: 'deploy'
logsBucket: gs://gke-deployment/
images:
- 'gcr.io/cohuman-432919/telegram-bot:$SHORT_SHA'
availableSecrets:
secretManager:
- versionName: projects/cohuman-432919/secrets/GH_TOKEN/versions/latest
env: 'GH_TOKEN'
I tried:
- RUN cwd: it prints out “/app” in Cloud Build logs.
- RUN ls: nothing.
- I looked thru almost all online posts and forums I can find and most mention that the copied files shouldn’t be in .dockerignore and the copied files should under the same directory as Dockerfile. My setup is correct to these 2 points.
Jerry Pan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.