Docker Image Artifact unavailable on Following Steps
Asked by Caleb Powell:

Hi,

I am trying to build a docker image in one step, and then deploy it to a container registry in another step. I am following the example laid out in Bitbucket pipeline Validator. My steps look like this:

```
- step: &build-docker-image
    name: Build Docker Image
    caches:
      - maven
      - docker
      - node

    script:
      - ./mvnw verify -Pprod -DskipTests
      - WARFILE=( "target"/*.war )
      - echo $WARFILE
      - cp $WARFILE src/main/docker/app.war
      - docker build -t foobar -f src/main/docker/Dockerfile src/main/docker
      - docker save foobar --output foobar-dockerimg.tar
    services:
      - docker
    artifacts:
      - foobar-dockerimg.tar
...

```

This step runs successfully, and the output indicates that it has successfully stored the artifact (the artifact is also available for download in the Artifacts tab for the Step):
> Searching for files matching artifact pattern foobar-dockerimg.tarArtifact pattern foobar-dockerimg.tar matched 1 files with a total size of 205 MiBCompressed files matching artifact pattern foobar-dockerimg.tar to 167 MiB in 9 secondsUploading artifact of 167 MiBSuccessfully uploaded artifact in 9 seconds

This is the second task that needs to use the artifact to publish:

```

- step: &publish-docker-img-prodcr
    name: Publish Artifacts -> Prod CR
    caches:
      - maven
      - docker
      - node
    script:
      - echo "*** Publishing Application Version:${CVC_APP_VERSION} to ${AZ_CR_SERVER_PROD}"
      - ls -lah
      - pwd
      - docker login $AZ_CR_SERVER_PROD -u "$AZ_CR_USER_PROD" -p "$AZ_CR_PASSWORD_PROD"
      - docker load --input ./foobar-dockerimg.tar
      - ... publishing stuff...
    services:
      - docker
    artifacts:
      - foobar-dockerimg.tar
```

When the step executes, the "Build setup" output indicates that it has successfully downloaded my artifact:
>
> Artifact "foobar-dockerimg.tar": DownloadingArtifact "foobar-dockerimg.tar": Downloaded 167 MiB in 5 secondsArtifact "foobar-dockerimg.tar": ExtractingArtifact "foobar-dockerimg.tar": Extracted in 1 seconds

Unfortunately, the \`docker load --input ./foobar-dockerimg.tar\` command in the second step always fails with the message:
>
> + docker load --input ./foobar-dockerimg.tar
>
> open ./foobar-dockerimg.tar: no such file or directory
>
The \`ls -lah\` command in the step confirms that the foobar-dockerimg.tar artifact is not available in the build directory (i.e. this doesn't appear to be an issue with the \`docker load\` command.

Is there something I am missing with respect to how artifacts work? Am i doing anything obviously wrong here?


Answers:
author: Caleb Powell
body: On a related note, I tried replacing the docker image .tar file with a vanilla text file (so, in Step #1 the artifact is created via \`touch foobar.txt\` and I add some data via \`echo "some data" \>\> foobar.txt\`. This foobar.txt file artifact is successfully delivered to my build workspace on Step #2.

The fact that the foobar.txt file is being delivered properly on Step #2 suggests that my general approach to publishing and consuming artifacts between steps is valid. I suspect one of two things is going on:

1. The docker image .tar file is too large, or some other system constraint is preventing a successful download. In any case, the Bitbucket logging doesn't indicate any constraint violation.
2. There is a bug in pipelines, where the artifact isn't downloaded successfully to the workspace, or, the build steps are kicked off before the artifact is downloaded successfully.

Of course, I could also be missing something obvious. But my approach here is based on the Docker example provided by Bitbucket, so I'm not sure what I could be doing wrong.

comments: author: Martin Nicolaides
body: Same exact thing is happening with me.

End of the build output:

Successfully built a9da703464ce  
Successfully tagged blahbuild:0.1.1  
mkdir ./build-artifacts  
docker save -o build-artifacts/blahbuild_0.1.1.tar blahbuild:0.1.1  
dir -ls build-artifacts/\*  
15238784 -rw------- 1 root root 15604507648 Jun 10 19:37 build-artifacts/blahbuild_0.1.1.tar

As you can see the tar file is 15GB.

Nothing in the Artifacts tab.

Probably the size.


Tags: bitbucket-cloud

cloud