Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate container configuration from base image? #595

Closed
10 tasks done
coollog opened this issue Jul 12, 2018 · 20 comments
Closed
10 tasks done

Propagate container configuration from base image? #595

coollog opened this issue Jul 12, 2018 · 20 comments
Assignees
Milestone

Comments

@coollog
Copy link
Contributor

coollog commented Jul 12, 2018

Thumbs up if this is useful for you.

Configuration currently propagated from the base image:

  • environment variables
  • workingdir
  • entrypoint
  • cmd
  • history
  • labels
  • volumes
  • healthcheck
  • exposed ports

UPDATE(04/23/2020):

@chanseokoh
Copy link
Member

Hmm... if the images built by docker in the normal way don't inherit the container configuration, I think we don't need to do this. OTOH, if they do, this is something we can consider.

@coollog
Copy link
Contributor Author

coollog commented Jul 13, 2018

Yes, I believe Dockerfile FROM uses the container configuration from the base image. Any instructions afterwards are extensions on that base container configuration.

@essh
Copy link

essh commented Jul 14, 2018

This is useful for me to pick up on the Env from a base image (specifically PATH and JAVA_HOME). As already mentioned these were previously coming along when using a DockerFile FROM and would save having to specify them when launching a container built with jib.

@sunnychanwork
Copy link

Without this feature we will be forced to copy/link the java executables into the /usr/bin directory which might not be desirable.

@coollog coollog modified the milestones: 0.10.0, v0.9.8 Jul 16, 2018
@coollog
Copy link
Contributor Author

coollog commented Jul 20, 2018

I think for this feature, we can start with propagating environment variables since that seems to be the most useful case.

@TadCordle
Copy link
Contributor

Adjusting the milestone since we were only planning on propagating environment variables for this next release.

@TadCordle TadCordle removed their assignment Jul 26, 2018
@chanseokoh
Copy link
Member

chanseokoh commented Aug 3, 2018

For those who are following this issue, environment variables from the base image are now being propagated into the target image, starting from Jib 0.9.8.

@chanseokoh
Copy link
Member

chanseokoh commented Aug 29, 2018

Turns out we also need to propagate WorkingDir to make use of distroless-jetty as a base image for #431. Will work on this.

@chanseokoh
Copy link
Member

chanseokoh commented Aug 29, 2018

Also ExposedPorts in the container configuration.

However, this is a bit different: we have a config parameter for setting the value. The question becomes then, should we add ports on top of the ports from the base image? Or, does it still make sense to replace the base value with the value given by our config parameter? Maybe, we inherit ports only when not configured in Jib, but when configured, just replace the ports from the base?

@chanseokoh
Copy link
Member

#924: Entrypoint and CMD

@paivagustavo
Copy link
Contributor

@chanseokoh I like using the base image ports if none is specified.

Also, I think volumes must be inherited as well. After the PR for supporting volume configuration (#1215) is accepted we can do it.

@chanseokoh
Copy link
Member

@GuustavoPaiva yeah, we actually do need to inherit the ports and the volumes, which docker does with FROM in Dockerfile.

@coollog coollog modified the milestones: v1.1.0, v0.10.1 Nov 9, 2018
@coollog
Copy link
Contributor Author

coollog commented Nov 20, 2018

We have two left: volumes and healthcheck

Updated original post with a TODO list.

@chanseokoh
Copy link
Member

I think we haven't handled ports either. Updated the TODO list.

@chanseokoh
Copy link
Member

chanseokoh commented Nov 20, 2018

Also need to check if User can/should be inherited.

UPDATE(04/23/2020): issue #2421 reported.

@chanseokoh
Copy link
Member

chanseokoh commented Nov 20, 2018

Just in case, I am documenting here that there is one subtle to be careful about when enabling inheriting ports, volumes, etc. In BuildImageSteps, the code currently looks like

      // inherit properties
      imageBuilder
          .addEnvironment(baseImage.getEnvironment())
          .addLabels(baseImage.getLabels())
          .setWorkingDirectory(baseImage.getWorkingDirectory());
      ...
      // set properties when explicitly given
      if (containerConfiguration != null) {
        imageBuilder
            .addEnvironment(containerConfiguration.getEnvironmentMap())
            ...
            .setExposedPorts(containerConfiguration.getExposedPorts())
            .setVolumes(containerConfiguration.getVolumes())
            ...
      }

To inherit volumes for example, one would start with

      // inherit properties
      imageBuilder
          ...
          .setWorkingDirectory(baseImage.getWorkingDirectory())
          .setVolumes(baseImage.getVolumes());  // inherit volumes, YEAH!
      ...
      // set properties when explicitly given
      if (containerConfiguration != null) {
        ...
      }

In addition to this, we should update the code to selectively override properties:

      // inherit properties
      imageBuilder
          ...
          .setVolumes(baseImage.getVolumes());  // inherit volumes, YEAH!

      // set properties when explicitly given
      if (containerConfiguration != null) {
        ...
        // should override only when actually given
        if (containerConfiguration.getExposedPorts() != null) {
            imageBuilder.setExposedPorts(containerConfiguration.getExposedPorts());
        }
        // should override only when actually given
        if (containerConfiguration.getVolumes() != null) {
            imageBuilder.setVolumes(containerConfiguration.getVolumes());
        }
      }

UPDATE: we should actually do addExposedPorts() and addVolumes() instead of replacing them. We may still need to do the null check unless the add methods ignore null.

@coollog
Copy link
Contributor Author

coollog commented Nov 26, 2018

I think we should be adding the volumes/ports rather than replacing them since that's the behavior of Dockerfile builds as well. So, having port 1234 on the base image and setting port 5678 to expose would result in an image with ports 1234 and 5678 exposed.

@chanseokoh
Copy link
Member

Ah, you're right. We should actually do addExposedPorts() and addVolumes() instead of replacing them. I wonder if we need to ensure no duplicate.

@coollog
Copy link
Contributor Author

coollog commented Nov 26, 2018

When generating the container configuration, there would be no duplicates since the ports/volumes are maps to empty objects. We should probably just have them be represented as sets instead of lists in the image builder and other parts of the API too though.

@coollog
Copy link
Contributor Author

coollog commented Dec 5, 2018

@essh @cwensel @thekguy @sunnychanwork @joelhandwell @jcrossley3 @Tanmayshetty All of these configurations are propagated from the base image now in version 0.10.1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants