Script tasks to the rescue!
You CAN use docker on a Windows Agent, but it requires more manual steps.
I have docker running my builds on Windows 10 with:
- Bamboo Server 7.2.3
- Docker Desktop 4.2.0
- Using Bamboo-Specs
There are various issues that I had to overcome, but now that everything is in place, it works very well.
That's not saying that Atlassian shouldn't support this feature natively (and it doesn't seem that difficult), but in case you want to implement docker containers in your build system, you can use the example YAML bamboo spec code below.
This code includes examples for
- Pulling your docker image
- Running your image as a container
- Executing commands on your container
- Stopping the container
- Copying files off of the container to the host system
- Removing the container
You may also need to log into your repo, if required, but that's just another script task executing the docker login command.
Example Docker YAML Scripts:
Example Docker Tasks:
key: EDT
tasks:
## Pull the docker image
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker pull ${bamboo.docker_image_name}
## Run the docker image as a new container with a couple of different volumes mounted
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker run --volume ${bamboo.working.directory}:${bamboo.docker_container_build_dir} --volume c:\something_else:c:\something_else_in_container --detach --interactive --tty --net=nat --workdir=${bamboo.docker_container_build_dir} --name ${bamboo.docker_container_name} ${bamboo.docker_image_name}
## Execute a .NET build on the container
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker exec -i -w ${bamboo.docker_container_build_dir} ${bamboo.docker_container_name} dotnet restore ${bamboo.solution_file}
## Stop the container because you can't use "docker cp" on a running Windows container
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker stop ${bamboo.docker_container_name}
## Copy some files off of the container to the local file system
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker cp ${bamboo.docker_container_name}:${bamboo.docker_container_buildoutput_dir} ${bamboo.working.directory}\buildoutput
## Remove the stopped container (container must be stopped first)
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker rm ${bamboo.docker_container_name}
## Some variables
## This is necessary when using TCP for controlling the docker daemon.
## If you use named pipes, setting this environment variable is not required.
docker_host: tcp:
docker_registry: <address:port>
docker_registry_and_path: ${bamboo.docker_registry}/<your_path_on_registry>
docker_image_name: ${bamboo.docker_registry_and_path}/<your_image_name>:latest
docker_container_name: <some_identifier>-${bamboo.buildNumber}
docker_container_build_dir: c:\build
docker_container_buildoutput_dir: c:\buildoutput
solution_file: <your_solution_file>
Hey @uka2-matthew - I noticed the same issue. Remove the "tail -f /dev/null" from the command that Bamboo tries to run, and that command will then succesfully work in a Windows OS running docker, so it does seem like a trivial step to remove the tail -f. There may well be other parts of the process that then need adjusting to suit a Windows based image, but it would be great to hear from an Atlassian on their plan here.
As we have a large % of our teams dev'ing in Windows, we've been looking for a non-native solution and currently testing using https://windtunnel.io/products/ksb/#/ - we've spoken with the WindTunnel team and they released version 1.3.31 last month that provides Windows support - https://marketplace.atlassian.com/apps/1222674/kubernetes-agents-for-bamboo/version-history
While it'd be great to have better native support, the pricing for this plugin seems completely reasonable to me for what it delivers, so if that's the direction we need to go, then fine by me!
I'll report back with results from our testing
CCM