0

I am trying to build an image using google cloud build for my GKE. Locally I can build images using this command:

docker build -t backend .
docker  tag backend  gcr.io/project-id/backend:v15.8
docker  push  gcr.io/project-id/backend:v15.8

And it works fine but when I am trying to use:

steps:
- name: "gcr.io/cloud-builders/docker"
  args: ["build", "-t", "gcr.io/project-id/backend:v15.8", "."]
  # push container image
- name: "gcr.io/cloud-builders/docker"
  args: ["push", "gcr.io/project-id/backend:v15.8"]

This code is building the image but I don't know why some of the files it misses. I have several files in .gitignore.

I can build an image but it is not the same as I am building an image from command locally. When I am deploying it to my GKE one file is missing which is in .gitignore file. What do I need to do in order to achieve my goal

Nilay Singh
  • 2,201
  • 6
  • 31
  • 61
  • What is the missing file? Perhaps a credential file? – John Hanley Aug 04 '20 at 05:03
  • I am using Django and I added my settings.py in my .gitignore When I am building an image using local commands it works great but. Using cloud build I am getting error settings.py not there. I am running cloud build inside my project directory – Nilay Singh Aug 04 '20 at 05:05
  • 3
    Use a `.gcloudignore` file. Ignore the `.gitignore` and specify the Cloud Build files to ignore. This answer might help you. https://stackoverflow.com/a/56963506/8016720 – John Hanley Aug 04 '20 at 05:18
  • I added the #!include:.gitignore to my .gcloudignore no change is there any way we can delete the cache. – Nilay Singh Aug 04 '20 at 10:12
  • From what I understood of what the issue is and what John shared above, plus what is mentioned on the answer shared, you should only use a `.gcloudignore` and specify in there the files you want to ignore instead of importing the `.gitignore` into the `.gcloudignore`. Did you try that? – Ralemos Aug 04 '20 at 13:44
  • I don't want to ignore anything my cloud build is ignoring when I am running the code. And in my .gitignore my settings.py is ignored and I want that file when I build the image. Is cloud build using git ignore to build my image if yes then how to add that file? – Nilay Singh Aug 04 '20 at 16:39
  • if you want to add a file that is being ignored by `.gitignore` you **should not** import the `.gitignore` into the `.gcloudignore`, instead of that you should specify manually all the files that are in the `.gitignore` and that you also want in `.gcloudignore`. – Ralemos Aug 05 '20 at 14:14
  • I added this line .gitignore to .gcloudignore meaning I ignored the ignore file as suggested by @JohnHanley and it worked. GCP should provide the proper documents. – Nilay Singh Aug 05 '20 at 14:21

1 Answers1

1

As mentioned by @JohnHanley on the comments, the use of .gcloudignore is recommended in cases like this. You should ignore the .gitignore file inside the .gcloudignore to be able to use the required file.

So if you add this a line with .gitignore to your .gcloudignore it will fix the issue you are facing.

Ralemos
  • 5,571
  • 2
  • 9
  • 18