question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The plugin does not honor the JAVA_HOME I set in ENV directive of Dockfile

See original GitHub issue

Description

The plugin does not honor the JAVA_HOME I set in ENV directive of Dockfile, it replaces it to the JAVA_HOME I set on host machine, for example /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home

Info

  • d-m-p version : 0.31.0
  • Maven version (mvn -v) :
Maven home: /usr/local/Cellar/maven/3.6.2/libexec
Java version: 1.8.0_192, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
  • Docker version :
Client: Docker Engine - Community
 Version:           19.03.3
 API version:       1.40
 Go version:        go1.12.10
 Git commit:        a872fc2
 Built:             Tue Oct  8 00:55:12 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.3
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.10
  Git commit:       a872fc2
  Built:            Tue Oct  8 01:01:15 2019
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
  • How to reproduce :
  1. Clone the sample project from https://github.com/SgrAlpha/dmp-bug.git
  2. Build it using mvn clean package
    • Expected: The build will success
    • Actually: The build failed. If you take a look at <repo>/target/docker/sgrio/sample_webapp/1.0.0-SNAPSHOT/build/Dockerfile, you will see around line 47 the JAVA_HOME variable has been incorrectly replaced to the JAVA_HOME on host machine, but it should use the JAVA_HOME defined here: https://github.com/SgrAlpha/dmp-bug/blob/master/src/main/docker/Dockerfile#L5

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
rhusscommented, Nov 22, 2019

Yes, probably. How maybe just that I haven’t set the JAVA_HOME variable locally 😬

It’s just as easy as this: If you have JAVA_HOME set, its broken. If not, the sample works.

So the real problem is, that environment variables are interpolated into a given Dockerfile when copied over into the target directory. I will have to look closer whether this is intentional (e.g. to allow your Dockerfiles to be parameterized) or not.

0reactions
paul8620commented, Jun 28, 2022

Found the issue

public class BuildImageConfiguration implements Serializable {

    public static final String DEFAULT_FILTER = "${*}";

this is where the problem is if you have something like

ENV PATH ${JAVA_HOME}/bin:${PATH}

in your Dockerfile it will substitute the entire line with your PATH switched my ENV line to

ENV PATH $JAVA_HOME/bin:$PATH

and it seems to not do the substitution

@rohanKanojia thanks for suggesting me to fix it otherwise i wouldn’t be able to find the issue. Though i still think the behaviour is buggy with the default filter being what it is

I would considering adding a new feature where the Dockerfile used is not rewritten that would be enabled by a property under <image>

I really consider people using Dockerfiles to be knowledgeable people and also i totally understand the interpolation feature where you want to add build props in the Dockerfile but i believe there are one two many ways to do that.

The proper way to do it is by passing args to Dockerifle and that is less confusing to anyone.

I’ll quit rambling since I fixed my issue thanks again

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically set JAVA_HOME of docker container
1. This won't work. I think the reason is that the export command —like any other command executed with the RUN instruction— runs...
Read more >
fabric8io/fabric8-maven-plugin
This plugin supports a rich set for providing a smooth Java developer experience. These goals can be categorized in multiple groups: Build goals ......
Read more >
No Java Home variables in Dockerfile (#5) · Issues - Repo One
There are no JAVA_HOME nor JAVA_VERSION variables defined in the ... Your use of /etc/profile seems to only set the env vars for...
Read more >
Building Docker Images with heroku.yml
The Docker build context is set to the directory containing the Dockerfile. If you do not specify a run section, the CMD specified...
Read more >
Topical Guide | Spring Boot Docker
If you do not want to call docker directly in your build, there is a rich set of plugins for Maven and Gradle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found