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: Failed to get image hash. Commit may be failed! #1

Open
Startouf opened this issue Dec 7, 2016 · 1 comment
Open

Docker: Failed to get image hash. Commit may be failed! #1

Startouf opened this issue Dec 7, 2016 · 1 comment

Comments

@Startouf
Copy link

Startouf commented Dec 7, 2016

Hi,
Thanks you for this gem, it is just incredible.
I've been trying to build my own container, and deploy inside it with your gem, but for some reason I always run into a

Docker: Failed to get image hash. Commit may be failed!
At the end of the deploy invocation

Here is some debug info with --trace

01:18 deploy:log_revision
      01 echo "Branch production (at bdf8973bf8c7abfeb111f5fd88d5f9ab313f59cb) deployed as release 20161207005548 by Startouf" >> /home/app/webapp/revisions.log
    ✔ 01 app:app@(docker image: my-image/production, container: 849094b97d35) 0.116s
** Invoke deploy_into_docker:commit (first_time)
** Execute deploy_into_docker:commit
invalid reference format
01:19 deploy_into_docker:commit
      Docker: Failed to get image hash. Commit may be failed!
cap aborted!
NoMethodError: undefined method `chomp!' for nil:NilClass
/Users/Cyril/.rvm/gems/ruby-2.3.1/gems/sshkit-backend-docker-0.1.1/lib/sshkit/backend/docker.rb:218:in `docker_commit'
/Users/Cyril/.rvm/gems/ruby-2.3.1/gems/capistrano-deploy_into_docker-0.2.0/lib/capistrano/tasks/deploy_into_docker.cap:8:in `block (3 levels) in <top (required)>'
/Users/Cyril/.rvm/gems/ruby-2.3.1/gems/sshkit-1.11.3/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/Users/Cyril/.rvm/gems/ruby-2.3.1/gems/sshkit-1.11.3/lib/sshkit/backends/abstract.rb:29:in `run'
/Users/Cyril/.rvm/gems/ruby-2.3.1/gems/sshkit-1.11.3/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy_into_docker:commit
The deploy has failed with an error: undefined method `chomp!' for nil:NilClass
** Invoke deploy:failed (first_time)
@Startouf
Copy link
Author

Startouf commented Dec 7, 2016

Ok there were some bugs in beckend/docker.rb, most likely the command to commit wasn't joined correctly.

Here is my suggested patch, will make a PR

if image_config["User"].to_s.length > 1
            cmd << "-c \"USER #{image_config["User"]}\""
          end

          c = image_config["Cmd"]
          if c[0] == "/bin/sh" && c[1] == "-c"
            c.shift; c.shift;
          end
          unless c.empty?
            cmd << "-c \"CMD #{c.join(' ')}\""
          end
        end

        image_name = host.docker_options[:commit]
        if image_name.is_a?(Hash)
          image_name.symbolize_keys.each do |key, val|
            if key == :name
              image_name = val
            else
              [*val].each do |v|
                cmd << "--#{key.to_s.tr('_', '-')}" << v
              end
            end
          end
        end
        cmd << container
        image_name == true or
          cmd << image_name

        pid = nil
        puts "Executing #{cmd}"
        image_hash = `#{cmd.join(' ')}`.tr('sha256:', '')
        image_hash.nil? and
          output.error "Docker: Failed to get image hash. Commit may be failed!"
        image_hash.chomp!
        ret = image_name == true ? image_hash : image_name
        output.info "Docker: commit #{container} as #{ret}"

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

No branches or pull requests

1 participant