Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bamboo can't open ScriptBuildTask in temp with root privileges (Bamboo version 6.6.1 build 60605)

Sander Mol July 14, 2018

Greetings Atlassian Community,

Recently I have been trying to set up a CI-environment with a Docker-in-a-Docker (Dind) setup with a shared `docker.sock` (sibling strategy). Now everything seems to work okay-ish, however Bamboo is unable to run my defined job script:

Beginning to execute external process for build 'php-stack-test - test - Job 1 #9 (PHPSTACK-TEST-JOB1-9)'\n ... running command line: \n/opt/atlassian/bamboo/temp/runInDocker9198014177222089800.sh /bin/sh /var/atlassian/bamboo/temp/PHPSTACK-TEST-JOB1-9-ScriptBuildTask-3671834363422173327.sh\n ... in: /opt/atlassian/bamboo/temp\n
error	14-Jul-2018 11:28:03	/bin/sh: can't open '/var/atlassian/bamboo/temp/PHPSTACK-TEST-JOB1-9-ScriptBuildTask-3671834363422173327.sh'

 I notice the "ScriptBuildTask" file is deleted immediately after creation in the shared temp volume. I am unsure what deletes this file.

My Bamboo Spec file:

project:
   key: PHPSTACK
   plan:
      key: TEST
      name: test
dockerImage: my-docker-registry.serveo.net/my-php
stages:
   - jobs:
      - scripts:
         - composer -n install --prefer-dist --no-dev
         - phpunit

Both the whoami of the Bamboo and the test container show me as a root user. 

The Bamboo container runs this docker build command:

/usr/bin/docker run --volume /var/atlassian/bamboo/xml-data/build-dir/PHPSTACK-TEST-JOB1:/var/atlassian/bamboo/xml-data/build-dir/PHPSTACK-TEST-JOB1 --volume /var/atlassian/bamboo/temp:/var/atlassian/bamboo/temp --detach --name f1851818-15e5-4023-a5e1-2542acbe28b61179650 --net=host my-docker-registry.serveo.net/my-php tail -f /dev/null

 

If any more information is needed, please let me know.

With kind regards,

 

EDIT

I have file watched the temp folder on the host mounted volume, which resulted in the following chronological output:

-rw-r--r-- 1 user staff 417821 Jul 18 10:57 /Users/user/Intern/Bamboo_data/temp/webresources/3.cachedfile
event: 514
-rw-r--r-- 1 user staff 434571 Jul 18 10:57 /Users/user/Intern/Bamboo_data/temp/webresources/4.cachedfile
event: 514
-rw-r--r-- 1 user staff 436181 Jul 18 10:57 /Users/user/Intern/Bamboo_data/temp/webresources/3.cachedfile
event: 518
-rw-r--r-- 1 user staff 2322164 Jul 18 10:57 /Users/user/Intern/Bamboo_data/temp/webresources/4.cachedfile
event: 518
-rw-r--r-- 1 user staff 215131 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/5.cachedfile
event: 514
-rw-r--r-- 1 user staff 119222 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/6.cachedfile
event: 514
-rw-r--r-- 1 user staff 436181 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/5.cachedfile
event: 518
-rw-r--r-- 1 user staff 2320617 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/6.cachedfile
event: 518
-rw-r--r-- 1 user staff 427717 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/7.cachedfile
event: 514
-rw-r--r-- 1 user staff 436181 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/7.cachedfile
event: 518
-rw-r--r-- 1 user staff 5826 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/8.cachedfile
event: 518
-rw-r--r-- 1 user staff 434571 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/10.cachedfile
event: 514
-rw-r--r-- 1 user staff 13036 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/9.cachedfile
event: 518
-r-xr--r-- 1 user staff 50 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/PHPSTACK-TEST-JOB1-11-ScriptBuildTask-5451486074298017692.sh
event: 551
ls: /Users/user/Intern/Bamboo_data/temp/PHPSTACK-TEST-JOB1-11-ScriptBuildTask-5451486074298017692.sh: No such file or directory
event: 559
-rw-r--r-- 1 user staff 2340466 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/webresources/10.cachedfile
event: 518

With the path of the following line being red:

-r-xr--r--  1 user  staff  50 Jul 18 10:58 /Users/user/Intern/Bamboo_data/temp/PHPSTACK-TEST-JOB1-11-ScriptBuildTask-5451486074298017692.sh

2 answers

1 accepted

1 vote
Answer accepted
Jens Rutschmann _K15t_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2018

@nkmol I could solve my issue by mounting the build and temp dirs using the paths as the host (and docker daemon) sees them, and not as the bamboo server in its container sees them. By default these are paths that don't exist on the host but only inside the container of the bamboo server.

Here's for reference how we map paths into the bamboo-server container:

-v /home/bamboo/home:/var/atlassian/bamboo

I haven't seen such volume mappings in your specs file so that might be the issue.

This can be done by changing the volume configurations in Bamboo, not sure about Bamboo Specs. See the screenshot.

Hope that helps a bit.

bamboo-docker-config.png

Sander Mol August 11, 2018

Excuse my late response. 

This was exactly my problem, I forgot it was mounting the volumes from the perspective of the host.

Sadly Bamboo Specs YAML does not support custom volumes. However the Java variant does. Eventually resulting in this example script running a simple composer script in the Docker environment.

final Plan plan = new Plan(new Project()
.oid(new BambooOid("10r8szw61um0x"))
.key(new BambooKey("PHPSTACK"))
.name("php-stack-test"),
"test1",
new BambooKey("TEST1"))
.oid(new BambooOid("10qz3sasu0uf5"))
.pluginConfigurations(new ConcurrentBuilds()
.useSystemWideDefault(false))
.stages(new Stage("Default Stage")
.jobs(new Job("Default Job",
new BambooKey("JOB1"))
.finalTasks(new VcsCheckoutTask()
.description("Checkout Default Repository")
.checkoutItems(new CheckoutItem().defaultRepository()),
new ScriptTask()
.description("Composer install 2")
.interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
.inlineBody("composer -n install --prefer-dist --no-dev"))
.dockerConfiguration(new DockerConfiguration()
.image("myrepo/php-test")
.withoutDefaultVolumes()
.volume("/Users/{user}/Intern/Bamboo_data/temp", "${bamboo.tmp.directory}")
.volume("/Users/{user}/Intern/Bamboo_data/xml-data/build-dir/${bamboo.buildKey}", "${bamboo.working.directory}"))))
.linkedRepositories("Bitbucket local stack")

.triggers(new BitbucketServerTrigger())
.planBranchManagement(new PlanBranchManagement()
.delete(new BranchCleanup())
.notificationForCommitters());

I had to use "/Users/{user}/" instead of the MacOS "~" path for it to work. 

0 votes
Foong
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 25, 2018
Jens Rutschmann _K15t_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2018

Hi @Foong,

is this the same problem? The issue is about non-root images whereas @nkmol and me are using images that use the root user.

I also found in the logs that the script task does not seem to be executed with docker exec but just outside of the container:

simple 29-Jul-2018 23:02:37 Starting task 'Run test script' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
command 29-Jul-2018 23:02:37 Beginning to execute external process for build 'Dummy - Dummy - Dummy #9 (DUMMY-DUMMY-JOB1-9)'\n ... running command line: \n/opt/atlassian/bamboo/temp/runInDocker3475537595457460619.sh /bin/sh /var/atlassian/bamboo/temp/DUMMY-DUMMY-JOB1-9-ScriptBuildTask-2801009385737648867.sh\n ... in: /opt/atlassian/bamboo/temp\n
error 29-Jul-2018 23:02:37 /bin/sh: can't open '/var/atlassian/bamboo/temp/DUMMY-DUMMY-JOB1-9-ScriptBuildTask-2801009385737648867.sh': No such file or directory

It does however run the container initialization script (whatever that one does?) inside the container using docker exec:

command 29-Jul-2018 23:02:35 Beginning to execute external process for build 'Dummy - Dummy - Dummy #9 (DUMMY-DUMMY-JOB1-9)'\n ... running command line: \n/usr/bin/docker exec a30b367b-12bd-4092-a8f6-4e9630bf5f22133169159 /tmp/initialiseContainer.sh\n ... in: /var/atlassian/bamboo/xml-data/build-dir/DUMMY-DUMMY-JOB1\n

 Is this a different problem?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events