Search code examples
firebasegoogle-cloud-platformgoogle-cloud-build

Using Google Cloud Storage in The Google Cloud Build


According to the documentation google cloud build can build from google cloud storage or a repository. But I'm having a hard time finding documentation on how to use files I upload to google cloud storage in the build steps. My intention is for a website where my jekyll source code is in the repository and my images are in google cloud storage; I'd like to add the images to the jekyll output and then upload to firebase with these steps.

Thanks for any guidance provided!


Solution

  • For a step in Cloud Build to copy files you would provide your Cloud Build service account with IAM permission to read the files in the bucket (probably something like: roles/storage.objectViewer).

    Once the Service Account used by Cloud Build can read the files you would create a step to pull the files in before your step to deploy to Firebase.

    A rough example:

    steps: 
      - name: 'gcr.io/cloud-builders/gsutil'
        args: ['cp', 'gs://$MY_BUCKET/*.jpg', '.']
    
      - name: gcr.io/$PROJECT_ID/firebase
        args: ['deploy', '--project=$PROJECT_ID', '--only=hosting']