2

I have a Google Source Repository that mirrors a private Github repo of mine that contains code for a Python package. I also have a Cloud Run instance where I'd like to install this private Python library. How can I go about doing that in the cloudbuild.yaml or Dockerfile?

pete
  • 561
  • 6
  • 16
  • How do you want to get this library? Perform a git clone? perform a pip install? – guillaume blaquiere Feb 21 '21 at 17:51
  • @guillaumeblaquiere I could `git clone` and then CD into the directory to `python setup.py install`, or I could `pip install`. As long as it gets installled – pete Feb 21 '21 at 19:16

1 Answers1

4

Cloud Source repository is a Git repository. So, if you want to get sources (your private library) from there, simply clone the repo (the head, or a specific tag/commit sha).

You can't use pip install command because you need a private pipy server installed to achieve this. If you have this, get the credentials and request it!


That's for the principle. Then how to achieve this in Cloud Build or in Docker build.

IMO, the easiest is in the Cloud Build pipeline. Load a GIT compliant image (for instance gcr.io/cloud-builders/git) and close your Cloud Source repo. I recommend this step because you can use the Cloud Build authentication context to log into Cloud Source repository.

Then, in your Dockerfile, copy all your environment (your code and the venv that contains the download library). The additional public libraries can be download inside the Dockerfile, or in the Cloud Build, as you wish.

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • I added a step in the `cloudbuild.yaml` that clones the repository. Then, in the `Dockerfile`, I added the lines `COPY private-repo/ private-repo/` and then `RUN python private-repo/setup.py`, but the logs indicate that the file is not found. – pete Feb 22 '21 at 02:29
  • 1
    @pete you might wanna check how `dir` works on Cloud Build https://cloud.google.com/build/docs/build-config#dir – Donnald Cucharo Feb 22 '21 at 09:12