0

My Dockerfile includes a COPY command which copies a directory that was just created in the pipeline.

COPY ["$CI_PROJECT_DIR/ui-dist/", "/content/ui-dist/"]

That COPY command fails with the following error:

COPY failed: stat /var/lib/docker/tmp/docker-builder597514812/ui-dist: no such file or directory

However, I know the directory exists because right before I build the image, ls $CI_PROJECT_DIR/ui-dist prints bundle.js

The runner is using the dind service. I'm not sure if that's relevant.

EDIT:

Okay, I tried removing the reference to the env variable. i.e. I changed the pipeline from

- docker cp ui:/content/dist $CI_PROJECT_DIR/ui-dist
- docker build --tag ${IMAGE_ID} api

to

- docker cp ui:/content/dist ui-dist
- docker build --tag ${IMAGE_ID} api

and I've updated the docker command to

COPY ["ui-dist/", "/content/ui-dist/"]

and I'm still getting this error message:

COPY failed: stat /var/lib/docker/tmp/docker-builder488922739/ui-dist: no such file or directory
chris.va.rao
  • 373
  • 1
  • 10
  • $CI_PROJECT_DIR is an environment variable? Are you passing the value for it using `--build-args` in the `docker build` command? – vijay v Apr 04 '20 at 04:50
  • It's an environment variable. Docker is evaluating it to `/var/lib/docker/tmp/docker-builder597514812` as you can see from the output above – chris.va.rao Apr 04 '20 at 17:23
  • Only if you're creating the Dockerfile from the pipeline and building, the value will be replaced. If you're checking out your code and then building then you need to.pass those variable as a build argument. – vijay v Apr 05 '20 at 02:56
  • Please see my edit – chris.va.rao Apr 06 '20 at 17:08
  • Can't you have a script directive like --> ```build_image: script: - cd /path/to-docker-and-copy-files/ - docker build -t my-docker-image . - docker run my-docker-image /script/to/run/tests``` Given your last EDIT, it says no such file, means you're trying to build an image that doesn't have the required contents to be copied from the present working directory. – vijay v Apr 07 '20 at 15:52

1 Answers1

0

I figured it out. I had to copy the asset into the api folder where the Dockerfile is located.

The docker builds take place in /builds/$CI_PROJECT_PATH/.

So, the asset had to be copied into /builds/$CI_PROJECT_PATH/api

chris.va.rao
  • 373
  • 1
  • 10