Mounting volumes, however, doesn't seem to work. I tried the following locally hoping that /workspace will get mounted but it looks like it doesn't.
Broken:
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [
'run',
'--rm',
'--network', 'cloudbuild',
'--volume', '/workspace:/workspace',
'node:8.11-alpine',
'sh', '-c', 'pwd && ls -lah && ls -lah /workspace'
]
- name: 'gcr.io/cloud-builders/docker'
args: [
'run',
'--rm',
'--network', 'cloudbuild',
'node:8.11-alpine',
'sh', '-c', 'pwd && ls -lah && ls -lah /workspace'
]
Working:
I can't use something like below, that mount the current directory correctly, because I need a service to be up when I run the tests, that is, I need make sure the container runs with --network=cloudbuild.
- name: 'gcr.io/cloud-builders/npm'
args: ['test']
See this for more information: https://github.com/GoogleCloudPlatform/cloud-builders/issues/321.
Output:
$ cloud-build-local --config=cloudbuild.yaml --dryrun=false .
2018/08/06 19:00:08 Warning: The server docker version installed (18.06.0-ce-rc3) is different from the one used in GCB (17.12.0-ce)
2018/08/06 19:00:08 Warning: The client docker version installed (18.06.0-ce-rc3) is different from the one used in GCB (17.12.0-ce)
Using default tag: latest
latest: Pulling from cloud-builders/metadata
Digest: sha256:1a4ae9cbfeb9eb982c8788f1db42f80555499000cd1ce5dbfe657af9955f8812
Status: Image is up to date for gcr.io/cloud-builders/metadata:latest
2018/08/06 19:00:34 Started spoofed metadata server
2018/08/06 19:00:34 Build id = localbuild_478a3f90-ca58-400a-967f-e07fd58082c0
2018/08/06 19:00:34 status changed to "BUILD"
BUILD
Starting Step #0
Step #0: Already have image (with digest): gcr.io/cloud-builders/docker
Step #0: /
Step #0: total 64
Step #0: drwxr-xr-x 1 root root 4.0K Aug 6 18:00 .
Step #0: drwxr-xr-x 1 root root 4.0K Aug 6 18:00 ..
Step #0: -rwxr-xr-x 1 root root 0 Aug 6 18:00 .dockerenv
Step #0: drwxr-xr-x 1 root root 4.0K Jul 6 16:02 bin
Step #0: drwxr-xr-x 5 root root 340 Aug 6 18:00 dev
Step #0: drwxr-xr-x 1 root root 4.0K Aug 6 18:00 etc
Step #0: drwxr-xr-x 1 root root 4.0K Jul 6 15:55 home
Step #0: drwxr-xr-x 1 root root 4.0K Jul 5 14:47 lib
Step #0: drwxr-xr-x 5 root root 4.0K Jul 5 14:47 media
Step #0: drwxr-xr-x 2 root root 4.0K Jul 5 14:47 mnt
Step #0: drwxr-xr-x 3 root root 4.0K Jul 6 16:02 opt
Step #0: dr-xr-xr-x 237 root root 0 Aug 6 18:00 proc
Step #0: drwx------ 1 root root 4.0K Jul 6 15:55 root
Step #0: drwxr-xr-x 2 root root 4.0K Jul 5 14:47 run
Step #0: drwxr-xr-x 2 root root 4.0K Jul 5 14:47 sbin
Step #0: drwxr-xr-x 2 root root 4.0K Jul 5 14:47 srv
Step #0: dr-xr-xr-x 13 root root 0 Aug 6 18:00 sys
Step #0: drwxrwxrwt 1 root root 4.0K Jul 6 16:02 tmp
Step #0: drwxr-xr-x 1 root root 4.0K Jul 6 16:02 usr
Step #0: drwxr-xr-x 1 root root 4.0K Jul 5 14:47 var
Step #0: drwxr-xr-x 2 root root 40 Aug 6 18:00 workspace
Step #0: total 4
Step #0: drwxr-xr-x 2 root root 40 Aug 6 18:00 .
Step #0: drwxr-xr-x 1 root root 4.0K Aug 6 18:00 ..
Finished Step #0
Starting Step #1
Step #1: Already have image (with digest): gcr.io/cloud-builders/docker
Step #1: /
Step #1: total 64
Step #1: drwxr-xr-x 1 root root 4.0K Aug 6 18:00 .
Step #1: drwxr-xr-x 1 root root 4.0K Aug 6 18:00 ..
Step #1: -rwxr-xr-x 1 root root 0 Aug 6 18:00 .dockerenv
Step #1: drwxr-xr-x 1 root root 4.0K Jul 6 16:02 bin
Step #1: drwxr-xr-x 5 root root 340 Aug 6 18:00 dev
Step #1: drwxr-xr-x 1 root root 4.0K Aug 6 18:00 etc
Step #1: drwxr-xr-x 1 root root 4.0K Jul 6 15:55 home
Step #1: drwxr-xr-x 1 root root 4.0K Jul 5 14:47 lib
Step #1: drwxr-xr-x 5 root root 4.0K Jul 5 14:47 media
Step #1: drwxr-xr-x 2 root root 4.0K Jul 5 14:47 mnt
Step #1: drwxr-xr-x 3 root root 4.0K Jul 6 16:02 opt
Step #1: dr-xr-xr-x 237 root root 0 Aug 6 18:00 proc
Step #1: drwx------ 1 root root 4.0K Jul 6 15:55 root
Step #1: drwxr-xr-x 2 root root 4.0K Jul 5 14:47 run
Step #1: drwxr-xr-x 2 root root 4.0K Jul 5 14:47 sbin
Step #1: drwxr-xr-x 2 root root 4.0K Jul 5 14:47 srv
Step #1: dr-xr-xr-x 13 root root 0 Aug 6 18:00 sys
Step #1: drwxrwxrwt 1 root root 4.0K Jul 6 16:02 tmp
Step #1: drwxr-xr-x 1 root root 4.0K Jul 6 16:02 usr
Step #1: drwxr-xr-x 1 root root 4.0K Jul 5 14:47 var
Step #1: ls: /workspace: No such file or directory
Finished Step #1
2018/08/06 19:00:40 status changed to "ERROR"
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/docker" failed: exit status 1
2018/08/06 19:00:42 Build finished with ERROR status
make: *** [ci] Error 1
In your config, the second step doesn't have a volume mount, so the /workspace directory doesn't exist.
@bendory don't know why you closed this issue.
The problem is /workspace is not being mounted correctly.
I know the second example doesn't mount it. I did that intentionally.
Are you able to reproduce the issue in the first step?
Here is a yaml that demonstrates proper mounting of /workspace into a docker run:
~/cloudbuild$ cat mount.yaml
steps:
- name: 'ubuntu'
args: [ "touch", "foo" ]
- name: 'ubuntu'
args: [ "ls", "-l" ]
- name: 'gcr.io/cloud-builders/docker'
args: [ "run", "--volume", "/workspace:/workspace", "--rm", "ubuntu", "ls", "-l", "/workspace" ]
~/cloudbuild$ gcloud builds submit --no-source --config=mount.yaml
Created [https://cloudbuild.googleapis.com/v1/projects/bendory-argo/builds/e6a176c4-172e-40f7-8a1a-0f9ea7526f30].
Logs are available at [https://console.cloud.google.com/gcr/builds/e6a176c4-172e-40f7-8a1a-0f9ea7526f30?project=1063385002080].
--------------------------------------------------------------------------- REMOTE BUILD OUTPUT ---------------------------------------------------------------------------
starting build "e6a176c4-172e-40f7-8a1a-0f9ea7526f30"
FETCHSOURCE
BUILD
Starting Step #0
Step #0: Already have image (with digest): ubuntu
Finished Step #0
Starting Step #1
Step #1: Already have image (with digest): ubuntu
Step #1: total 0
Step #1: -rw-r--r-- 1 root root 0 Aug 7 17:05 foo
Finished Step #1
Starting Step #2
Step #2: Already have image (with digest): gcr.io/cloud-builders/docker
Step #2: total 0
Step #2: -rw-r--r-- 1 root root 0 Aug 7 17:05 foo
Finished Step #2
PUSH
DONE
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID CREATE_TIME DURATION SOURCE IMAGES STATUS
e6a176c4-172e-40f7-8a1a-0f9ea7526f30 2018-08-07T17:04:53+00:00 6S - - SUCCESS
If that doesn't make sense, please provide a similarly simple build configuration that demonstrates the problem you are having.
@bendory, using the steps you mentioned above:
steps:
- name: 'ubuntu'
args: [ "touch", "foo" ]
- name: 'ubuntu'
args: [ "ls", "-l" ]
- name: 'gcr.io/cloud-builders/docker'
args: [ "run", "--volume", "/workspace:/workspace", "--rm", "ubuntu", "ls", "-l", "/workspace" ]
I ran this with cloud-build-local --config=cloudbuild.yaml --dryrun=false ..
The output I get is:
2019/04/02 11:48:56 Warning: The server docker version installed (18.09.2) is different from the one used in GCB (18.09.0)
2019/04/02 11:48:56 Warning: The client docker version installed (18.09.2) is different from the one used in GCB (18.09.0)
Using default tag: latest
latest: Pulling from cloud-builders/metadata
Digest: sha256:d2e7a5e204ed695f082c2422c4ae39ce74e4c01c06337dc63b84e192c8d888f4
Status: Image is up to date for gcr.io/cloud-builders/metadata:latest
2019/04/02 11:49:03 Started spoofed metadata server
2019/04/02 11:49:03 Build id = localbuild_5ed93f9c-8d4b-419d-b4ae-4d85657b05e3
2019/04/02 11:49:03 status changed to "BUILD"
BUILD
Starting Step #0
Step #0: Already have image (with digest): ubuntu
Finished Step #0
2019/04/02 11:49:05 Step Step #0 finished
Starting Step #1
Step #1: Already have image (with digest): ubuntu
Step #1: total 4
Step #1: -rw-r--r-- 1 501 dialout 230 Apr 2 10:48 cloudbuild.yaml
Step #1: -rw-r--r-- 1 root root 0 Apr 2 10:49 foo
Finished Step #1
2019/04/02 11:49:06 Step Step #1 finished
Starting Step #2
Step #2: Already have image (with digest): gcr.io/cloud-builders/docker
Step #2: total 0
Finished Step #2
2019/04/02 11:49:10 Step Step #2 finished
2019/04/02 11:49:10 status changed to "DONE"
DONE
foo is not in the output. Any ideas?
Seems like Cloud Build local doesn't do the same as gcloud builds submit --no-source --config=cloudbuild.yaml.
...
Step #2: Already have image (with digest): gcr.io/cloud-builders/docker
Step #2: total 0
Step #2: -rw-r--r-- 1 root root 0 Apr 2 10:53 foo
Finished Step #2
PUSH
DONE
Hopefully this helps someone else out.
Ditto the above. Can this be reopened? The behavior is different between the local and remote build...
Most helpful comment
Here is a yaml that demonstrates proper mounting of /workspace into a docker run:
If that doesn't make sense, please provide a similarly simple build configuration that demonstrates the problem you are having.