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

Help building Java project using Maven inside Docker

PeteSmith April 28, 2021

Hi all.

I'm a long time JIRA user. I've started a new job, and we decided to get JIRA, Bamboo and Bitbucket, for a fully integrated experience.

JIRA and Bitbucket are all configured nicely, and working perfectly.

Bamboo is a different matter. I've fallen at the (almost) first hurdle.

We've decided to try building in Docker, so we've created our own Docker image, based on the Atlassian Docker Agent image, with the addition of Maven and Ant. This has been pushed to a Docker repos in the Bamboo machine. Docker is installed on the Bamboo machine, and all works as expected.

I've created a linked repository, and all is well.

When I try to build the plan which uses the Docker agent, it fails instantly as soon as it calls "mvn clean install", it returns with a result code 137, which could be anything between "no", and a memory error. It's not like it gets halfway through the build, it's an immediate failure.

simple 28-Apr-2021 19:34:15 Starting task 'Clean and Install' of type 'com.atlassian.bamboo.plugins.maven:task.builder.mvn3'
command 28-Apr-2021 19:34:15 Beginning to execute external process for build 'SIM Quality of Experience - SIMQOE Plan - Default Job #6 (SIMQOE-SP-JOB1-6)'\n ... running command line: \n/home/bamboo/atlassian-bamboo-7.2.1/temp/runInDocker2427305850259878450.sh /usr/share/maven/bin/mvn --batch-mode clean install\n ... in: /home/bamboo/atlassian-bamboo-7.2.1/temp\n
simple 28-Apr-2021 19:34:17 Failing task since return code of [/home/bamboo/atlassian-bamboo-7.2.1/temp/runInDocker2427305850259878450.sh /usr/share/maven/bin/mvn --batch-mode clean install] was 137 while expected 0
simple 28-Apr-2021 19:34:17 Finished task 'Clean and Install' with result: Failed

 

  • I've tried setting the MAVEN_OPTS to tweak the memory options, all the way from 128M up to 1Gb.
  • I've created a new plan, which runs on the bare Bamboo server (had to install maven on it), and it "works". It fails to build, but that's a different matter. Maven starts up, does its thing, then fails. I don't mind about that.
  • I've modified the maven target, removing "clean install", replacing it with "-version". It returns Maven 3.6.3, running in JDK 1.8.0_292, so maven is there, the JDK is correct, installed and functional.
  • I've taken the docker image, manually started it on my Windows PC, sharing a volume, pointing my repos at /mnt/test, ssh'd into it, and run "mvn clean install" in /mnt/test, and it builds correctly (better than on the Docker box itself)
  • I've taken the docker image on the Bamboo server, manually started it, copying the repos files to my home dir, sharing that as /mnt/test, and running mvn clean install. It builds correctly too

It only fails when calling maven in docker, from Bamboo. The only substantive difference is 

/home/bamboo/atlassian-bamboo-7.2.1/temp/runInDocker2427305850259878450.sh

which calls maven.

Because it fails so quickly, it tidies up the files, and deletes the temp file, so I don't know what's going on.

Have I missed anything?

Thanks.

Pete.

2 answers

1 vote
PeteSmith April 29, 2021

I think I've found the issue:

From

https://hub.docker.com/r/atlassian/bamboo-agent-base/ 

Make sure your Bamboo server is running and has remote agents support enabled. To enable it:

I tried rebuilding the docker agent to use localhost, but when it starts up, it complains (correctly) that there is already an agent running on the machine.

Looks like I'm building locally for now!

Pete.

0 votes
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 28, 2021

Hi! 

What environment options did you configure for agent? 

PeteSmith April 28, 2021

To be honest - I don't know.

I set up the plan, selected "Docker", entered the fully qualified local registry name (192.168.80.19:5000/build_agent). It's got the default shared volumes (Bamboo temp & working directories)

DockerConfig.png

The agent config itself is pretty much the default.

I've added a Docker capability to this agent.

The JDK and Maven paths are common to the agent and host, so they're shared

Config.png

Does this help?

Thanks for your assistance!

Pete.

PeteSmith April 29, 2021

I've done some more investigating.

I don't believe the problem is with maven itself.

I stripped everything back to basics. I removed the maven build step, and replaced it with a script step which just did  pwd & ls -la. 

This failed with a permission denied error. I modified the docker config to add 

--privileged

This then worked. I was able to pwd and ls. Everything seemed to be in place and correct - the source was present.

I then extended the script to check for free memory - the VM was only 4Gb, so we bumped that up to 8. Once that was done, we had >5Gb available according to free -m.

This is then where things get strange.

If I try to run any command which takes more than a second or so to run, it exits immediately with return code 137. When I thought maven was returning with 137, it was actually the calling script.

If I try to "sleep 2m", or "free -m -s 1 -c 10", it gets about 2 seconds in, then the script exits.

The dockerfile is

FROM atlassian/bamboo-agent-base:latest

USER root

RUN apt-get update
RUN apt-get install maven -y
RUN apt-get install git -y
RUN apt-get install ant -y

and the docker-compose is

version: "3.9"
services:
agent:
build: .
image: build_agent
container_name: build_agent
init: true
command: http://192.168.80.18:8085

I'm completely stuck just now.

Thanks.

Pete

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events