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

docker_container does not redeploy when ENV property elements are removed #747

Open
rmoriz opened this issue Sep 9, 2016 · 8 comments
Open
Assignees
Labels
Bug Something isn't working Priority: Medium Will bring visible benefit to the project

Comments

@rmoriz
Copy link
Contributor

rmoriz commented Sep 9, 2016

Cookbook version

2.9.6

Chef-client version

12.9.41

Platform Details

Debian 8.3

Scenario:

  1. Initial deployment of a container:

    docker_container 'pg-stable' do
      repo 'postgres'
      tag '9.5.3'
      volumes ['pg-stable-data:/var/lib/postgresql/data']
    
      env %w(
        POSTGRES_USER=username
        WHATEVER=false
        
      )
      port ['127.0.0.1:15432:5432']
    
      restart_policy 'unless-stopped'
      action :run
    end
  2. Now, let's assume that we have to make changes to the environment and the port-mapping:

    docker_container 'pg-stable' do
      repo 'postgres'
      tag '9.5.3'
      volumes ['pg-stable-data:/var/lib/postgresql/data']
    
      env %w(
        POSTGRES_USER=username
         # change: WHATEVER removed
        
      )
      port ['127.0.0.1:15432:5432']
    
      restart_policy 'unless-stopped'
      action :run
    end

Unfortunately nothing happens on reconverge. The resource is not able to detect changes (removed elements from env array) and to properly redeploy the container on change.

@rmoriz
Copy link
Contributor Author

rmoriz commented Sep 9, 2016

turns out this is also the case with the ":run" action because the comparison (https://github.com/chef-cookbooks/docker/blob/7c3e166a9ff6a208e9462eb178766865998bfc38/libraries/docker_base.rb#L15) only checks for additional elements, ignores removed ENV k/v.

@someara someara changed the title docker_container does not redeploy when properties change docker_container does not redeploy when ENV property elements are removed Dec 19, 2016
@someara someara self-assigned this Dec 19, 2016
@chasebolt
Copy link
Contributor

this is because of issues we have with a container's Dockerfile adding to the inspect properties.

@someara an idea for this is to grab the image sha from the container, then docker inspect the image sha which will return us the Env, Volumes, Cmd, etc. We can then merge (and overwrite) properties as required to build the correct finalized properties of the container. This will allow us to remove the desired_state: false we have set on properties.

@brooksa321
Copy link

brooksa321 commented Dec 29, 2016

Are there any workarounds for this? It seems this bug removes ALL of the benefits of using Chef to manage your docker containers. For me this is not just an issue with environment variables. It wont redeploy for any changed options.

@chasebolt
Copy link
Contributor

chasebolt commented Dec 29, 2016 via email

@erincerys
Copy link

@rmoriz I tried changing that hunk you referenced to

class UnorderedArray < Array
  def ==(other)
    # If two envs have differences, let == return false
    other.is_a?(Array) && ((self - other) | (other - self)).empty? 
  end
end

but the result was containers being replaced despite no env differences within the context of the attribute passed to docker_container e.g.

  * docker_container[grafana] action run
    - stopping grafana 
    - deleting grafana
    - update grafana
    -   set env to ["IAM_ROLE=utils-container-grafana-role"] (was ["IAM_ROLE=utils-container-grafana-role", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"])
    - starting grafana

Docker sets additional environment variables based on the container's Dockerfile. I assume that is why you set a custom == comparison operation to match on the new env being a subset of the current env.

I was hoping this would have been a simple fix, as this affects me as well. Hopefully this is helpful for others who find interest in contributing.

@chasebolt
Copy link
Contributor

chasebolt commented Feb 2, 2018 via email

@tokozedg
Copy link
Contributor

Workaround can be to write ENV in a file and use it for container.
You can than notify file changes to container redeploy.

But this is quite important bug I agree.

@ramereth ramereth added Bug Something isn't working Priority: Medium Will bring visible benefit to the project labels Nov 19, 2020
@ramereth
Copy link
Contributor

If someone wants to make a PR which addresses this, we can certainly review and merge it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Priority: Medium Will bring visible benefit to the project
Projects
None yet
Development

No branches or pull requests

10 participants