buildkite-plugins / docker-compose-buildkite-plugin

🐳⚡️ Run build scripts, and build + push images, w/ Docker Compose
MIT License
172 stars 139 forks source link

The JAVA_HOME environment variable is not defined correctly, #358

Closed sharon-go closed 1 year ago

sharon-go commented 1 year ago

Hey,

On my local server echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home

docker-compose.yml version: "3" services: maven:

Run pre-built maven image from docker library

image: maven
volumes:
  # Cache maven dependencies
  - $HOME/.m2:/root/.m2
  # Mount the application source and target directories
  - ..:/app
# Run maven inside the application directory
working_dir: /app

volumes: maven-repository:

pipeline.yml steps:

when trying to build my java project getting this error:

docker-compose -f .buildkite/docker-compose.yml -p buildkite0184627a9f4e4fc4b0452a9bdce7c59b run --name buildkite0184627a9f4e4fc4b0452a9bdce7c59b_maven_build_49 --rm maven /bin/sh -e -c 'mvn clean install -P local' The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program.

user command error: The plugin docker-compose command hook exited with status 1

toote commented 1 year ago

@sharon-go from what I can read, the error comes from your docker image so that means that the variable is not defined correctly in the environment inside the container. The fact that it is defined in your machine is irrelevant... unless you pass it on, which I wouldn't recommend because probably the path specified in that variable wouldn't be the same.

That said, assuming you are running the official and latest maven image as mentioned, that variable is indeed defined when the image is created and it is propagated when running as well:

$ docker run --rm -ti maven:latest /bin/sh -c 'env | sort | grep JAVA'
JAVA_HOME=/opt/java/openjdk
JAVA_VERSION=jdk-17.0.5+8

I can duplicate the error if I replace the variable with another value:

$ docker run --rm -ti -e JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home maven 
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

So the issue appears to be that either your docker compose file or your plugin's configuration is replacing the variable as it comes in the image to an invalid value :(

sharon-go commented 1 year ago

Hey,

Look like an issue in docker-maven https://github.com/carlossg/docker-maven/issues/282

I did try to run the mvn command using your example same issue: docker run --rm -ti maven:latest /bin/sh -c 'mvn --version' The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program.

docker run --rm -ti maven:latest /bin/sh -c 'env | sort | grep JAVA' JAVA_HOME=/opt/java/openjdk JAVA_VERSION=jdk-17.0.5+8

toote commented 1 year ago

@sharon-go glad to know that it is a compatibility issue between the latest maven images and old docker daemons and not something in this plugin :)

sharon-go commented 1 year ago

Yes this is the issue :)

Thank you .

docker run --rm -ti maven:latest /bin/sh -c 'mvn --version' Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /usr/share/maven Java version: 17.0.5, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "5.15.49-linuxkit", arch: "amd64", family: "unix"