Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish an Artifact from inside a Docker container

I'm running a TeamCity agent that spawns a docker container, running several tasks inside that (php) container. Such as phpunit, phplint and composer. I zipped the content inside the container if all tests pass, it will create a phpproject.zip.

After it's done I would like to push that phpproject.zip as an Artifact back to the TeamCity server from inside the docker container.

My docker container is running with the --rm parameters to remove the container after the script is done.

Is this possible?

Tim

like image 448
Tim Ververs Avatar asked Mar 02 '16 16:03

Tim Ververs


People also ask

How do I publish a docker image as an artifact in Azure Devops?

Steps: Add task docker->switch the task version to 0->select the option Run a Docker command , then we could run the docker save command, check the pic below. Is there any better way of doing this apart from saving an image. We recommend that you use this to upload the docker image as an artifact.

Can we create image from container in Docker?

If you modify the contents of a container, you can use the docker commit command to save the current state of the container as an image.


1 Answers

You can map a volume of the Docker daemon to the container with the -v parameter and publish the artifacts to the daemon:

...
# Your build path and build command here
VOLUME /foo/build
ENTRYPOINT make

In TeamCity, configure a Docker build step to build the Dockerfile, and name:tag the resulting image. Add a second step in which you configure an other... Docker command as run, with the arguments:

-v /tmp/build:/foo/build --rm <name of image>

The result is then available in /tmp/build on the agent, and you can configure that as artifact path in the project's settings, or alternatively echo "##teamcity[publishArtifacts '/tmp/build']" somewhere.

like image 78
Tim Ververs Avatar answered Sep 27 '22 22:09

Tim Ververs