Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Google Cloud Build recurse through directories of artifacts?

My workspace looks like this:

|
|--> web-app
     |
     |--> src
     |--> build
          |
          |--> fonts
          |--> static

My cloudbuild.json looks like this:

{
    "steps" : [
    {
...
    },
    ],
    "artifacts": {
        "objects": {
            "location": "gs://my_bucket/",
            "paths": [
                "web-app/build/**"
            ]
        }
    }
}

What I'm hoping for is that Google Cloud Build will recurse through the contents of the build/ folder and copy the files & directories to my storage bucket. Instead it only copies the files that are rooted in the build/ directory, ignores the directories and gives a warning about using the -r option of gsutil cp.

Here is the build output:

...
Artifacts will be uploaded to gs://my_bucket using gsutil cp
web-app/build/**: Uploading path....
Omitting directory "file://web-app/build/fonts". (Did you mean to do cp -r?)
Omitting directory "file://web-app/build/static". (Did you mean to do cp -r?)
Copying file://web-app/build/index.html [Content-Type=text/html]...
Copying file://web-app/build/asset-manifest.json [Content-Type=application/json]...
Copying file://web-app/build/favicon.ico [Content-Type=image/vnd.microsoft.icon]...
Copying file://web-app/build/manifest.json [Content-Type=application/json]...   
Copying file://web-app/build/service-worker.js [Content-Type=application/javascript]...
/ [5/5 files][ 28.4 KiB/ 28.4 KiB] 100% Done                                    
Operation completed over 5 objects/28.4 KiB.                                     
web-app/build/**: 5 matching files uploaded
5 total artifacts uploaded to gs://my_bucket/
Uploading manifest artifacts-d4a2b3e4-97ba-4eb0-b226-e0c914ac4f61.json
Artifact manifest located at gs://my_bucket/artifacts-d4a2b3e4-97ba-4eb0-b226-e0c914ac4f61.json
DONE

The documentation https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames#directory-by-directory-vs-recursive-wildcards suggests that this shouldn't be the case.

I guess I could use the gsutil cloud builder but my suspicion is that I don't need to and that I'm doing something wrong here.

like image 943
Chris Priest Avatar asked Oct 16 '18 06:10

Chris Priest


People also ask

How does Google Cloud build work?

Cloud Build is a service that executes your builds on Google Cloud. Cloud Build can import source code from a variety of repositories or cloud storage spaces, execute a build to your specifications, and produce artifacts such as Docker containers or Java archives.

Which Google Cloud tools can be used to build a continuous integration pipeline?

Google Cloud CI/CD provides various tools for continuous integration and deployment and integrates seamlessly with third-party solutions. Google Cloud Build and Google Cloud Run are two Google Cloud services that use pipelines to automate builds and deployments.

How do I upload a directory to the GCS bucket?

In the Google Cloud console, go to the Cloud Storage Buckets page. Navigate to the bucket. Click on Create folder to create an empty new folder, or Upload folder to upload an existing folder.

Where do you store building artifacts?

We recommend using Artifact Registry for storing build artifacts. Artifact Registry is a Google Cloud product that you can integrate with Cloud Build to securely store and manage your artifacts in private or public repositories.


1 Answers

There's currently (2018-11) no way to copy an artifacts directory recursively one-to-one. Your best bet is to use a gsutil step in your cloudbuild.yaml file (as you mentioned already), similar to:

steps:
- ....
- name: 'gcr.io/cloud-builders/gsutil'
  args: ['-m', 'cp', '-r', 'web-app/build*', 'gs://my_bucket/$BUILD_ID']
like image 138
Maik Avatar answered Oct 23 '22 22:10

Maik